add changePvAt to control application rate

During an experiment, you can change the application rate with the
param changePvAt:when,-L XX(unit)

Signed-off-by: Benjamin Hesmans <benjamin.hesmans@uclouvain.be>
This commit is contained in:
Benjamin Hesmans 2015-02-10 11:03:21 +01:00
parent d76f0c7f0c
commit 6576eb330f
7 changed files with 78 additions and 6 deletions

View File

@ -1,4 +1,10 @@
xpType:ncpv
ncClientPort_0:33400
clientPcap:yes
ddCount:15000
pvRateLimit:100k
sched:roundrobin
changePv:yes
changePvAt:5,-L 200k
changePvAt:10,-L 100k
changePvAt:15,-L 600k

View File

@ -1,5 +1,6 @@
from mpExperience import MpExperience
from mpParamXp import MpParamXp
from mpPvAt import MpPvAt
class MpExperienceNCPV(MpExperience):
"""
@ -32,7 +33,47 @@ class MpExperienceNCPV(MpExperience):
if len(self.ncClientPort) == 0:
d = self.xpParam.getParam(MpParamXp.NCCLIENTPORT)
self.ncClientPort.append(d)
self.loadPvAt()
def loadPvAt(self):
self.changePvAt = []
self.changePv = self.xpParam.getParam(MpParamXp.CHANGEPV)
if self.changePv != "yes":
print("Don't change pv rate...")
return
changePvAt = self.xpParam.getParam(MpParamXp.CHANGEPVAT)
if not isinstance(changePvAt, list):
changePvAt = [changePvAt]
for p in changePvAt:
tab = p.split(",")
if len(tab)==2:
o = MpPvAt(float(tab[0]), tab[1])
self.addPvAt(o)
else:
print("pv wrong line : " + n)
def addPvAt(self, p):
if len(self.changePvAt) == 0 :
p.delta = p.at
else:
if p.at > self.changePvAt[-1].at:
p.delta = p.at - self.changePvAt[-1].at
else:
print("Do not take into account " + p.__str__() + \
"because ooo !")
return
self.changePvAt.append(p)
def getPvChangeCmd(self):
cmd = ""
for p in self.changePvAt:
cmd = cmd + "sleep " + str(p.delta)
cmd = cmd + " && "
cmd = cmd + MpExperienceNCPV.PV_BIN + " -R " + self.pvPid
cmd = cmd + " " + p.cmd + " && "
cmd = cmd + " true &"
return cmd
def prepare(self):
MpExperience.prepare(self)
@ -64,6 +105,9 @@ class MpExperienceNCPV(MpExperience):
"_" + str(id) + ".log"
print(s)
return s
def getPvPidCmd(self):
s = "pgrep -n pv"
return s
def clean(self):
MpExperience.clean(self)
@ -77,6 +121,17 @@ class MpExperienceNCPV(MpExperience):
self.mpTopo.commandTo(self.mpConfig.server, cmd)
cmd = self.getNCClientCmd(i)
self.mpTopo.commandTo(self.mpConfig.client, cmd)
self.mpConfig.client.sendCmd(cmd)
cmd = self.getPvPidCmd()
self.pvPid = self.mpTopo.commandTo(self.mpConfig.server, cmd)[:-1]
cmd = self.getPvChangeCmd()
print(cmd)
self.mpTopo.commandTo(self.mpConfig.server, cmd)
self.mpConfig.client.waitOutput()
self.mpTopo.commandTo(self.mpConfig.client, "sleep 1")

View File

@ -10,7 +10,7 @@ class MpMininetBuilder(Topo):
self.net = None
def commandTo(self, who, cmd):
who.cmd(cmd)
return who.cmd(cmd)
def notNSCommand(self, cmd):
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)

View File

@ -21,9 +21,8 @@ class MpParam:
k = tab[0]
val = tab[1][:-1]
if k in self.paramDic:
tmp = self.paramDic[k]
self.paramDic[k] = []
self.paramDic[k].append(tmp)
if not isinstance(self.paramDic[k], list):
self.paramDic[k] = [self.paramDic[k]]
self.paramDic[k].append(val)
else:
self.paramDic[k] = val

View File

@ -17,6 +17,8 @@ class MpParamXp(MpParam):
PVZ = "pvZ"
NCSERVERPORT = "ncServerPort"
NCCLIENTPORT = "ncClientPort"
CHANGEPV = "changePv"
CHANGEPVAT = "changePvAt"
# global sysctl
sysctlKey = {}
@ -45,6 +47,7 @@ class MpParamXp(MpParam):
defaultValue[PVG] = "10000"
defaultValue[NCSERVERPORT] = "33666"
defaultValue[NCCLIENTPORT] = "33555"
defaultValue[CHANGEPV] = "no"
def __init__(self, paramFile):
MpParam.__init__(self, paramFile)

9
src/mpPvAt.py Normal file
View File

@ -0,0 +1,9 @@
class MpPvAt:
def __init__(self, at, cmd):
self.at = at
self.cmd = cmd
self.delta = 0
def __str__(self):
return "Pv... at " + str(self.at) + "(" + str(self.delta) + \
") will be " + self.cmd

View File

@ -24,7 +24,7 @@ class MpTopo:
def commandTo(self, who, cmd):
self.logFile.write(who.__str__() + " : " + cmd + "\n")
self.topoBuilder.commandTo(who, cmd)
return self.topoBuilder.commandTo(who, cmd)
def notNSCommand(self, cmd):
"""