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-02-23 11:26:32 +00:00
|
|
|
self.runUserspacePM()
|
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-02-23 11:26:32 +00:00
|
|
|
def runUserspacePM(self):
|
|
|
|
if self.xpParam.getParam(MpParamXp.KERNELPMC) != "netlink":
|
|
|
|
print("Client : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
|
|
|
upmc = self.xpParam.getParam(MpParamXp.USERPMC)
|
2015-02-23 11:42:14 +00:00
|
|
|
upmca = self.xpParam.getParam(MpParamXp.USERPMCARGS)
|
2015-02-23 11:30:32 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client, upmc + \
|
2015-02-23 11:42:14 +00:00
|
|
|
upmca + " &>upmc.log &")
|
2015-02-23 11:26:32 +00:00
|
|
|
if self.xpParam.getParam(MpParamXp.KERNELPMS) != "netlink":
|
|
|
|
print("Server : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
|
|
|
upms = self.xpParam.getParam(MpParamXp.USERPMS)
|
2015-02-23 11:42:14 +00:00
|
|
|
upmsa = self.xpParam.getParam(MpParamXp.USERPMSARGS)
|
2015-02-23 11:30:32 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.server, upms + \
|
2015-02-23 11:42:14 +00:00
|
|
|
upmsa + " &>upms.log &")
|
2015-02-23 11:26:32 +00:00
|
|
|
|
|
|
|
def cleanUserspacePM(self):
|
|
|
|
if self.xpParam.getParam(MpParamXp.KERNELPMC) != "netlink":
|
|
|
|
print("Client : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
|
|
|
upmc = self.xpParam.getParam(MpParamXp.USERPMC)
|
2015-02-23 11:30:32 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client, "killall " + upmc)
|
2015-02-23 11:26:32 +00:00
|
|
|
if self.xpParam.getParam(MpParamXp.KERNELPMS) != "netlink":
|
|
|
|
print("Server : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
|
|
|
upms = self.xpParam.getParam(MpParamXp.USERPMS)
|
2015-02-23 11:30:32 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.server, "killall " + upms)
|
2015-02-23 11:26:32 +00:00
|
|
|
|
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-02-23 11:26:32 +00:00
|
|
|
self.cleanUserspacePM()
|
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 = {}
|
2015-02-23 10:32:22 +00:00
|
|
|
self._saveSysctl(MpParamXp.sysctlKey, self.sysctlBUP)
|
|
|
|
self.sysctlBUPC = {}
|
|
|
|
self._saveSysctl(MpParamXp.sysctlKeyClient, self.sysctlBUPC,
|
|
|
|
ns = True, who = self.mpConfig.client)
|
|
|
|
self.sysctlBUPS = {}
|
|
|
|
self._saveSysctl(MpParamXp.sysctlKeyServer, self.sysctlBUPS,
|
|
|
|
ns = True, who = self.mpConfig.server)
|
|
|
|
|
|
|
|
def _saveSysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
|
|
|
for k in sysctlDic:
|
|
|
|
sysctlKey = sysctlDic[k]
|
2015-01-14 14:19:39 +00:00
|
|
|
cmd = self.cmdReadSysctl(sysctlKey)
|
2015-02-23 10:32:22 +00:00
|
|
|
if not ns:
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
else:
|
|
|
|
val = self.mpTopo.commandTo(who, cmd)
|
2015-01-14 14:19:39 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't get sysctl " + sysctlKey)
|
|
|
|
else:
|
2015-02-23 10:32:22 +00:00
|
|
|
sysctlBUP[k] = val.split(" ",2)[2][:-1]
|
|
|
|
|
2015-01-14 14:19:39 +00:00
|
|
|
|
|
|
|
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):
|
2015-02-23 10:32:22 +00:00
|
|
|
self._writeSysctl(MpParamXp.sysctlKey, self.sysctlBUP)
|
|
|
|
self._writeSysctl(MpParamXp.sysctlKeyClient, self.sysctlBUPC,
|
|
|
|
ns = True, who = self.mpConfig.client)
|
|
|
|
self._writeSysctl(MpParamXp.sysctlKeyServer, self.sysctlBUPS,
|
|
|
|
ns = True, who = self.mpConfig.server)
|
|
|
|
|
|
|
|
def _writeSysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
|
|
|
for k in sysctlBUP:
|
|
|
|
sysctlKey = sysctlDic[k]
|
2015-01-14 14:19:39 +00:00
|
|
|
sysctlValue = self.xpParam.getParam(k)
|
|
|
|
cmd = self.cmdWriteSysctl(sysctlKey,sysctlValue)
|
2015-02-23 10:32:22 +00:00
|
|
|
if not ns:
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
else:
|
|
|
|
val = self.mpTopo.commandTo(who, cmd)
|
2015-01-14 14:19:39 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
|
|
|
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2015-01-14 14:19:39 +00:00
|
|
|
def backUpSysctl(self):
|
2015-02-23 10:32:22 +00:00
|
|
|
self._backUpSysctl(MpParamXp.sysctlKey, self.sysctlBUP)
|
|
|
|
self._backUpSysctl(MpParamXp.sysctlKeyClient, self.sysctlBUPC,
|
|
|
|
ns = True, who = self.mpConfig.client)
|
|
|
|
self._backUpSysctl(MpParamXp.sysctlKeyServer, self.sysctlBUPS,
|
|
|
|
ns = True, who = self.mpConfig.server)
|
|
|
|
|
|
|
|
|
|
|
|
def _backUpSysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
|
|
|
for k in sysctlBUP:
|
2015-02-23 10:40:04 +00:00
|
|
|
sysctlKey = sysctlDic[k]
|
2015-02-23 10:32:22 +00:00
|
|
|
sysctlValue = sysctlBUP[k]
|
2015-01-14 14:19:39 +00:00
|
|
|
cmd = self.cmdWriteSysctl(sysctlKey,sysctlValue)
|
2015-02-23 10:32:22 +00:00
|
|
|
if not ns:
|
|
|
|
val = self.mpTopo.notNSCommand(cmd)
|
|
|
|
else:
|
|
|
|
val = self.mpTopo.commandTo(who, cmd)
|
|
|
|
|
2015-01-14 14:19:39 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
|
|
|
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2015-01-08 18:52:45 +00:00
|
|
|
def runTcpDump(self):
|
2015-01-12 15:34:41 +00:00
|
|
|
#todo : replace filename by cst
|
2015-01-21 09:38:11 +00:00
|
|
|
cpcap = self.xpParam.getParam(MpParamXp.CLIENTPCAP)
|
|
|
|
spcap = self.xpParam.getParam(MpParamXp.SERVERPCAP)
|
|
|
|
if cpcap == "yes" :
|
2015-01-12 15:34:41 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"tcpdump -i any -w client.pcap &")
|
2015-01-21 09:38:11 +00:00
|
|
|
if spcap == "yes" :
|
2015-01-12 15:34:41 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,
|
|
|
|
"tcpdump -i any -w server.pcap &")
|
2015-01-21 09:38:11 +00:00
|
|
|
if spcap == "yes" or cpcap == "yes":
|
|
|
|
self.mpTopo.commandTo(self.mpConfig.client,"sleep 5")
|