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

#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 = 100k - CAP <= 25
#kp=float(-0.000004825)
#ki=float(0.000018530)

#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)

filename = "debugTest"
physicalHost = PhysicalHost("floresta","xen+ssh")
desiredThroughput = 20000
samplePeriod = 1
errorPercentageAcceptable = 0
minPercentageSamplePeriod = 1
constantCap = 0
operationalPointThroughput = 27023
test1 = IperfTest(100,1,64,51007,"10.0.1.3",filename,"146.164.69.149","5001")
control = ThroughputControl(kp,ki,operationalPointThroughput,desiredThroughput,samplePeriod,errorPercentageAcceptable,minPercentageSamplePeriod,constantCap,3,physicalHost,test1)

control.runFeedackControl()

statistic = Statistics(filename,20)
print str(statistic.average)
print str(statistic.rmse)
