#!/usr/bin/python -u
import os
import xenprototypeModulesCarrier
from xenprototype.VirtualManagementLib.virtualManagement import PhysicalHost
from xenprototype.CpuAllocation.cpuFeedbackControl import *

test1 = IperfTest(100,1,64,51007,"10.0.1.3","30paperParalellControllerThreeOntestVM1","146.164.69.149","5001")
test2 = IperfTest(100,1,64,51007,"10.0.3.3","30paperParalellControllerThreeOntestVM2","146.164.69.149","5002")
test3 = IperfTest(100,1,64,51007,"10.0.5.3","30paperParalellControllerThreeOntestVM3","146.164.69.149","5003")

#Pior ks e melhor Mp
#kp=float(-0.000003422)
#ki=float(0.000022158)

#P/ packet rate = 100k
kp=float(-0.000003422)
ki=float(0.000010158)


#P/ packet rate = 60k
#kp=float(-0.000007378)
#ki=float(0.000021043)

#Testando = 60k
#kp=float(-0.000007378)
#ki=float(0.000015043)


#Melhor ks e pior Mp
#kp=float(-0.000003422)
#ki=float(0.000029066)

physicalHost = PhysicalHost("floresta","xen+ssh")
desiredThroughput = 20000
samplePeriod = 1
errorPercentageAcceptable = 0.1
minPercentageSamplePeriod = 1
constantCap = 0
operationalPointThroughput = 40007


control1 = ThroughputControl(kp,ki,operationalPointThroughput,desiredThroughput,samplePeriod,errorPercentageAcceptable,minPercentageSamplePeriod,constantCap,3,physicalHost,test1)

control2 = ThroughputControl(kp,ki,operationalPointThroughput,desiredThroughput,samplePeriod,errorPercentageAcceptable,minPercentageSamplePeriod,constantCap,4,physicalHost,test2)

control3 = ThroughputControl(kp,ki,operationalPointThroughput,desiredThroughput,samplePeriod,errorPercentageAcceptable,minPercentageSamplePeriod,constantCap,7,physicalHost,test3)


ControlThread("10001",control1).start()
ControlThread("10002",control2).start()
ControlThread("10003",control3).start()

while (control1.done == "False") and (control2.done == "False") and (control3.done == "False"):
	physicalHost.printSchedParameters()
	os.popen("sleep 1")

#while (control1.done == "False"):
#	os.popen("sleep 1")

