refactoring of Topo

This commit is contained in:
Quentin De Coninck 2020-06-29 09:51:55 +02:00
parent 894579b91c
commit af06305029
24 changed files with 406 additions and 493 deletions

View File

@ -90,22 +90,7 @@ class ExperimentParameter(Parameter):
def __init__(self, parameter_filename): def __init__(self, parameter_filename):
super(ExperimentParameter, self).__init__(parameter_filename) super(ExperimentParameter, self).__init__(parameter_filename)
self.default_parameters = ExperimentParameter.DEFAULT_PARAMETERS self.default_parameters.update(ExperimentParameter.DEFAULT_PARAMETERS)
def get(self, key):
"""
Get the value of the parameter with key `key`.
If not defined by the configuration file, return the default value.
Raise Exception if the parameter has no default value and is absent.
"""
val = super(ExperimentParameter, self).get(key)
if val is None:
if key in self.default_parameters:
return self.default_parameters[key]
else:
raise Exception("Parameter not found " + key)
else:
return val
class Experiment(object): class Experiment(object):
@ -129,6 +114,7 @@ class Experiment(object):
PARAMETER_CLASS = ExperimentParameter PARAMETER_CLASS = ExperimentParameter
IP_BIN = "ip" IP_BIN = "ip"
PING_OUTPUT = "ping.log"
def __init__(self, experiment_parameter_filename, topo, topo_config): def __init__(self, experiment_parameter_filename, topo, topo_config):
""" """
@ -374,6 +360,18 @@ class Experiment(object):
logging.info("Activating tcpdump, waiting for it to run") logging.info("Activating tcpdump, waiting for it to run")
self.topo.command_to(self.topo_config.client,"sleep 5") self.topo.command_to(self.topo_config.client,"sleep 5")
def ping(self):
self.topo.command_to(self.topo_config.client,
"rm {}".format(Experiment.PING_OUTPUT))
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def ping_command(self, from_ip, to_ip, n=5):
return "ping -c {} -I {} {} >> {}".format(n, from_ip, to_ip, Experiment.PING_OUTPUT)
class RandomFileParameter(ExperimentParameter): class RandomFileParameter(ExperimentParameter):
""" """

View File

@ -6,9 +6,11 @@ class Parameter(object):
Attributes: Attributes:
parameters dictionary containing the value for configuration parameters parameters dictionary containing the value for configuration parameters
default_parameters dictionary containung default values for parameters
""" """
def __init__(self, parameter_filename): def __init__(self, parameter_filename):
self.parameters = {} self.parameters = {}
self.default_parameters = {}
if parameter_filename is None: if parameter_filename is None:
logging.warning("No parameter file provided; using default parameters") logging.warning("No parameter file provided; using default parameters")
else: else:
@ -37,9 +39,18 @@ class Parameter(object):
def get(self, key): def get(self, key):
""" """
Get the parameter with key `key`. If it does not exist, return None Get the value of the parameter with key `key`.
If not defined by the configuration file, return the default value.
Raise Exception if the parameter has no default value and is absent.
""" """
return self.parameters.get(key) val = self.parameters.get(key)
if val is None:
if key in self.default_parameters:
return self.default_parameters[key]
else:
raise Exception("Parameter not found " + key)
else:
return val
def __str__(self): def __str__(self):
return self.parameters.__str__() return self.parameters.__str__()

View File

