2020-06-24 08:36:26 +00:00
|
|
|
from .parameter import ExperienceParameter
|
2020-06-24 10:28:44 +00:00
|
|
|
from topos.multi_interface import MultiInterfaceTopo
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2020-06-24 08:54:44 +00:00
|
|
|
class Experience(object):
|
2020-06-24 14:11:54 +00:00
|
|
|
"""
|
|
|
|
Base class to instantiate an experience to perform.
|
|
|
|
|
|
|
|
This class is not instantiable as it. You must define a child class with the
|
|
|
|
`NAME` attribute.
|
2020-06-25 08:53:56 +00:00
|
|
|
|
|
|
|
Attributes:
|
|
|
|
experience_parameter Instance of ExperienceParameter
|
|
|
|
topo Instance of Topo
|
|
|
|
topo_config Instance of TopoConfig
|
2020-06-24 14:11:54 +00:00
|
|
|
"""
|
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def __init__(self, experience_parameter, topo, topo_config):
|
|
|
|
self.experience_parameter = experience_parameter
|
|
|
|
self.topo = topo
|
|
|
|
self.topo_config = topo_config
|
|
|
|
|
|
|
|
def classic_run(self):
|
|
|
|
"""
|
|
|
|
Default function to perform the experiment. It consists into three phases:
|
|
|
|
- A preparation phase through `prepare()` (generating experiment files,...)
|
|
|
|
- A running phase through `run()` (where the actual experience takes place)
|
|
|
|
- A cleaning phase through `clean()` (stopping traffic, removing generated files,...)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
Typically, this function is called in the constructor of child classes.
|
|
|
|
"""
|
2020-06-23 11:20:07 +00:00
|
|
|
self.prepare()
|
|
|
|
self.run()
|
|
|
|
self.clean()
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def prepare(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
"""
|
|
|
|
Prepare the environment to run the experience.
|
|
|
|
Typically, when you inherit from this class, you want to extend this
|
|
|
|
method, while still calling this parent function.
|
|
|
|
|
|
|
|
TODO: split experience traffic and protocol configuration
|
|
|
|
"""
|
|
|
|
self.setup_sysctl()
|
|
|
|
self.run_userspace_path_manager() # TODO to move elsewhere
|
|
|
|
self.topo_config.configure_network()
|
|
|
|
self.change_metric() # TODO to move elsewhere
|
|
|
|
self.put_priority_on_paths() # TODO to move elsewhere
|
|
|
|
self.disable_tso()
|
2020-06-23 11:20:07 +00:00
|
|
|
self.runTcpDump()
|
|
|
|
self.runNetemAt()
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def change_metric(self):
|
|
|
|
"""
|
|
|
|
Function only meaningful for MPTCP and its specific scheduler
|
|
|
|
"""
|
|
|
|
metric = self.experience_parameter.get(ExperienceParameter.METRIC)
|
2020-06-23 11:20:07 +00:00
|
|
|
if int(metric) >= 0:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_global(
|
|
|
|
"echo {} > /sys/module/mptcp_sched_metric/parameters/metric".format(metric))
|
2016-06-21 15:31:17 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def put_priority_on_paths(self):
|
|
|
|
"""
|
|
|
|
Function only meaningful for MPTCP
|
|
|
|
"""
|
2020-06-24 10:28:44 +00:00
|
|
|
# Only meaningful if mpTopo is instance of MultiInterfaceTopo
|
2020-06-25 08:53:56 +00:00
|
|
|
if isinstance(self.topo, MultiInterfaceTopo):
|
|
|
|
prioPath0 = self.experience_parameter.get(ExperienceParameter.PRIOPATH0)
|
|
|
|
prioPath1 = self.experience_parameter.get(ExperienceParameter.PRIOPATH1)
|
2020-06-23 11:20:07 +00:00
|
|
|
if not prioPath0 == prioPath1:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "/home/mininet/iproute/ip/ip link set dev " +
|
|
|
|
self.topo_config.getClientInterface(0) + " priority " + str(prioPath0))
|
|
|
|
self.topo.command_to(self.topo_config.router, "/home/mininet/iproute/ip/ip link set dev " +
|
|
|
|
self.topo_config.getRouterInterfaceSwitch(0) + " priority " +
|
2020-06-23 11:20:07 +00:00
|
|
|
str(prioPath0))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "/home/mininet/iproute/ip/ip link set dev " +
|
|
|
|
self.topo_config.getClientInterface(1) + " priority " + str(prioPath1))
|
|
|
|
self.topo.command_to(self.topo_config.router, "/home/mininet/iproute/ip/ip link set dev " +
|
|
|
|
self.topo_config.getRouterInterfaceSwitch(1) + " priority " +
|
2020-06-23 11:20:07 +00:00
|
|
|
str(prioPath1))
|
2016-05-13 08:00:29 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
backupPath0 = self.experience_parameter.get(ExperienceParameter.BACKUPPATH0)
|
2020-06-23 11:20:07 +00:00
|
|
|
if int(backupPath0) > 0:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, self.topo_config.interfaceBUPCommand(self.topo_config.getClientInterface(0)))
|
|
|
|
self.topo.command_to(self.topo_config.router, self.topo_config.interfaceBUPCommand(self.topo_config.getRouterInterfaceSwitch(0)))
|
|
|
|
backupPath1 = self.experience_parameter.get(ExperienceParameter.BACKUPPATH1)
|
2020-06-23 11:20:07 +00:00
|
|
|
if int(backupPath1) > 0:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, self.topo_config.interfaceBUPCommand(self.topo_config.getClientInterface(1)))
|
|
|
|
self.topo.command_to(self.topo_config.router, self.topo_config.interfaceBUPCommand(self.topo_config.getRouterInterfaceSwitch(1)))
|
2016-06-21 15:32:19 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def disable_tso(self):
|
|
|
|
links = self.topo.getLinkCharacteristics()
|
2020-06-23 11:20:07 +00:00
|
|
|
i = 0
|
|
|
|
for l in links:
|
2020-06-25 08:53:56 +00:00
|
|
|
lname = self.topo_config.getMidLeftName(i)
|
|
|
|
rname = self.topo_config.getMidRightName(i)
|
|
|
|
lbox = self.topo.get_host(lname)
|
|
|
|
lif = self.topo_config.getMidL2RInterface(i)
|
|
|
|
rif = self.topo_config.getMidR2LInterface(i)
|
|
|
|
rbox = self.topo.get_host(rname)
|
2020-06-23 11:20:07 +00:00
|
|
|
print(str(lname) + " " + str(lif))
|
|
|
|
print(str(rname) + " " + str(rif))
|
|
|
|
print("boxes " + str(lbox) + " " + str(rbox))
|
|
|
|
cmd = "ethtool -K " + lif + " tso off"
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(lbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = "ethtool -K " + rif + " tso off"
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(rbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
i = i + 1
|
2017-05-09 08:36:01 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
# And for the server
|
2020-06-25 08:53:56 +00:00
|
|
|
cmd = "ethtool -K " + self.topo_config.getServerInterface() + " tso off"
|
2020-06-23 11:20:07 +00:00
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, cmd)
|
2017-05-09 08:36:01 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
cmd = "ethtool -K " + self.topo_config.getRouterInterfaceSwitch(self.topo_config.getClientInterfaceCount()) + " tso off"
|
2020-06-23 11:20:07 +00:00
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.router, cmd)
|
2017-05-09 08:36:01 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def run_userspace_path_manager(self):
|
|
|
|
if self.experience_parameter.get(ExperienceParameter.KERNELPMC) != "netlink":
|
2020-06-23 11:20:07 +00:00
|
|
|
print("Client : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
upmc = self.experience_parameter.get(ExperienceParameter.USERPMC)
|
|
|
|
upmca = self.experience_parameter.get(ExperienceParameter.USERPMCARGS)
|
|
|
|
self.topo.command_to(self.topo_config.client, upmc + \
|
2020-06-23 11:20:07 +00:00
|
|
|
" " + upmca + " &>upmc.log &")
|
2020-06-25 08:53:56 +00:00
|
|
|
if self.experience_parameter.get(ExperienceParameter.KERNELPMS) != "netlink":
|
2020-06-23 11:20:07 +00:00
|
|
|
print("Server : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
upms = self.experience_parameter.get(ExperienceParameter.USERPMS)
|
|
|
|
upmsa = self.experience_parameter.get(ExperienceParameter.USERPMSARGS)
|
|
|
|
self.topo.command_to(self.topo_config.server, upms + \
|
2020-06-23 11:20:07 +00:00
|
|
|
" " + upmsa + " &>upms.log &")
|
2015-02-23 11:26:32 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def cleanUserspacePM(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
if self.experience_parameter.get(ExperienceParameter.KERNELPMC) != "netlink":
|
2020-06-23 11:20:07 +00:00
|
|
|
print("Client : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
upmc = self.experience_parameter.get(ExperienceParameter.USERPMC)
|
|
|
|
self.topo.command_to(self.topo_config.client, "killall " + upmc)
|
|
|
|
if self.experience_parameter.get(ExperienceParameter.KERNELPMS) != "netlink":
|
2020-06-23 11:20:07 +00:00
|
|
|
print("Server : Error, I can't change the userspace pm if the kernel pm is not netlink !")
|
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
upms = self.experience_parameter.get(ExperienceParameter.USERPMS)
|
|
|
|
self.topo.command_to(self.topo_config.server, "killall " + upms)
|
2015-02-23 11:26:32 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def runNetemAt(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
if not self.topo.changeNetem == "yes":
|
2020-06-23 11:20:07 +00:00
|
|
|
print("I don't need to change netem")
|
|
|
|
return
|
|
|
|
print("Will change netem config on the fly")
|
2020-06-25 08:53:56 +00:00
|
|
|
links = self.topo.getLinkCharacteristics()
|
2020-06-23 11:20:07 +00:00
|
|
|
i = 0
|
|
|
|
for l in links:
|
2020-06-25 08:53:56 +00:00
|
|
|
lname = self.topo_config.getMidLeftName(i)
|
|
|
|
rname = self.topo_config.getMidRightName(i)
|
|
|
|
lbox = self.topo.get_host(lname)
|
|
|
|
lif = self.topo_config.getMidL2RInterface(i)
|
|
|
|
rif = self.topo_config.getMidR2LInterface(i)
|
|
|
|
rbox = self.topo.get_host(rname)
|
2020-06-23 11:20:07 +00:00
|
|
|
print(str(lname) + " " + str(lif))
|
|
|
|
print(str(rname) + " " + str(rif))
|
|
|
|
print("boxes " + str(lbox) + " " + str(rbox))
|
|
|
|
cmd = l.buildBwCmd(lif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(lbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = l.buildBwCmd(rif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(rbox, cmd)
|
|
|
|
ilif = self.topo_config.getMidL2RIncomingInterface(i)
|
|
|
|
irif = self.topo_config.getMidR2LIncomingInterface(i)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = l.buildPolicingCmd(ilif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(lbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = l.buildPolicingCmd(irif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(rbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = l.buildNetemCmd(irif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(rbox, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
cmd = l.buildNetemCmd(ilif)
|
|
|
|
print(cmd)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(lbox, cmd)
|
2019-11-28 08:32:49 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
i = i + 1
|
2015-01-20 10:04:36 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def run(self):
|
|
|
|
pass
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def clean(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client,
|
2020-06-23 11:20:07 +00:00
|
|
|
"killall tcpdump")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server,
|
2020-06-23 11:20:07 +00:00
|
|
|
"killall tcpdump")
|
|
|
|
self.backUpSysctl()
|
|
|
|
self.cleanUserspacePM()
|
|
|
|
pass
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def setup_sysctl(self):
|
|
|
|
self.save_sysctl()
|
|
|
|
self.write_sysctl()
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def save_sysctl(self):
|
2020-06-23 11:20:07 +00:00
|
|
|
self.sysctlBUP = {}
|
2020-06-25 08:53:56 +00:00
|
|
|
self._save_sysctl(ExperienceParameter.sysctlKey, self.sysctlBUP)
|
2020-06-23 11:20:07 +00:00
|
|
|
self.sysctlBUPC = {}
|
2020-06-25 08:53:56 +00:00
|
|
|
self._save_sysctl(ExperienceParameter.sysctlKeyClient, self.sysctlBUPC,
|
|
|
|
ns = True, who = self.topo_config.client)
|
2020-06-23 11:20:07 +00:00
|
|
|
self.sysctlBUPS = {}
|
2020-06-25 08:53:56 +00:00
|
|
|
self._save_sysctl(ExperienceParameter.sysctlKeyServer, self.sysctlBUPS,
|
|
|
|
ns = True, who = self.topo_config.server)
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def _save_sysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
2020-06-23 11:20:07 +00:00
|
|
|
for k in sysctlDic:
|
|
|
|
sysctlKey = sysctlDic[k]
|
|
|
|
cmd = self.cmdReadSysctl(sysctlKey)
|
|
|
|
if not ns:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_global(cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_to(who, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't get sysctl " + sysctlKey)
|
|
|
|
else:
|
2020-06-23 11:23:27 +00:00
|
|
|
# For Python3 compatibility
|
|
|
|
if type(val) is bytes:
|
|
|
|
val = val.decode()
|
2020-06-23 11:20:07 +00:00
|
|
|
sysctlBUP[k] = val.split(" ",2)[2][:-1]
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def cmdReadSysctl(self, key):
|
|
|
|
s = "sysctl " + key
|
|
|
|
return s
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def cmd_write_sysctl(self, key, value):
|
2020-06-23 11:20:07 +00:00
|
|
|
s = self.cmdReadSysctl(key)
|
|
|
|
s = s + "=\"" + str(value) + "\""
|
|
|
|
return s
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def write_sysctl(self):
|
|
|
|
self._write_sysctl(ExperienceParameter.sysctlKey, self.sysctlBUP)
|
|
|
|
self._write_sysctl(ExperienceParameter.sysctlKeyClient, self.sysctlBUPC,
|
|
|
|
ns = True, who = self.topo_config.client)
|
|
|
|
self._write_sysctl(ExperienceParameter.sysctlKeyServer, self.sysctlBUPS,
|
|
|
|
ns = True, who = self.topo_config.server)
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def _write_sysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
2020-06-23 11:20:07 +00:00
|
|
|
for k in sysctlBUP:
|
|
|
|
sysctlKey = sysctlDic[k]
|
2020-06-25 08:53:56 +00:00
|
|
|
sysctlValue = self.experience_parameter.get(k)
|
|
|
|
cmd = self.cmd_write_sysctl(sysctlKey,sysctlValue)
|
2020-06-23 11:20:07 +00:00
|
|
|
if not ns:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_global(cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_to(who, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def backUpSysctl(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
self._backUpSysctl(ExperienceParameter.sysctlKey, self.sysctlBUP)
|
|
|
|
self._backUpSysctl(ExperienceParameter.sysctlKeyClient, self.sysctlBUPC,
|
2020-06-25 08:53:56 +00:00
|
|
|
ns = True, who = self.topo_config.client)
|
2020-06-24 08:36:26 +00:00
|
|
|
self._backUpSysctl(ExperienceParameter.sysctlKeyServer, self.sysctlBUPS,
|
2020-06-25 08:53:56 +00:00
|
|
|
ns = True, who = self.topo_config.server)
|
2015-02-23 10:32:22 +00:00
|
|
|
|
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def _backUpSysctl(self, sysctlDic, sysctlBUP, ns = False, who = None):
|
|
|
|
for k in sysctlBUP:
|
|
|
|
sysctlKey = sysctlDic[k]
|
|
|
|
sysctlValue = sysctlBUP[k]
|
2020-06-25 08:53:56 +00:00
|
|
|
cmd = self.cmd_write_sysctl(sysctlKey,sysctlValue)
|
2020-06-23 11:20:07 +00:00
|
|
|
if not ns:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_global(cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
else:
|
2020-06-25 08:53:56 +00:00
|
|
|
val = self.topo.command_to(who, cmd)
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
if val == "Error":
|
|
|
|
print("oooops can't set sysctl " + sysctlKey)
|
2015-01-14 14:19:39 +00:00
|
|
|
|
2015-02-23 10:32:22 +00:00
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def runTcpDump(self):
|
|
|
|
#todo : replace filename by cst
|
2020-06-25 08:53:56 +00:00
|
|
|
cpcap = self.experience_parameter.get(ExperienceParameter.CLIENTPCAP)
|
|
|
|
spcap = self.experience_parameter.get(ExperienceParameter.SERVERPCAP)
|
|
|
|
snaplenpcap = self.experience_parameter.get(ExperienceParameter.SNAPLENPCAP)
|
2020-06-23 11:20:07 +00:00
|
|
|
if cpcap == "yes" :
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client,
|
2020-06-23 11:20:07 +00:00
|
|
|
"tcpdump -i any -s " + snaplenpcap + " -w client.pcap &")
|
|
|
|
if spcap == "yes" :
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server,
|
2020-06-23 11:20:07 +00:00
|
|
|
"tcpdump -i any -s " + snaplenpcap + " -w server.pcap &")
|
|
|
|
if spcap == "yes" or cpcap == "yes":
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client,"sleep 5")
|