2015-01-08 18:52:45 +00:00
|
|
|
from mpParamXp import MpParamXp
|
|
|
|
|
|
|
|
class MpExperience:
|
|
|
|
PING = "ping"
|
2015-01-12 15:34:41 +00:00
|
|
|
NCPV = "ncpv"
|
2015-01-08 18:52:45 +00:00
|
|
|
def __init__(self, xpParam, mpTopo, mpConfig):
|
|
|
|
self.xpParam = xpParam
|
|
|
|
self.mpTopo = mpTopo
|
|
|
|
self.mpConfig = mpConfig
|
|
|
|
print(self.xpParam)
|
|
|
|
|
|
|
|
def classicRun(self):
|
|
|
|
self.prepare()
|
|
|
|
self.run()
|
|
|
|
self.clean()
|
|
|
|
|
|
|
|
def prepare(self):
|
2015-01-14 14:19:39 +00:00
|
|
|
self.setupSysctl()
|
2015-01-08 18:52:45 +00:00
|
|
|
self.runTcpDump()
|
2015-01-16 02:59:52 +00:00
|
|
|
self.runNetemAt()
|
2015-01-08 18:52:45 +00:00
|
|
|
pass
|
|
|
|
|
2015-01-20 10:04:36 +00:00
|
|
|
def runNetemAt(self):
|
|
|
|
if not self.mpTopo.changeNetem == "yes":
|
2015-01-16 02:59:52 +00:00
|
|
|
print("I don't need to change netem")
|
2015-01-20 10:04:36 +00:00
|
|
|
return
|
|
|
|
print("Will change netem config on the fly")
|
|
|
|
links = self.mpTopo.getLinkCharacteristics()
|
2015-01-20 11:23:57 +00:00
|
|
|
i = 0
|
2015-01-20 10:04:36 +00:00
|
|
|
for l in links:
|
2015-01-20 11:23:57 +00:00
|
|
|
lname = self.mpConfig.getMidLeftName(i)
|
|
|
|
rname = self.mpConfig.getMidRightName(i)
|
|
|
|
lbox = self.mpTopo.getHost(lname)
|
|
|
|
lif = self.mpConfig.getMidL2RInterface(i)
|
|
|
|
rif = self.mpConfig.getMidR2LInterface(i)
|
|
|
|
rbox = self.mpTopo.getHost(rname)
|
|
|
|
print(str(lname) + " " + str(lif))
|
|
|
|
print(str(rname) + " " + str(rif))
|
|
|
|
print("boxes " + str(lbox) + " " + str(rbox))
|
|
|
|
cmd = l.buildNetemCmd(lif)
|
2015-01-20 10:04:36 +00:00
|
|
|
print(cmd)
|
2015-01-20 11:23:57 +00:00
|
|
|
self.mpTopo.commandTo(lbox, cmd)
|
|
|
|
cmd = l.buildNetemCmd(rif)
|
|
|
|
print(cmd)
|
|
|
|
self.mpTopo.commandTo(rbox, cmd)
|
|
|
|
i = i + 1
|
2015-01-20 10:04:36 +00:00
|
|
|
|
2015-01-08 18:52:45 +00:00
|
|
|
def run(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def clean(self):
|
2015-01-12 15:34:41 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"killall tcpdump")
|
|
|
|
self.mpTopo.commandTo(self.mpConfig.server,
|
|
|
|
"killall tcpdump")
|
2015-01-14 14:19:39 +00:00
|
|
|
self.backUpSysctl()
|
2015-01-08 18:52:45 +00:00
|
|
|
pass
|
|
|
|
|
2015-01-14 14:19:39 +00:00
|
|
|
def setupSysctl(self):
|
|
|
|
self.saveSysctl()
|
|
|
|
self.writeSysctl()
|
|
|
|
|
|
|
|
def saveSysctl(self):
|
|
|
|
self.sysctlBUP = {}
|
|
|
|
for k in MpParamXp.sysctlKey:
|
|
|
|
sysctlKey = MpParamXp.sysctlKey[k]
|
|
|
|
cmd = self.cmdReadSysctl(sysctlKey)
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't get sysctl " + sysctlKey)
|
|
|
|
else:
|
|
|
|
self.sysctlBUP[k] = val.split(" ",2)[2][:-1]
|
|
|
|
|
|
|
|
def cmdReadSysctl(self, key):
|
|
|
|
s = "sysctl " + key
|
|
|
|
return s
|
|
|
|
|
|
|
|
def cmdWriteSysctl(self, key, value):
|
|
|
|
s = self.cmdReadSysctl(key)
|
|
|
|
s = s + "=\"" + str(value) + "\""
|
|
|
|
return s
|
|
|
|
|
|
|
|
def writeSysctl(self):
|
|
|
|
for k in self.sysctlBUP:
|
|
|
|
sysctlKey = MpParamXp.sysctlKey[k]
|
|
|
|
sysctlValue = self.xpParam.getParam(k)
|
|
|
|
cmd = self.cmdWriteSysctl(sysctlKey,sysctlValue)
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
|
|
|
|
|
|
|
def backUpSysctl(self):
|
|
|
|
for k in self.sysctlBUP:
|
|
|
|
sysctlKey = MpParamXp.sysctlKey[k]
|
|
|
|
sysctlValue = self.sysctlBUP[k]
|
|
|
|
cmd = self.cmdWriteSysctl(sysctlKey,sysctlValue)
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
|
|
|
|
2015-01-08 18:52:45 +00:00
|
|
|
def runTcpDump(self):
|
2015-01-12 15:34:41 +00:00
|
|
|
#todo : replace filename by cst
|
|
|
|
if self.xpParam.getParam(MpParamXp.CLIENTPCAP) == "yes" :
|
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"tcpdump -i any -w client.pcap &")
|
|
|
|
if self.xpParam.getParam(MpParamXp.SERVERPCAP) == "yes" :
|
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"tcpdump -i any -w server.pcap &")
|
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"sleep 5")
|