@ -5,6 +5,9 @@ import math
class NetemAt(object): class NetemAt(object):
"""
Class representing a netem command to be run after some time
"""
def __init__(self, at, cmd): def __init__(self, at, cmd):
self.at = at self.at = at
self.cmd = cmd self.cmd = cmd
@ -110,89 +113,85 @@ Link id: {}
class TopoParameter(Parameter): class TopoParameter(Parameter):
LSUBNET = "leftSubnet" LEFT_SUBNET = "leftSubnet"
RSUBNET = "rightSubnet" RIGHT_SUBNET = "rightSubnet"
netem_at = "netem_at_" NETEM_AT = "netem_at_"
changeNetem = "changeNetem" CHANGE_NETEM = "changeNetem"
DEFAULT_PARAMETERS = {}
DEFAULT_PARAMETERS[LSUBNET] = "10.1." DEFAULT_PARAMETERS = {
DEFAULT_PARAMETERS[RSUBNET] = "10.2." LEFT_SUBNET: "10.1.",
DEFAULT_PARAMETERS[changeNetem] = "false" RIGHT_SUBNET: "10.2.",
CHANGE_NETEM: "false",
}
def __init__(self, parameter_filename): def __init__(self, parameter_filename):
Parameter.__init__(self, parameter_filename) Parameter.__init__(self, parameter_filename)
self.linkCharacteristics = [] self.default_parameters.update(TopoParameter.DEFAULT_PARAMETERS)
self.loadLinkCharacteristics() self.link_characteristics = []
self.loadNetemAt() self.load_link_characteristics()
print(self.__str__()) self.load_netem_at()
logging.info(self)
def loadNetemAt(self): def load_netem_at(self):
if not self.get(TopoParameter.changeNetem) == "yes": if not self.get(TopoParameter.CHANGE_NETEM) == "yes":
return return
for k in sorted(self.parameters): for k in sorted(self.parameters):
if k.startswith(TopoParameter.netem_at): if k.startswith(TopoParameter.NETEM_AT):
i = int(k[len(TopoParameter.netem_at):]) link_id = int(k[len(TopoParameter.NETEM_AT):])
val = self.parameters[k] val = self.parameters[k]
if not isinstance(val, list): if not isinstance(val, list):
tmp = val tmp = val
val = [] val = []
val.append(tmp) val.append(tmp)
self.loadNetemAtList(i, val) self.load_netem_at_list(link_id, val)
def loadNetemAtList(self, id, nlist): def load_netem_at_list(self, link_id, nlist):
for n in nlist: for n in nlist:
tab = n.split(",") try:
if len(tab)==2: at, cmd = n.split(",")
o = NetemAt(float(tab[0]), tab[1]) na = NetemAt(float(at), cmd)
if id < len(self.linkCharacteristics): if link_id < len(self.link_characteristics):
self.linkCharacteristics[id].add_netem_at(o) self.link_characteristics[id].add_netem_at(na)
else: else:
print("Error can't set netem for link " + str(id)) logging.error("Unable to set netem for link {}; only have {} links".format(
else: link_id, len(self.link_characteristics)))
print("Netem wrong line : " + n) except ValueError as e:
print(self.linkCharacteristics[id].netem_at) logging.error("Unable to set netem for link {}: {}".format(link_id, n))
def loadLinkCharacteristics(self): logging.info(self.link_characteristics[link_id].netem_at)
def load_link_characteristics(self):
"""
CAUTION: the path_i in config file is not taken into account. Hence place them in
increasing order in the topo parameter file!
"""
i = 0 i = 0
for k in sorted(self.parameters): for k in sorted(self.parameters):
# TODO FIXME rewrite this function
if k.startswith("path"): if k.startswith("path"):
tab = self.parameters[k].split(",") tab = self.parameters[k].split(",")
bup = False bup = False
loss = "0.0" loss = "0.0"
if len(tab) == 5: if len(tab) == 5:
loss = tab[3] loss = tab[3]
bup = tab[4] == 'True' bup = tab[4].lower() == 'true'
if len(tab) == 4: if len(tab) == 4:
try: try:
loss = float(tab[3]) loss = float(tab[3])
loss = tab[3] loss = tab[3]
except ValueError: except ValueError:
bup = tab[3] == 'True' bup = tab[3].lower() == 'true'
if len(tab) == 3 or len(tab) == 4 or len(tab) == 5: if len(tab) == 3 or len(tab) == 4 or len(tab) == 5:
path = LinkCharacteristics(i, tab[0], path = LinkCharacteristics(i, tab[0],
tab[1], tab[2], loss, bup) tab[1], tab[2], loss, bup)
self.linkCharacteristics.append(path) self.link_characteristics.append(path)
i = i + 1 i = i + 1
else: else:
print("Ignored path :") logging.warning("Ignored path {}".format(self.parameters[k]))
print(self.parameters[k])
def get(self, key):
val = Parameter.get(self, key)
if val is None:
if key in TopoParameter.DEFAULT_PARAMETERS:
return TopoParameter.DEFAULT_PARAMETERS[key]
else:
raise Exception("Param not found " + key)
else:
return val
def __str__(self): def __str__(self):
s = Parameter.__str__(self) s = "{}".format(super(TopoParameter, self).__str__())
s = s + "\n" s += "".join(["{}".format(lc) for lc in self.link_characteristics])
for p in self.linkCharacteristics[:-1]:
s = s + p.__str__() + "\n"
s = s + self.linkCharacteristics[-1].__str__()
return s return s
class Topo(object): class Topo(object):
@ -201,60 +200,65 @@ class Topo(object):
This class is not instantiable as it. You must define a child class with the This class is not instantiable as it. You must define a child class with the
`NAME` attribute. `NAME` attribute.
Attributes:
topo_builder instance of TopoBuilder
topo_parameter instance of TopoParameter
change_netem boolean indicating if netem must be changed
log_file file descriptor logging commands relative to the topo
""" """
MININET_BUILDER = "mininet" MININET_BUILDER = "mininet"
TOPO_ATTR = "topoType" TOPO_ATTR = "topoType"
switchNamePrefix = "s" SWITCH_NAME_PREFIX = "s"
routerNamePrefix = "r" ROUTER_NAME_PREFIX = "r"
clientName = "Client" CLIENT_NAME = "Client"
serverName = "Server" SERVER_NAME = "Server"
routerName = "Router" ROUTER_NAME = "Router"
cmdLog = "command.log" CMD_LOG_FILENAME = "command.log"
"""Simple MpTopo""" def __init__(self, topo_builder, topo_parameter):
def __init__(self, topoBuilder, topoParam): self.topo_builder = topo_builder
self.topoBuilder = topoBuilder self.topo_parameter = topo_parameter
self.topoParam = topoParam self.change_netem = topo_parameter.get(TopoParameter.CHANGE_NETEM).lower() == "yes"
self.changeNetem = topoParam.get(TopoParameter.changeNetem) self.log_file = open(Topo.CMD_LOG_FILENAME, 'w')
self.logFile = open(Topo.cmdLog, 'w')
def getLinkCharacteristics(self): def get_link_characteristics(self):
return self.topoParam.linkCharacteristics return self.topo_parameter.link_characteristics
def command_to(self, who, cmd): def command_to(self, who, cmd):
self.logFile.write(who.__str__() + " : " + cmd + "\n") self.log_file.write("{} : {}\n".format(who, cmd))
return self.topoBuilder.command_to(who, cmd) return self.topo_builder.command_to(who, cmd)
def command_global(self, cmd): def command_global(self, cmd):
""" """
mainly use for not namespace sysctl. mainly use for not namespace sysctl.
""" """
self.logFile.write("Not_NS" + " : " + cmd + "\n") self.log_file.write("Global : {}\n".format(cmd))
return self.topoBuilder.command_global(cmd) return self.topo_builder.command_global(cmd)
def get_host(self, who): def get_host(self, who):
return self.topoBuilder.get_host(who) return self.topo_builder.get_host(who)
def addHost(self, host): def add_host(self, host):
return self.topoBuilder.addHost(host) return self.topo_builder.add_host(host)
def addSwitch(self, switch): def add_switch(self, switch):
return self.topoBuilder.addSwitch(switch) return self.topo_builder.add_switch(switch)
def addLink(self, fromA, toB, **kwargs): def add_link(self, from_a, to_b, **kwargs):
self.topoBuilder.addLink(fromA,toB,**kwargs) self.topo_builder.add_link(from_a, to_b, **kwargs)
def get_cli(self): def get_cli(self):
self.topoBuilder.get_cli() self.topo_builder.get_cli()
def start_network(self): def start_network(self):
self.topoBuilder.start_network() self.topo_builder.start_network()
def closeLogFile(self): def close_log_file(self):
self.logFile.close() self.log_file.close()
def stop_network(self): def stop_network(self):
self.topoBuilder.stop_network() self.topo_builder.stop_network()
class TopoConfig(object): class TopoConfig(object):
@ -264,89 +268,78 @@ class TopoConfig(object):
This class is not instantiable as it. You must define a child class with the This class is not instantiable as it. You must define a child class with the
`NAME` attribute. `NAME` attribute.
""" """
PING_OUTPUT = "ping.log"
def __init__(self, topo, param): def __init__(self, topo, param):
self.topo = topo self.topo = topo
self.param = param self.param = param
def configure_network(self): def configure_network(self):
print("Configure interfaces....Generic call ?") logging.debug("Configure network in TopoConfig")
self.configureInterfaces() self.configure_interfaces()
self.configureRoute() self.configure_routing()
def disable_tso(self): def disable_tso(self):
""" """
Disable TSO on all interfaces Disable TSO on all interfaces
""" """
links = self.topo.getLinkCharacteristics() links = self.topo.get_link_characteristics()
for i, l in enumerate(links): for i, l in enumerate(links):
lname = self.getMidLeftName(i) lbox = self.topo.get_host(self.getMidLeftName(i))
rname = self.getMidRightName(i) rbox = self.topo.get_host(self.getMidRightName(i))
lbox = self.topo.get_host(lname)
lif = self.getMidL2RInterface(i) lif = self.getMidL2RInterface(i)
rif = self.getMidR2LInterface(i) rif = self.getMidR2LInterface(i)
rbox = self.topo.get_host(rname) logging.info("Disable TSO on link between {} and {}".format(lif, rif))
print(str(lname) + " " + str(lif)) cmd = "ethtool -K {} tso off".format(lif)
print(str(rname) + " " + str(rif)) logging.info(cmd)
print("boxes " + str(lbox) + " " + str(rbox))
cmd = "ethtool -K " + lif + " tso off"
print(cmd)
self.topo.command_to(lbox, cmd) self.topo.command_to(lbox, cmd)
cmd = "ethtool -K " + rif + " tso off" cmd = "ethtool -K {} tso off".format(rif)
print(cmd) logging.info(cmd)
self.topo.command_to(rbox, cmd) self.topo.command_to(rbox, cmd)
# And for the server # And for the server
cmd = "ethtool -K " + self.getServerInterface() + " tso off" cmd = "ethtool -K {} tso off".format(self.get_server_interface())
print(cmd) logging.info(cmd)
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
cmd = "ethtool -K " + self.get_router_interface_to_switch(self.client_interface_count()) + " tso off" cmd = "ethtool -K {} tso off".format(self.get_router_interface_to_switch(self.client_interface_count()))
print(cmd) logging.info(cmd)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
def run_netem_at(self): def run_netem_at(self):
""" """
Prepare netem commands to be run after some delay Prepare netem commands to be run after some delay
""" """
if not self.topo.changeNetem == "yes": if not self.topo.change_netem:
# Just rely on defaults of TCLink # Just rely on defaults of TCLink
logging.debug("No need to change netem") logging.info("No need to change netem")
return return
logging.info("Will change netem config on the fly") logging.info("Will change netem config on the fly")
links = self.topo.getLinkCharacteristics() links = self.topo.get_link_characteristics()
for i, l in enumerate(links): for i, l in enumerate(links):
lname = self.getMidLeftName(i) lbox = self.topo.get_host(self.getMidLeftName(i))
rname = self.getMidRightName(i) rbox = self.topo.get_host(self.getMidRightName(i))
lbox = self.topo.get_host(lname)
lif = self.getMidL2RInterface(i) lif = self.getMidL2RInterface(i)
rif = self.getMidR2LInterface(i) rif = self.getMidR2LInterface(i)
rbox = self.topo.get_host(rname) logging.info("Put netem command on link {} {}".format(lif, rif))
print(str(lname) + " " + str(lif))
print(str(rname) + " " + str(rif))
print("boxes " + str(lbox) + " " + str(rbox))
cmd = l.build_bandwidth_cmd(lif) cmd = l.build_bandwidth_cmd(lif)
print(cmd) logging.info(cmd)
self.topo.command_to(lbox, cmd) self.topo.command_to(lbox, cmd)
cmd = l.build_bandwidth_cmd(rif) cmd = l.build_bandwidth_cmd(rif)
print(cmd) logging.info(cmd)
self.topo.command_to(rbox, cmd) self.topo.command_to(rbox, cmd)
ilif = self.getMidL2RIncomingInterface(i) ilif = self.getMidL2RIncomingInterface(i)
irif = self.getMidR2LIncomingInterface(i) irif = self.getMidR2LIncomingInterface(i)
cmd = l.build_policing_cmd(ilif) cmd = l.build_policing_cmd(ilif)
print(cmd) logging.info(cmd)
self.topo.command_to(lbox, cmd) self.topo.command_to(lbox, cmd)
cmd = l.build_policing_cmd(irif) cmd = l.build_policing_cmd(irif)
print(cmd) logging.info(cmd)
self.topo.command_to(rbox, cmd) self.topo.command_to(rbox, cmd)
cmd = l.build_netem_cmd(irif) cmd = l.build_netem_cmd(irif)
print(cmd) logging.info(cmd)
self.topo.command_to(rbox, cmd) self.topo.command_to(rbox, cmd)
cmd = l.build_netem_cmd(ilif) cmd = l.build_netem_cmd(ilif)
print(cmd) logging.info(cmd)
self.topo.command_to(lbox, cmd) self.topo.command_to(lbox, cmd)
def getMidL2RInterface(self, id): def getMidL2RInterface(self, id):
@ -363,7 +356,16 @@ class TopoConfig(object):
def getMidRightName(self, i): def getMidRightName(self, i):
pass pass
def configureInterfaces(self): def configure_interfaces(self):
"""
Function to override to configure the interfaces of the topology
"""
pass
def configure_routing(self):
"""
Function to override to configure the routing of the topology
"""
pass pass
def client_interface_count(self): def client_interface_count(self):
@ -384,51 +386,28 @@ class TopoConfig(object):
""" """
raise NotImplementedError() raise NotImplementedError()
def interface_backup_command(self, interfaceName): def interface_backup_command(self, interface_name):
s = "/home/mininet/git/iproute-mptcp/ip/ip link set dev " + interfaceName + " multipath backup " return "ip link set dev {} multipath backup ".format(
print(s) interface_name)
return s
def interfaceUpCommand(self, interfaceName, ip, subnet): def interface_up_command(self, interface_name, ip, subnet):
s = "ifconfig " + interfaceName + " " + ip + " netmask " + \ return "ifconfig {} {} netmask {}".format(interface_name, ip, subnet)
subnet
print(s)
return s
def addRouteTableCommand(self, fromIP, id): def add_table_route_command(self, from_ip, id):
s = "ip rule add from " + fromIP + " table " + str(id + 1) return "ip rule add from {} table {}".format(from_ip, id + 1)
print(s)
return s
def addRouteScopeLinkCommand(self, network, interfaceName, id): def add_link_scope_route_command(self, network, interface_name, id):
s = "ip route add " + network + " dev " + interfaceName + \ return "ip route add {} dev {} scope link table {}".format(
" scope link table " + str(id + 1) network, interface_name, id + 1)
print(s)
return s
def addRouteDefaultCommand(self, via, id): def add_table_default_route_command(self, via, id):
s = "ip route add default via " + via + " table " + str(id + 1) return "ip route add default via {} table {}".format(via, id + 1)
print(s)
return s
def addRouteDefaultGlobalCommand(self, via, interfaceName): def add_global_default_route_command(self, via, interface_name):
s = "ip route add default scope global nexthop via " + via + \ return "ip route add default scope global nexthop via {} dev {}".format(via, interface_name)
" dev " + interfaceName
print(s)
return s
def arpCommand(self, ip, mac): def arp_command(self, ip, mac):
s = "arp -s " + ip + " " + mac return "arp -s {} {}".format(ip, mac)
print(s)
return s
def addRouteDefaultSimple(self, via): def add_simple_default_route_command(self, via):
s = "ip route add default via " + via return "ip route add default via {}".format(via)
print(s)
return s
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + TopoConfig.PING_OUTPUT
print(s)
return s

