#!/usr/bin/python -u

import os
import xenprototypeModulesCarrier
from throughputTest import *
from xenprototype.CpuAllocation.cpuFeedbackControl import *
from xenprototype.VirtualManagementLib.virtualManagement import PhysicalHost
from xenprototype.CpuAllocation.statistics import *



physicalHost = PhysicalHost("floresta","xen+ssh")
physicalHost.setSchedParametersCap(15,3)
#physicalHost.setSchedParametersCap(0,6)
#physicalHost.setSchedParametersCap(0,3)
#physicalHost.setSchedParametersCap(0,5)
physicalHost.printSchedParameters()


test1 = IperfTest(100,1,64,51200,"10.0.1.3","testVM1","146.164.69.149","5001")
#test2 = IperfTest(100,1,1470,705600,"10.0.3.3","testVM2","146.164.69.149","5002")
#test3 = IperfTest(100,1,1470,30720,"10.0.5.3","testVM3","146.164.69.149","5003")

#IperfThread("1",test1).start()
#IperfThread("1",test2).start()
#IperfThread("1",test3).start()

#1470 Bytes - Packet Rate 60 - Cap < 35
kp=float(-0.000000362)
#ki=float(0.000001483)
ki=float(0.000000700)

filename = "debugTest"
#physicalHost = PhysicalHost("floresta","xen+ssh")
desiredThroughput = 400000
samplePeriod = 1
errorPercentageAcceptable = 0.1
minPercentageSamplePeriod = 1
constantCap = 0
operationalPointThroughput = 27023
#control = ThroughputControl(kp,ki,operationalPointThroughput,desiredThroughput,samplePeriod,errorPercentageAcceptable,minPercentageSamplePeriod,constantCap,6,physicalHost,test2)

#ControlThread("10001",control).start()
IperfThread("1",test1).start()
#IperfThread("2",test2).start()

while (test1.done == False):
	print "Test 1 " + str(test1.lastMeasure)
	#print "Test 2 " + str(test2.lastMeasure)
	#print "Test 3 " + str(test3.lastMeasure)
	os.popen("sleep 1")

os.popen("sleep 5")

#statistic = Statistics("testVM2",20)
#print "Controler Average" + str(statistic.average)
#print "Controler RMSE" + str(statistic.rmse)

#del statistic

statistic = Statistics("testVM1",20)
print "Pure Average" + str(statistic.average)
print "Pure RMSE" + str(statistic.rmse)