View File

@ -26,21 +26,6 @@ class AB(RandomFileExperiment):
def __init__(self, experiment_parameter_filename, topo, topo_config): def __init__(self, experiment_parameter_filename, topo, topo_config):
super(AB, self).__init__(experiment_parameter_filename, topo, topo_config) super(AB, self).__init__(experiment_parameter_filename, topo, topo_config)
def ping(self):
self.topo.command_to(self.topo_config.client,
"rm " + AB.PING_OUTPUT)
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + AB.PING_OUTPUT
print(s)
return s
def load_parameters(self): def load_parameters(self):
super(AB, self).load_parameters() super(AB, self).load_parameters()
self.concurrent_requests = self.experiment_parameter.get(ABParameter.CONCURRENT_REQUESTS) self.concurrent_requests = self.experiment_parameter.get(ABParameter.CONCURRENT_REQUESTS)

View File

@ -41,21 +41,6 @@ class DITG(Experiment):
self.load_parameters() self.load_parameters()
self.ping() self.ping()
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
Experiment.PING_OUTPUT)
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + DITG.PING_OUTPUT
print(s)
return s
def load_parameters(self): def load_parameters(self):
self.kbytes = self.experiment_parameter.get(DITGParameter.KBYTES) self.kbytes = self.experiment_parameter.get(DITGParameter.KBYTES)
self.constant_packet_size = self.experiment_parameter.get(DITGParameter.CONSTANT_PACKET_SIZE) self.constant_packet_size = self.experiment_parameter.get(DITGParameter.CONSTANT_PACKET_SIZE)

View File

@ -26,21 +26,6 @@ class Epload(Experiment):
self.load_parameters() self.load_parameters()
self.ping() self.ping()
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
Epload.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + Epload.PING_OUTPUT
print(s)
return s
def load_parameters(self): def load_parameters(self):
self.test_dir = self.experiment_parameter.get(EploadParameter.TEST_DIR) self.test_dir = self.experiment_parameter.get(EploadParameter.TEST_DIR)

View File

@ -13,21 +13,6 @@ class HTTP(RandomFileExperiment):
# Just rely on RandomFileExperiment # Just rely on RandomFileExperiment
super(HTTP, self).__init__(experiment_parameter_filename, topo, topo_config) super(HTTP, self).__init__(experiment_parameter_filename, topo, topo_config)
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
HTTP.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + HTTP.PING_OUTPUT
print(s)
return s
def load_parameters(self): def load_parameters(self):
# Just rely on RandomFileExperiment # Just rely on RandomFileExperiment
super(HTTP, self).load_parameters() super(HTTP, self).load_parameters()

View File

@ -13,21 +13,6 @@ class HTTPS(RandomFileExperiment):
# Just rely on RandomFileExperiment # Just rely on RandomFileExperiment
super(HTTPS, self).__init__(experiment_parameter_filename, topo, topo_config) super(HTTPS, self).__init__(experiment_parameter_filename, topo, topo_config)
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
HTTPS.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + HTTPS.PING_OUTPUT
print(s)
return s
def load_parameters(self): def load_parameters(self):
# Just rely on RandomFileExperiment # Just rely on RandomFileExperiment
super(HTTPS, self).load_parameters() super(HTTPS, self).load_parameters()

View File

@ -31,11 +31,11 @@ class IPerf(Experiment):
IPerf.PING_OUTPUT) IPerf.PING_OUTPUT)
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + IPerf.PING_OUTPUT " >> " + IPerf.PING_OUTPUT
print(s) print(s)

View File

@ -36,11 +36,11 @@ class Msg(Experiment):
Msg.PING_OUTPUT ) Msg.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + Msg.PING_OUTPUT " >> " + Msg.PING_OUTPUT
print(s) print(s)

View File

@ -52,11 +52,11 @@ class NCPV(NC):
NCPV.PING_OUTPUT ) NCPV.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + NCPV.PING_OUTPUT " >> " + NCPV.PING_OUTPUT
print(s) print(s)

View File

@ -36,11 +36,11 @@ class Netperf(Experiment):
Netperf.PING_OUTPUT) Netperf.PING_OUTPUT)
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + Netperf.PING_OUTPUT " >> " + Netperf.PING_OUTPUT
print(s) print(s)

View File

@ -19,11 +19,11 @@ class Ping(Experiment):
Ping.PING_OUTPUT ) Ping.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + Ping.PING_OUTPUT " >> " + Ping.PING_OUTPUT
print(s) print(s)

View File

@ -35,11 +35,11 @@ class QUIC(RandomFileExperiment):
QUIC.PING_OUTPUT ) QUIC.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + QUIC.PING_OUTPUT " >> " + QUIC.PING_OUTPUT
print(s) print(s)

View File

@ -34,11 +34,11 @@ class QUICSiri(Experiment):
QUICSiri.PING_OUTPUT ) QUICSiri.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + QUICSiri.PING_OUTPUT " >> " + QUICSiri.PING_OUTPUT
print(s) print(s)

View File

@ -18,11 +18,11 @@ class SendFile(RandomFileExperiment):
SendFile.PING_OUTPUT ) SendFile.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + SendFile.PING_OUTPUT " >> " + SendFile.PING_OUTPUT
print(s) print(s)

View File

@ -49,11 +49,11 @@ class Siri(Experiment):
Siri.PING_OUTPUT ) Siri.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + Siri.PING_OUTPUT " >> " + Siri.PING_OUTPUT
print(s) print(s)

View File

@ -23,11 +23,11 @@ class SiriHTTP(Siri, RandomFileExperiment):
SiriHTTP.PING_OUTPUT ) SiriHTTP.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + SiriHTTP.PING_OUTPUT " >> " + SiriHTTP.PING_OUTPUT
print(s) print(s)

View File

@ -31,11 +31,11 @@ class VLC(Experiment):
VLC.PING_OUTPUT ) VLC.PING_OUTPUT )
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT) count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
for i in range(0, self.topo_config.client_interface_count()): for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i), cmd = self.ping_command(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count) self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5): def ping_command(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + VLC.PING_OUTPUT " >> " + VLC.PING_OUTPUT
print(s) print(s)

View File

@ -100,7 +100,7 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
logging.basicConfig(level=logging.INFO) logging.basicConfig(format="%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s", level=logging.INFO)
# XXX Currently, there is no alternate topo builder... # XXX Currently, there is no alternate topo builder...
Runner(Topo.MININET_BUILDER, args.topo_param_file, args.experiment_param_file) Runner(Topo.MININET_BUILDER, args.topo_param_file, args.experiment_param_file)

View File

@ -4,35 +4,35 @@ from struct import *
class ECMPSingleInterfaceTopo(Topo): class ECMPSingleInterfaceTopo(Topo):
NAME = "ECMPLike" NAME = "ECMPLike"
def __init__(self, topoBuilder, parameterFile): def __init__(self, topo_builder, parameterFile):
super(ECMPSingleInterfaceTopo, self).__init__(topoBuilder, parameterFile) super(ECMPSingleInterfaceTopo, self).__init__(topo_builder, parameterFile)
print("Hello ECMP topo") print("Hello ECMP topo")
self.client = self.addHost(Topo.clientName) self.client = self.add_host(Topo.CLIENT_NAME)
self.server = self.addHost(Topo.serverName) self.server = self.add_host(Topo.SERVER_NAME)
self.lswitch = self.addSwitch(Topo.switchNamePrefix + "0") self.lswitch = self.add_switch(Topo.SWITCH_NAME_PREFIX + "0")
self.rswitch = self.addSwitch(Topo.switchNamePrefix + "1") self.rswitch = self.add_switch(Topo.SWITCH_NAME_PREFIX + "1")
self.addLink( self.client, self.lswitch) self.add_link( self.client, self.lswitch)
self.addLink( self.server, self.rswitch) self.add_link( self.server, self.rswitch)
self.routers = [] self.routers = []
for l in self.topoParam.linkCharacteristics: for l in self.topo_parameter.link_characteristics:
self.routers.append(self.addOneRouterPerLink(l)) self.routers.append(self.addOneRouterPerLink(l))
print("added : " + self.routers[-1]) print("added : " + self.routers[-1])
self.addLink(self.lswitch, self.routers[-1]) self.add_link(self.lswitch, self.routers[-1])
self.addLink(self.rswitch, self.routers[-1], **l.as_dict()) self.add_link(self.rswitch, self.routers[-1], **l.as_dict())
def addOneRouterPerLink(self, link): def addOneRouterPerLink(self, link):
return self.addHost(Topo.routerNamePrefix + return self.add_host(Topo.ROUTER_NAME_PREFIX +
str(link.id)) str(link.id))
def __str__(self): def __str__(self):
s = "Single if ECMP like env\n" s = "Single if ECMP like env\n"
i = 0 i = 0
n = len(self.topoParam.linkCharacteristics) n = len(self.topo_parameter.link_characteristics)
for p in self.topoParam.linkCharacteristics: for p in self.topo_parameter.link_characteristics:
if i == n // 2: if i == n // 2:
if n % 2 == 0: if n % 2 == 0:
s = s + "c---sw sw-----s\n" s = s + "c---sw sw-----s\n"
@ -52,7 +52,7 @@ class ECMPSingleInterfaceConfig(TopoConfig):
def __init__(self, topo, param): def __init__(self, topo, param):
super(ECMPSingleInterfaceConfig, self).__init__(topo, param) super(ECMPSingleInterfaceConfig, self).__init__(topo, param)
def configureRoute(self): def configure_routing(self):
i = 0 i = 0
mask = len(self.topo.routers) - 1 mask = len(self.topo.routers) - 1
for l in self.topo.routers: for l in self.topo.routers:
@ -79,10 +79,10 @@ class ECMPSingleInterfaceConfig(TopoConfig):
i = i + 1 i = i + 1
### ###
cmd = self.addRouteDefaultSimple(self.getRouterIPServer(0)) cmd = self.add_simple_default_route_command(self.getRouterIPServer(0))
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
cmd = self.addRouteDefaultSimple(self.getRouterIPClient(0)) cmd = self.add_simple_default_route_command(self.getRouterIPClient(0))
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
self.topo.command_to(self.client, "ip route flush cache") self.topo.command_to(self.client, "ip route flush cache")
@ -129,57 +129,57 @@ class ECMPSingleInterfaceConfig(TopoConfig):
print(s) print(s)
return s return s
def configureInterfaces(self): def configure_interfaces(self):
self.client = self.topo.get_host(Topo.clientName) self.client = self.topo.get_host(Topo.CLIENT_NAME)
self.server = self.topo.get_host(Topo.serverName) self.server = self.topo.get_host(Topo.SERVER_NAME)
self.routers = [] self.routers = []
i = 0 i = 0
netmask = "255.255.255.0" netmask = "255.255.255.0"
for l in self.topo.routers: for l in self.topo.routers:
self.routers.append(self.topo.get_host( self.routers.append(self.topo.get_host(
Topo.routerNamePrefix + str(i))) Topo.ROUTER_NAME_PREFIX + str(i)))
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.getRouterInterfaceLSwitch(i), self.getRouterInterfaceLSwitch(i),
self.getRouterIPClient(i), netmask) self.getRouterIPClient(i), netmask)
self.topo.command_to(self.routers[-1] , cmd) self.topo.command_to(self.routers[-1] , cmd)
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.getRouterInterfaceRSwitch(i), self.getRouterInterfaceRSwitch(i),
self.getRouterIPServer(i), netmask) self.getRouterIPServer(i), netmask)
self.topo.command_to(self.routers[-1] , cmd) self.topo.command_to(self.routers[-1] , cmd)
i = i + 1 i = i + 1
cmd = self.interfaceUpCommand(self.get_client_interface(0), cmd = self.interface_up_command(self.get_client_interface(0),
self.getClientIP(0), netmask) self.getClientIP(0), netmask)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.interfaceUpCommand(self.getServerInterface(), cmd = self.interface_up_command(self.get_server_interface(),
self.getServerIP(), netmask) self.getServerIP(), netmask)
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
def getClientIP(self, interfaceID): def getClientIP(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientIP = lSubnet + str(interfaceID) + ".1" clientIP = lSubnet + str(interfaceID) + ".1"
return clientIP return clientIP
def getClientSubnet(self, interfaceID): def getClientSubnet(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientSubnet = lSubnet + str(interfaceID) + ".0/24" clientSubnet = lSubnet + str(interfaceID) + ".0/24"
return clientSubnet return clientSubnet
def getRouterIPClient(self, id): def getRouterIPClient(self, id):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
routerIP = lSubnet + "0." + str(id + 2) routerIP = lSubnet + "0." + str(id + 2)
return routerIP return routerIP
def getRouterIPServer(self, id): def getRouterIPServer(self, id):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
routerIP = rSubnet + "0." + str(id + 2) routerIP = rSubnet + "0." + str(id + 2)
return routerIP return routerIP
def getServerIP(self): def getServerIP(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
serverIP = rSubnet + "0.1" serverIP = rSubnet + "0.1"
return serverIP return serverIP
@ -187,22 +187,22 @@ class ECMPSingleInterfaceConfig(TopoConfig):
return 1 return 1
def getRouterInterfaceLSwitch(self, id): def getRouterInterfaceLSwitch(self, id):
return Topo.routerNamePrefix + str(id) + "-eth0" return Topo.ROUTER_NAME_PREFIX + str(id) + "-eth0"
def getRouterInterfaceRSwitch(self, id): def getRouterInterfaceRSwitch(self, id):
return Topo.routerNamePrefix + str(id) + "-eth1" return Topo.ROUTER_NAME_PREFIX + str(id) + "-eth1"
def get_client_interface(self, interfaceID): def get_client_interface(self, interfaceID):
return Topo.clientName + "-eth" + str(interfaceID) return Topo.CLIENT_NAME + "-eth" + str(interfaceID)
def getServerInterface(self): def get_server_interface(self):
return Topo.serverName + "-eth0" return Topo.SERVER_NAME + "-eth0"
def getMidLeftName(self, id): def getMidLeftName(self, id):
return Topo.routerNamePrefix + str(id) return Topo.ROUTER_NAME_PREFIX + str(id)
def getMidRightName(self, id): def getMidRightName(self, id):
return Topo.switchNamePrefix + "1" return Topo.SWITCH_NAME_PREFIX + "1"
def getMidL2RInterface(self, id): def getMidL2RInterface(self, id):
return self.getMidLeftName(id) + "-eth1" return self.getMidLeftName(id) + "-eth1"

View File

@ -3,35 +3,35 @@ from core.topo import Topo, TopoConfig, TopoParameter
class MultiInterfaceTopo(Topo): class MultiInterfaceTopo(Topo):
NAME = "MultiIf" NAME = "MultiIf"
def __init__(self, topoBuilder, parameterFile): def __init__(self, topo_builder, parameterFile):
super(MultiInterfaceTopo, self).__init__(topoBuilder, parameterFile) super(MultiInterfaceTopo, self).__init__(topo_builder, parameterFile)
print("Hello from topo multi if") print("Hello from topo multi if")
self.client = self.addHost(Topo.clientName) self.client = self.add_host(Topo.CLIENT_NAME)
self.server = self.addHost(Topo.serverName) self.server = self.add_host(Topo.SERVER_NAME)
self.router = self.addHost(Topo.routerName) self.router = self.add_host(Topo.ROUTER_NAME)
self.switchClient = [] self.switchClient = []
self.switchServer = [] self.switchServer = []
for l in self.topoParam.linkCharacteristics: for l in self.topo_parameter.link_characteristics:
self.switchClient.append(self.addSwitch1ForLink(l)) self.switchClient.append(self.add_switch1ForLink(l))
self.addLink(self.client,self.switchClient[-1]) self.add_link(self.client,self.switchClient[-1])
self.switchServer.append(self.addSwitch2ForLink(l)) self.switchServer.append(self.add_switch2ForLink(l))
self.addLink(self.switchClient[-1], self.switchServer[-1], **l.as_dict()) self.add_link(self.switchClient[-1], self.switchServer[-1], **l.as_dict())
self.addLink(self.switchServer[-1],self.router) self.add_link(self.switchServer[-1],self.router)
self.addLink(self.router, self.server) self.add_link(self.router, self.server)
def addSwitch1ForLink(self, link): def add_switch1ForLink(self, link):
return self.addSwitch(MultiInterfaceTopo.switchNamePrefix + return self.add_switch(MultiInterfaceTopo.SWITCH_NAME_PREFIX +
str(2 * link.id)) str(2 * link.id))
def addSwitch2ForLink(self, link): def add_switch2ForLink(self, link):
return self.addSwitch(MultiInterfaceTopo.switchNamePrefix + return self.add_switch(MultiInterfaceTopo.SWITCH_NAME_PREFIX +
str(2 * link.id + 1)) str(2 * link.id + 1))
def __str__(self): def __str__(self):
s = "Simple multiple interface topolgy \n" s = "Simple multiple interface topolgy \n"
i = 0 i = 0
n = len(self.topoParam.linkCharacteristics) n = len(self.topo_parameter.link_characteristics)
for p in self.topoParam.linkCharacteristics: for p in self.topo_parameter.link_characteristics:
if i == n // 2: if i == n // 2:
if n % 2 == 0: if n % 2 == 0:
s = s + "c r-----s\n" s = s + "c r-----s\n"
@ -50,40 +50,40 @@ class MultiInterfaceConfig(TopoConfig):
def __init__(self, topo, param): def __init__(self, topo, param):
super(MultiInterfaceConfig, self).__init__(topo, param) super(MultiInterfaceConfig, self).__init__(topo, param)
def configureRoute(self): def configure_routing(self):
i = 0 i = 0
for l in self.topo.switchClient: for l in self.topo.switchClient:
cmd = self.addRouteTableCommand(self.getClientIP(i), i) cmd = self.add_table_route_command(self.getClientIP(i), i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteScopeLinkCommand( cmd = self.add_link_scope_route_command(
self.getClientSubnet(i), self.getClientSubnet(i),
self.get_client_interface(i), i) self.get_client_interface(i), i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteDefaultCommand(self.getRouterIPSwitch(i), cmd = self.add_table_default_route_command(self.getRouterIPSwitch(i),
i) i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
i = i + 1 i = i + 1
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(0), cmd = self.add_global_default_route_command(self.getRouterIPSwitch(0),
self.get_client_interface(0)) self.get_client_interface(0))
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteDefaultSimple(self.getRouterIPServer()) cmd = self.add_simple_default_route_command(self.getRouterIPServer())
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
def configureInterfaces(self): def configure_interfaces(self):
print("Configure interfaces for multi inf") print("Configure interfaces for multi inf")
self.client = self.topo.get_host(Topo.clientName) self.client = self.topo.get_host(Topo.CLIENT_NAME)
self.server = self.topo.get_host(Topo.serverName) self.server = self.topo.get_host(Topo.SERVER_NAME)
self.router = self.topo.get_host(Topo.routerName) self.router = self.topo.get_host(Topo.ROUTER_NAME)
i = 0 i = 0
netmask = "255.255.255.0" netmask = "255.255.255.0"
links = self.topo.getLinkCharacteristics() links = self.topo.get_link_characteristics()
for l in self.topo.switchClient: for l in self.topo.switchClient:
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.get_client_interface(i), self.get_client_interface(i),
self.getClientIP(i), netmask) self.getClientIP(i), netmask)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
@ -99,7 +99,7 @@ class MultiInterfaceConfig(TopoConfig):
i = 0 i = 0
for l in self.topo.switchServer: for l in self.topo.switchServer:
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.get_router_interface_to_switch(i), self.get_router_interface_to_switch(i),
self.getRouterIPSwitch(i), netmask) self.getRouterIPSwitch(i), netmask)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
@ -108,40 +108,40 @@ class MultiInterfaceConfig(TopoConfig):
print(str(links[i])) print(str(links[i]))
i = i + 1 i = i + 1
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(), cmd = self.interface_up_command(self.getRouterInterfaceServer(),
self.getRouterIPServer(), netmask) self.getRouterIPServer(), netmask)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC() routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac) self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
cmd = self.interfaceUpCommand(self.getServerInterface(), cmd = self.interface_up_command(self.get_server_interface(),
self.getServerIP(), netmask) self.getServerIP(), netmask)
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
serverIntfMac = self.server.intf(self.getServerInterface()).MAC() serverIntfMac = self.server.intf(self.get_server_interface()).MAC()
self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac) self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
def getClientIP(self, interfaceID): def getClientIP(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientIP = lSubnet + str(interfaceID) + ".1" clientIP = lSubnet + str(interfaceID) + ".1"
return clientIP return clientIP
def getClientSubnet(self, interfaceID): def getClientSubnet(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientSubnet = lSubnet + str(interfaceID) + ".0/24" clientSubnet = lSubnet + str(interfaceID) + ".0/24"
return clientSubnet return clientSubnet
def getRouterIPSwitch(self, interfaceID): def getRouterIPSwitch(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
routerIP = lSubnet + str(interfaceID) + ".2" routerIP = lSubnet + str(interfaceID) + ".2"
return routerIP return routerIP
def getRouterIPServer(self): def getRouterIPServer(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
routerIP = rSubnet + "0.2" routerIP = rSubnet + "0.2"
return routerIP return routerIP
def getServerIP(self): def getServerIP(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
serverIP = rSubnet + "0.1" serverIP = rSubnet + "0.1"
return serverIP return serverIP
@ -152,19 +152,19 @@ class MultiInterfaceConfig(TopoConfig):
return self.get_router_interface_to_switch(len(self.topo.switchServer)) return self.get_router_interface_to_switch(len(self.topo.switchServer))
def get_client_interface(self, interfaceID): def get_client_interface(self, interfaceID):
return Topo.clientName + "-eth" + str(interfaceID) return Topo.CLIENT_NAME + "-eth" + str(interfaceID)
def get_router_interface_to_switch(self, interfaceID): def get_router_interface_to_switch(self, interfaceID):
return Topo.routerName + "-eth" + str(interfaceID) return Topo.ROUTER_NAME + "-eth" + str(interfaceID)
def getServerInterface(self): def get_server_interface(self):
return Topo.serverName + "-eth0" return Topo.SERVER_NAME + "-eth0"
def getSwitchClientName(self, id): def getSwitchClientName(self, id):
return Topo.switchNamePrefix + str(2 * id) return Topo.SWITCH_NAME_PREFIX + str(2 * id)
def getSwitchServerName(self, id): def getSwitchServerName(self, id):
return Topo.switchNamePrefix + str(2 * id + 1) return Topo.SWITCH_NAME_PREFIX + str(2 * id + 1)
def getMidLeftName(self, id): def getMidLeftName(self, id):
return self.getSwitchClientName(id) return self.getSwitchClientName(id)

View File

@ -7,25 +7,25 @@ class MultiInterfaceCongTopo(Topo):
congClientName = "CCli" congClientName = "CCli"
congServerName = "CSer" congServerName = "CSer"
def __init__(self, topoBuilder, parameterFile): def __init__(self, topo_builder, parameterFile):
super(MultiInterfaceCongTopo, self).__init__(topoBuilder, parameterFile) super(MultiInterfaceCongTopo, self).__init__(topo_builder, parameterFile)
print("Hello from topo multi if") print("Hello from topo multi if")
self.client = self.addHost(Topo.clientName) self.client = self.add_host(Topo.CLIENT_NAME)
self.server = self.addHost(Topo.serverName) self.server = self.add_host(Topo.SERVER_NAME)
self.router = self.addHost(Topo.routerName) self.router = self.add_host(Topo.ROUTER_NAME)
self.cong_clients = [] self.cong_clients = []
self.cong_servers = [] self.cong_servers = []
self.switch = [] self.switch = []
for l in self.topoParam.linkCharacteristics: for l in self.topo_parameter.link_characteristics:
self.switch.append(self.addOneSwitchPerLink(l)) self.switch.append(self.addOneSwitchPerLink(l))
self.addLink(self.client,self.switch[-1]) self.add_link(self.client,self.switch[-1])
self.cong_clients.append(self.addHost(MultiInterfaceCongTopo.congClientName + str(len(self.cong_clients)))) self.cong_clients.append(self.add_host(MultiInterfaceCongTopo.congClientName + str(len(self.cong_clients))))
self.addLink(self.cong_clients[-1], self.switch[-1]) self.add_link(self.cong_clients[-1], self.switch[-1])
self.addLink(self.switch[-1],self.router, **l.as_dict()) self.add_link(self.switch[-1],self.router, **l.as_dict())
self.addLink(self.router, self.server) self.add_link(self.router, self.server)
for i in range(len(self.cong_clients)): for i in range(len(self.cong_clients)):
self.cong_servers.append(self.addHost(MultiInterfaceCongTopo.congServerName + str(len(self.cong_servers)))) self.cong_servers.append(self.add_host(MultiInterfaceCongTopo.congServerName + str(len(self.cong_servers))))
self.addLink(self.router, self.cong_servers[-1]) self.add_link(self.router, self.cong_servers[-1])
def getCongClients(self): def getCongClients(self):
return self.cong_clients return self.cong_clients
@ -34,14 +34,14 @@ class MultiInterfaceCongTopo(Topo):
return self.cong_servers return self.cong_servers
def addOneSwitchPerLink(self, link): def addOneSwitchPerLink(self, link):
return self.addSwitch(MultiInterfaceCongTopo.switchNamePrefix + return self.add_switch(MultiInterfaceCongTopo.SWITCH_NAME_PREFIX +
str(link.id)) str(link.id))
def __str__(self): def __str__(self):
s = "Simple multiple interface topology with congestion \n" s = "Simple multiple interface topology with congestion \n"
i = 0 i = 0
n = len(self.topoParam.linkCharacteristics) n = len(self.topo_parameter.link_characteristics)
for p in self.topoParam.linkCharacteristics: for p in self.topo_parameter.link_characteristics:
if i == n // 2: if i == n // 2:
if n % 2 == 0: if n % 2 == 0:
s = s + "c r-----s\n" s = s + "c r-----s\n"
@ -61,28 +61,28 @@ class MultiInterfaceCongConfig(TopoConfig):
def __init__(self, topo, param): def __init__(self, topo, param):
super(MultiInterfaceCongConfig, self).__init__(topo, param) super(MultiInterfaceCongConfig, self).__init__(topo, param)
def configureRoute(self): def configure_routing(self):
i = 0 i = 0
for l in self.topo.switch: for l in self.topo.switch:
cmd = self.addRouteTableCommand(self.getClientIP(i), i) cmd = self.add_table_route_command(self.getClientIP(i), i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Congestion client # Congestion client
cmd = self.addRouteTableCommand(self.getCongClientIP(i), i) cmd = self.add_table_route_command(self.getCongClientIP(i), i)
self.topo.command_to(self.cong_clients[i], cmd) self.topo.command_to(self.cong_clients[i], cmd)
cmd = self.addRouteScopeLinkCommand( cmd = self.add_link_scope_route_command(
self.getClientSubnet(i), self.getClientSubnet(i),
self.get_client_interface(i), i) self.get_client_interface(i), i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Congestion client # Congestion client
cmd = self.addRouteScopeLinkCommand( cmd = self.add_link_scope_route_command(
self.getClientSubnet(i), self.getClientSubnet(i),
self.getCongClientInterface(i), i) self.getCongClientInterface(i), i)
self.topo.command_to(self.cong_clients[i], cmd) self.topo.command_to(self.cong_clients[i], cmd)
cmd = self.addRouteDefaultCommand(self.getRouterIPSwitch(i), cmd = self.add_table_default_route_command(self.getRouterIPSwitch(i),
i) i)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
@ -91,37 +91,37 @@ class MultiInterfaceCongConfig(TopoConfig):
self.topo.command_to(self.cong_clients[i], cmd) self.topo.command_to(self.cong_clients[i], cmd)
# Congestion client # Congestion client
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(i), cmd = self.add_global_default_route_command(self.getRouterIPSwitch(i),
self.getCongClientInterface(i)) self.getCongClientInterface(i))
i = i + 1 i = i + 1
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(0), cmd = self.add_global_default_route_command(self.getRouterIPSwitch(0),
self.get_client_interface(0)) self.get_client_interface(0))
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Congestion Client # Congestion Client
i = 0 i = 0
for c in self.cong_clients: for c in self.cong_clients:
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(i), cmd = self.add_global_default_route_command(self.getRouterIPSwitch(i),
self.getCongClientInterface(i)) self.getCongClientInterface(i))
self.topo.command_to(c, cmd) self.topo.command_to(c, cmd)
i = i + 1 i = i + 1
cmd = self.addRouteDefaultSimple(self.getRouterIPServer()) cmd = self.add_simple_default_route_command(self.getRouterIPServer())
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
# Congestion servers # Congestion servers
i = 0 i = 0
for s in self.cong_servers: for s in self.cong_servers:
cmd = self.addRouteDefaultSimple(self.getRouterIPCongServer(i)) cmd = self.add_simple_default_route_command(self.getRouterIPCongServer(i))
self.topo.command_to(s, cmd) self.topo.command_to(s, cmd)
i += 1 i += 1
def configureInterfaces(self): def configure_interfaces(self):
print("Configure interfaces for multi inf") print("Configure interfaces for multi inf")
self.client = self.topo.get_host(Topo.clientName) self.client = self.topo.get_host(Topo.CLIENT_NAME)
self.server = self.topo.get_host(Topo.serverName) self.server = self.topo.get_host(Topo.SERVER_NAME)
self.router = self.topo.get_host(Topo.routerName) self.router = self.topo.get_host(Topo.ROUTER_NAME)
cong_client_names = self.topo.getCongClients() cong_client_names = self.topo.getCongClients()
self.cong_clients = [] self.cong_clients = []
for cn in cong_client_names: for cn in cong_client_names:
@ -134,9 +134,9 @@ class MultiInterfaceCongConfig(TopoConfig):
i = 0 i = 0
netmask = "255.255.255.0" netmask = "255.255.255.0"
links = self.topo.getLinkCharacteristics() links = self.topo.get_link_characteristics()
for l in self.topo.switch: for l in self.topo.switch:
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.get_client_interface(i), self.get_client_interface(i),
self.getClientIP(i), netmask) self.getClientIP(i), netmask)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
@ -149,14 +149,14 @@ class MultiInterfaceCongConfig(TopoConfig):
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Congestion client # Congestion client
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.getCongClientInterface(i), self.getCongClientInterface(i),
self.getCongClientIP(i), netmask) self.getCongClientIP(i), netmask)
self.topo.command_to(self.cong_clients[i], cmd) self.topo.command_to(self.cong_clients[i], cmd)
congClientIntfMac = self.cong_clients[i].intf(self.getCongClientInterface(i)).MAC() congClientIntfMac = self.cong_clients[i].intf(self.getCongClientInterface(i)).MAC()
self.topo.command_to(self.router, "arp -s " + self.getCongClientIP(i) + " " + congClientIntfMac) self.topo.command_to(self.router, "arp -s " + self.getCongClientIP(i) + " " + congClientIntfMac)
cmd = self.interfaceUpCommand( cmd = self.interface_up_command(
self.get_router_interface_to_switch(i), self.get_router_interface_to_switch(i),
self.getRouterIPSwitch(i), netmask) self.getRouterIPSwitch(i), netmask)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
@ -167,28 +167,28 @@ class MultiInterfaceCongConfig(TopoConfig):
print(str(links[i])) print(str(links[i]))
i = i + 1 i = i + 1
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(), cmd = self.interface_up_command(self.getRouterInterfaceServer(),
self.getRouterIPServer(), netmask) self.getRouterIPServer(), netmask)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC() routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac) self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
cmd = self.interfaceUpCommand(self.getServerInterface(), cmd = self.interface_up_command(self.get_server_interface(),
self.getServerIP(), netmask) self.getServerIP(), netmask)
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
serverIntfMac = self.server.intf(self.getServerInterface()).MAC() serverIntfMac = self.server.intf(self.get_server_interface()).MAC()
self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac) self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
# Congestion servers # Congestion servers
i = 0 i = 0
for s in self.cong_servers: for s in self.cong_servers:
cmd = self.interfaceUpCommand(self.getRouterInterfaceCongServer(i), cmd = self.interface_up_command(self.getRouterInterfaceCongServer(i),
self.getRouterIPCongServer(i), netmask) self.getRouterIPCongServer(i), netmask)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
routerIntfMac = self.router.intf(self.getRouterInterfaceCongServer(i)).MAC() routerIntfMac = self.router.intf(self.getRouterInterfaceCongServer(i)).MAC()
self.topo.command_to(s, "arp -s " + self.getRouterIPCongServer(i) + " " + routerIntfMac) self.topo.command_to(s, "arp -s " + self.getRouterIPCongServer(i) + " " + routerIntfMac)
cmd = self.interfaceUpCommand(self.getCongServerInterface(i), cmd = self.interface_up_command(self.getCongServerInterface(i),
self.getCongServerIP(i), netmask) self.getCongServerIP(i), netmask)
self.topo.command_to(s, cmd) self.topo.command_to(s, cmd)
congServerIntfMac = s.intf(self.getCongServerInterface(i)).MAC() congServerIntfMac = s.intf(self.getCongServerInterface(i)).MAC()
@ -196,42 +196,42 @@ class MultiInterfaceCongConfig(TopoConfig):
i = i + 1 i = i + 1
def getClientIP(self, interfaceID): def getClientIP(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientIP = lSubnet + str(interfaceID) + ".1" clientIP = lSubnet + str(interfaceID) + ".1"
return clientIP return clientIP
def getCongClientIP(self, interfaceID): def getCongClientIP(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
congClientIP = lSubnet + str(interfaceID) + ".127" congClientIP = lSubnet + str(interfaceID) + ".127"
return congClientIP return congClientIP
def getClientSubnet(self, interfaceID): def getClientSubnet(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientSubnet = lSubnet + str(interfaceID) + ".0/24" clientSubnet = lSubnet + str(interfaceID) + ".0/24"
return clientSubnet return clientSubnet
def getRouterIPSwitch(self, interfaceID): def getRouterIPSwitch(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
routerIP = lSubnet + str(interfaceID) + ".2" routerIP = lSubnet + str(interfaceID) + ".2"
return routerIP return routerIP
def getRouterIPServer(self): def getRouterIPServer(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
routerIP = rSubnet + "0.2" routerIP = rSubnet + "0.2"
return routerIP return routerIP
def getRouterIPCongServer(self, congID): def getRouterIPCongServer(self, congID):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
routerIP = rSubnet + str(1 + congID) + ".2" routerIP = rSubnet + str(1 + congID) + ".2"
return routerIP return routerIP
def getServerIP(self): def getServerIP(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
serverIP = rSubnet + "0.1" serverIP = rSubnet + "0.1"
return serverIP return serverIP
def getCongServerIP(self, congID): def getCongServerIP(self, congID):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
serverIP = rSubnet + str(1 + congID) + ".1" serverIP = rSubnet + str(1 + congID) + ".1"
return serverIP return serverIP
@ -245,25 +245,25 @@ class MultiInterfaceCongConfig(TopoConfig):
return self.get_router_interface_to_switch(len(self.topo.switch) + 1 + congID) return self.get_router_interface_to_switch(len(self.topo.switch) + 1 + congID)
def get_client_interface(self, interfaceID): def get_client_interface(self, interfaceID):
return Topo.clientName + "-eth" + str(interfaceID) return Topo.CLIENT_NAME + "-eth" + str(interfaceID)
def getCongClientInterface(self, interfaceID): def getCongClientInterface(self, interfaceID):
return MultiInterfaceCongConfig.congClientName + str(interfaceID) + "-eth0" return MultiInterfaceCongConfig.congClientName + str(interfaceID) + "-eth0"
def get_router_interface_to_switch(self, interfaceID): def get_router_interface_to_switch(self, interfaceID):
return Topo.routerName + "-eth" + str(interfaceID) return Topo.ROUTER_NAME + "-eth" + str(interfaceID)
def getServerInterface(self): def get_server_interface(self):
return Topo.serverName + "-eth0" return Topo.SERVER_NAME + "-eth0"
def getCongServerInterface(self, interfaceID): def getCongServerInterface(self, interfaceID):
return MultiInterfaceCongConfig.congServerName + str(interfaceID) + "-eth0" return MultiInterfaceCongConfig.congServerName + str(interfaceID) + "-eth0"
def getMidLeftName(self, id): def getMidLeftName(self, id):
return Topo.switchNamePrefix + str(id) return Topo.SWITCH_NAME_PREFIX + str(id)
def getMidRightName(self, id): def getMidRightName(self, id):
return Topo.routerName return Topo.ROUTER_NAME
def getMidL2RInterface(self, id): def getMidL2RInterface(self, id):
return self.getMidLeftName(id) + "-eth2" return self.getMidLeftName(id) + "-eth2"

View File

@ -4,8 +4,8 @@ from core.topo import Topo, TopoConfig, TopoParameter
class TwoInterfaceCongestionTopo(Topo): class TwoInterfaceCongestionTopo(Topo):
NAME = "twoIfCong" NAME = "twoIfCong"
def __init__(self, topoBuilder, parameterFile): def __init__(self, topo_builder, parameterFile):
super(TwoInterfaceCongestionTopo, self).__init__(topoBuilder, parameterFile) super(TwoInterfaceCongestionTopo, self).__init__(topo_builder, parameterFile)
print("Hello from topo two ifs cong") print("Hello from topo two ifs cong")
print("Expected topo:") print("Expected topo:")
@ -14,37 +14,37 @@ class TwoInterfaceCongestionTopo(Topo):
print(" | |------s2") print(" | |------s2")
print("c2----link2----") print("c2----link2----")
self.client = self.addHost(Topo.clientName) self.client = self.add_host(Topo.CLIENT_NAME)
self.clientCong = self.addHost(Topo.clientName + "Cong") self.clientCong = self.add_host(Topo.CLIENT_NAME + "Cong")
self.server = self.addHost(Topo.serverName) self.server = self.add_host(Topo.SERVER_NAME)
self.serverCong = self.addHost(Topo.serverName + "Cong") self.serverCong = self.add_host(Topo.SERVER_NAME + "Cong")
self.router = self.addHost(Topo.routerName) self.router = self.add_host(Topo.ROUTER_NAME)
self.routerCong = self.addHost(Topo.routerName + "Cong") self.routerCong = self.add_host(Topo.ROUTER_NAME + "Cong")
self.switch = [] self.switch = []
# Link between c1 and r2 # Link between c1 and r2
self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[0])) self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[0]))
self.addLink(self.client, self.switch[-1]) self.add_link(self.client, self.switch[-1])
self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[0].as_dict()) self.add_link(self.switch[-1], self.router, **self.topo_parameter.link_characteristics[0].as_dict())
# Link between c1 and r1 # Link between c1 and r1
self.addLink(self.client, self.routerCong) self.add_link(self.client, self.routerCong)
# Link between c2 and r1 # Link between c2 and r1
self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[2])) self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[2]))
self.addLink(self.clientCong, self.switch[-1]) self.add_link(self.clientCong, self.switch[-1])
self.addLink(self.switch[-1], self.routerCong, **self.topoParam.linkCharacteristics[2].as_dict()) self.add_link(self.switch[-1], self.routerCong, **self.topo_parameter.link_characteristics[2].as_dict())
# Link between r1 and r2 # Link between r1 and r2
self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[1])) self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[1]))
self.addLink(self.routerCong, self.switch[-1]) self.add_link(self.routerCong, self.switch[-1])
self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[1].as_dict()) self.add_link(self.switch[-1], self.router, **self.topo_parameter.link_characteristics[1].as_dict())
# Link between r2 and s1 # Link between r2 and s1
self.addLink(self.router, self.server) self.add_link(self.router, self.server)
# Link between r2 and s2 # Link between r2 and s2
self.addLink(self.router, self.serverCong) self.add_link(self.router, self.serverCong)
def __str__(self): def __str__(self):
s = "Hello from topo two ifs cong \n" s = "Hello from topo two ifs cong \n"
@ -55,7 +55,7 @@ class TwoInterfaceCongestionTopo(Topo):
return s return s
def addOneSwitchPerLink(self, link): def addOneSwitchPerLink(self, link):
return self.addSwitch(Topo.switchNamePrefix + str(link.id)) return self.add_switch(Topo.SWITCH_NAME_PREFIX + str(link.id))
class TwoInterfaceCongestionConfig(TopoConfig): class TwoInterfaceCongestionConfig(TopoConfig):
@ -64,158 +64,158 @@ class TwoInterfaceCongestionConfig(TopoConfig):
def __init__(self, topo, param): def __init__(self, topo, param):
super(TwoInterfaceCongestionConfig, self).__init__(topo, param) super(TwoInterfaceCongestionConfig, self).__init__(topo, param)
def configureRoute(self): def configure_routing(self):
# Client - Router # Client - Router
cmd = self.addRouteTableCommand("10.0.0.1", 0) cmd = self.add_table_route_command("10.0.0.1", 0)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteScopeLinkCommand("10.0.0.0/24", Topo.clientName + "-eth0", 0) cmd = self.add_link_scope_route_command("10.0.0.0/24", Topo.CLIENT_NAME + "-eth0", 0)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteDefaultCommand("10.0.0.2", 0) cmd = self.add_table_default_route_command("10.0.0.2", 0)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Client -> Router cong # Client -> Router cong
cmd = self.addRouteTableCommand("10.0.1.1", 1) cmd = self.add_table_route_command("10.0.1.1", 1)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteScopeLinkCommand("10.0.1.0/24", Topo.clientName + "-eth1", 1) cmd = self.add_link_scope_route_command("10.0.1.0/24", Topo.CLIENT_NAME + "-eth1", 1)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
cmd = self.addRouteDefaultCommand("10.0.1.2", 1) cmd = self.add_table_default_route_command("10.0.1.2", 1)
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Client cong -> Router cong # Client cong -> Router cong
cmd = self.addRouteTableCommand("10.0.2.1", 0) cmd = self.add_table_route_command("10.0.2.1", 0)
self.topo.command_to(self.clientCong, cmd) self.topo.command_to(self.clientCong, cmd)
cmd = self.addRouteScopeLinkCommand("10.0.2.0/24", Topo.clientName + "Cong-eth0", 0) cmd = self.add_link_scope_route_command("10.0.2.0/24", Topo.CLIENT_NAME + "Cong-eth0", 0)
self.topo.command_to(self.clientCong, cmd) self.topo.command_to(self.clientCong, cmd)
cmd = self.addRouteDefaultCommand("10.0.2.2", 0) cmd = self.add_table_default_route_command("10.0.2.2", 0)
self.topo.command_to(self.clientCong, cmd) self.topo.command_to(self.clientCong, cmd)
# Router cong -> Router # Router cong -> Router
cmd = self.addRouteTableCommand("10.0.3.1", 0) cmd = self.add_table_route_command("10.0.3.1", 0)
self.topo.command_to(self.routerCong, cmd) self.topo.command_to(self.routerCong, cmd)
cmd = self.addRouteScopeLinkCommand("10.1.0.0/16", Topo.routerName + "Cong-eth2", 0) cmd = self.add_link_scope_route_command("10.1.0.0/16", Topo.ROUTER_NAME + "Cong-eth2", 0)
self.topo.command_to(self.routerCong, cmd) self.topo.command_to(self.routerCong, cmd)
cmd = self.addRouteDefaultCommand("10.0.3.2", 0) cmd = self.add_table_default_route_command("10.0.3.2", 0)
self.topo.command_to(self.routerCong, cmd) self.topo.command_to(self.routerCong, cmd)
# Router -> Router cong # Router -> Router cong
cmd = self.addRouteTableCommand("10.0.3.2", 0) cmd = self.add_table_route_command("10.0.3.2", 0)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
cmd = self.addRouteScopeLinkCommand("10.0.0.0/16", Topo.routerName + "-eth1", 0) cmd = self.add_link_scope_route_command("10.0.0.0/16", Topo.ROUTER_NAME + "-eth1", 0)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
cmd = self.addRouteDefaultCommand("10.0.3.1", 0) cmd = self.add_table_default_route_command("10.0.3.1", 0)
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
# Default route Client # Default route Client
cmd = self.addRouteDefaultGlobalCommand("10.0.0.2", Topo.clientName + "-eth0") cmd = self.add_global_default_route_command("10.0.0.2", Topo.CLIENT_NAME + "-eth0")
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
# Default route Client cong # Default route Client cong
cmd = self.addRouteDefaultGlobalCommand("10.0.2.2", Topo.clientName + "Cong-eth0") cmd = self.add_global_default_route_command("10.0.2.2", Topo.CLIENT_NAME + "Cong-eth0")
self.topo.command_to(self.clientCong, cmd) self.topo.command_to(self.clientCong, cmd)
# Default route Router cong # Default route Router cong
cmd = self.addRouteDefaultGlobalCommand("10.0.3.2", Topo.routerName + "Cong-eth2") cmd = self.add_global_default_route_command("10.0.3.2", Topo.ROUTER_NAME + "Cong-eth2")
self.topo.command_to(self.routerCong, cmd) self.topo.command_to(self.routerCong, cmd)
# Default route Router # Default route Router
cmd = self.addRouteDefaultGlobalCommand("10.0.3.1", Topo.routerName + "-eth1") cmd = self.add_global_default_route_command("10.0.3.1", Topo.ROUTER_NAME + "-eth1")
self.topo.command_to(self.router, cmd) self.topo.command_to(self.router, cmd)
# Default route Server # Default route Server
cmd = self.addRouteDefaultGlobalCommand("10.1.0.2", Topo.serverName + "-eth0") cmd = self.add_global_default_route_command("10.1.0.2", Topo.SERVER_NAME + "-eth0")
self.topo.command_to(self.server, cmd) self.topo.command_to(self.server, cmd)
# Default route Server cong # Default route Server cong
cmd = self.addRouteDefaultGlobalCommand("10.1.1.2", Topo.serverName + "Cong-eth0") cmd = self.add_global_default_route_command("10.1.1.2", Topo.SERVER_NAME + "Cong-eth0")
self.topo.command_to(self.serverCong, cmd) self.topo.command_to(self.serverCong, cmd)
def configureInterface(self, srcHost, dstHost, srcInterfaceName, srcIP, netmask): def configureInterface(self, srcHost, dstHost, srcInterfaceName, srcIP, netmask):
cmd = self.interfaceUpCommand(srcInterfaceName, srcIP, netmask) cmd = self.interface_up_command(srcInterfaceName, srcIP, netmask)
self.topo.command_to(srcHost, cmd) self.topo.command_to(srcHost, cmd)
mac = srcHost.intf(srcInterfaceName).MAC() mac = srcHost.intf(srcInterfaceName).MAC()
cmd = self.arpCommand(srcIP, mac) cmd = self.arp_command(srcIP, mac)
self.topo.command_to(dstHost, cmd) self.topo.command_to(dstHost, cmd)
def configureInterfaces(self): def configure_interfaces(self):
print("Configure interfaces for two inf cong") print("Configure interfaces for two inf cong")
self.client = self.topo.get_host(Topo.clientName) self.client = self.topo.get_host(Topo.CLIENT_NAME)
self.clientCong = self.topo.get_host(Topo.clientName + "Cong") self.clientCong = self.topo.get_host(Topo.CLIENT_NAME + "Cong")
self.server = self.topo.get_host(Topo.serverName) self.server = self.topo.get_host(Topo.SERVER_NAME)
self.serverCong = self.topo.get_host(Topo.serverName + "Cong") self.serverCong = self.topo.get_host(Topo.SERVER_NAME + "Cong")
self.router = self.topo.get_host(Topo.routerName) self.router = self.topo.get_host(Topo.ROUTER_NAME)
self.routerCong = self.topo.get_host(Topo.routerName + "Cong") self.routerCong = self.topo.get_host(Topo.ROUTER_NAME + "Cong")
netmask = "255.255.255.0" netmask = "255.255.255.0"
links = self.topo.getLinkCharacteristics() links = self.topo.get_link_characteristics()
# Link 0: Client - Router # Link 0: Client - Router
self.configureInterface(self.client, self.router, Topo.clientName + "-eth0", "10.0.0.1", netmask) self.configureInterface(self.client, self.router, Topo.CLIENT_NAME + "-eth0", "10.0.0.1", netmask)
if(links[0].backup): if(links[0].backup):
cmd = self.interface_backup_command(Topo.clientName + "-eth0") cmd = self.interface_backup_command(Topo.CLIENT_NAME + "-eth0")
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
self.configureInterface(self.router, self.client, Topo.routerName + "-eth0", "10.0.0.2", netmask) self.configureInterface(self.router, self.client, Topo.ROUTER_NAME + "-eth0", "10.0.0.2", netmask)
print(str(links[0])) print(str(links[0]))
# Client - Router cong # Client - Router cong
self.configureInterface(self.client, self.routerCong, Topo.clientName + "-eth1", "10.0.1.1", netmask) self.configureInterface(self.client, self.routerCong, Topo.CLIENT_NAME + "-eth1", "10.0.1.1", netmask)
if(links[1].backup): if(links[1].backup):
cmd = self.interface_backup_command(Topo.clientName + "-eth1") cmd = self.interface_backup_command(Topo.CLIENT_NAME + "-eth1")
self.topo.command_to(self.client, cmd) self.topo.command_to(self.client, cmd)
self.configureInterface(self.routerCong, self.client, Topo.routerName + "Cong-eth0", "10.0.1.2", netmask) self.configureInterface(self.routerCong, self.client, Topo.ROUTER_NAME + "Cong-eth0", "10.0.1.2", netmask)
# Link 1: Router - Router cong # Link 1: Router - Router cong
self.configureInterface(self.routerCong, self.router, Topo.routerName + "Cong-eth2", "10.0.3.1", netmask) self.configureInterface(self.routerCong, self.router, Topo.ROUTER_NAME + "Cong-eth2", "10.0.3.1", netmask)
self.configureInterface(self.router, self.routerCong, Topo.routerName + "-eth1", "10.0.3.2", netmask) self.configureInterface(self.router, self.routerCong, Topo.ROUTER_NAME + "-eth1", "10.0.3.2", netmask)
print(str(links[1])) print(str(links[1]))
# Link 2: Client cong - Router cong # Link 2: Client cong - Router cong
self.configureInterface(self.clientCong, self.routerCong, Topo.clientName + "Cong-eth0", "10.0.2.1", netmask) self.configureInterface(self.clientCong, self.routerCong, Topo.CLIENT_NAME + "Cong-eth0", "10.0.2.1", netmask)
self.configureInterface(self.routerCong, self.clientCong, Topo.routerName + "Cong-eth1", "10.0.2.2", netmask) self.configureInterface(self.routerCong, self.clientCong, Topo.ROUTER_NAME + "Cong-eth1", "10.0.2.2", netmask)
print(str(links[2])) print(str(links[2]))
# Router - Server # Router - Server
self.configureInterface(self.server, self.router, Topo.serverName + "-eth0", "10.1.0.1", netmask) self.configureInterface(self.server, self.router, Topo.SERVER_NAME + "-eth0", "10.1.0.1", netmask)
self.configureInterface(self.router, self.server, Topo.routerName + "-eth2", "10.1.0.2", netmask) self.configureInterface(self.router, self.server, Topo.ROUTER_NAME + "-eth2", "10.1.0.2", netmask)
# Router - Server cong # Router - Server cong
self.configureInterface(self.serverCong, self.router, Topo.serverName + "Cong-eth0", "10.1.1.1", netmask) self.configureInterface(self.serverCong, self.router, Topo.SERVER_NAME + "Cong-eth0", "10.1.1.1", netmask)
self.configureInterface(self.router, self.serverCong, Topo.routerName + "-eth3", "10.1.1.2", netmask) self.configureInterface(self.router, self.serverCong, Topo.ROUTER_NAME + "-eth3", "10.1.1.2", netmask)
def getClientIP(self, interfaceID): def getClientIP(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientIP = lSubnet + str(interfaceID) + ".1" clientIP = lSubnet + str(interfaceID) + ".1"
return clientIP return clientIP
def getClientSubnet(self, interfaceID): def getClientSubnet(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientSubnet = lSubnet + str(interfaceID) + ".0/24" clientSubnet = lSubnet + str(interfaceID) + ".0/24"
return clientSubnet return clientSubnet
def getClientCongIP(self): def getClientCongIP(self):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientIP = lSubnet + str(2) + ".1" clientIP = lSubnet + str(2) + ".1"
return clientIP return clientIP
def getClientCongSubnet(self, interfaceID): def getClientCongSubnet(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
clientSubnet = lSubnet + str(128) + ".0/24" clientSubnet = lSubnet + str(128) + ".0/24"
return clientSubnet return clientSubnet
def getRouterIPSwitch(self, interfaceID): def getRouterIPSwitch(self, interfaceID):
lSubnet = self.param.get(TopoParameter.LSUBNET) lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
routerIP = lSubnet + str(interfaceID) + ".2" routerIP = lSubnet + str(interfaceID) + ".2"
return routerIP return routerIP
def getRouterIPServer(self): def getRouterIPServer(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
routerIP = rSubnet + "0.2" routerIP = rSubnet + "0.2"
return routerIP return routerIP
def getServerIP(self): def getServerIP(self):
rSubnet = self.param.get(TopoParameter.RSUBNET) rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
serverIP = rSubnet + "0.1" serverIP = rSubnet + "0.1"
return serverIP return serverIP
@ -226,22 +226,22 @@ class TwoInterfaceCongestionConfig(TopoConfig):
return self.get_router_interface_to_switch(len(self.topo.switch)) return self.get_router_interface_to_switch(len(self.topo.switch))
def get_client_interface(self, interfaceID): def get_client_interface(self, interfaceID):
return Topo.clientName + "-eth" + str(interfaceID) return Topo.CLIENT_NAME + "-eth" + str(interfaceID)
def get_router_interface_to_switch(self, interfaceID): def get_router_interface_to_switch(self, interfaceID):
return Topo.routerName + "-eth" + str(interfaceID) return Topo.ROUTER_NAME + "-eth" + str(interfaceID)
def getServerInterface(self): def get_server_interface(self):
return Topo.serverName + "-eth0" return Topo.SERVER_NAME + "-eth0"
def getMidLeftName(self, id): def getMidLeftName(self, id):
return Topo.switchNamePrefix + str(id) return Topo.SWITCH_NAME_PREFIX + str(id)
def getMidRightName(self, id): def getMidRightName(self, id):
if id == 2: if id == 2:
return Topo.routerName + "Cong" return Topo.ROUTER_NAME + "Cong"
return Topo.routerName return Topo.ROUTER_NAME
def getMidL2RInterface(self, id): def getMidL2RInterface(self, id):
return self.getMidLeftName(id) + "-eth2" return self.getMidLeftName(id) + "-eth2"