From bcd306b21da01ac6b41cf4dd77793aba9410b703 Mon Sep 17 00:00:00 2001 From: Quentin De Coninck Date: Wed, 24 Jun 2020 12:28:44 +0200 Subject: [PATCH] move topos in their own module --- core/experience.py | 6 +- core/topo.py | 16 +++-- mpECMPSingleInterfaceTopo.py | 44 ------------- mpExperienceQUIC.py | 10 +-- mpMultiInterfaceCongTopo.py | 52 --------------- mpMultiInterfaceTopo.py | 44 ------------- mpTwoInterfaceCongestionTopo.py | 55 ---------------- mpXpRunner.py | 44 +++---------- topos/__init__.py | 12 ++++ .../ecmp_single_interface.py | 52 ++++++++++++++- .../multi_interface.py | 51 +++++++++++++- .../multi_interface_cong.py | 66 +++++++++++++++++-- .../two_interface_congestion.py | 65 +++++++++++++++++- 13 files changed, 260 insertions(+), 257 deletions(-) delete mode 100644 mpECMPSingleInterfaceTopo.py delete mode 100644 mpMultiInterfaceCongTopo.py delete mode 100644 mpMultiInterfaceTopo.py delete mode 100644 mpTwoInterfaceCongestionTopo.py create mode 100644 topos/__init__.py rename mpECMPSingleInterfaceConfig.py => topos/ecmp_single_interface.py (77%) rename mpMultiInterfaceConfig.py => topos/multi_interface.py (73%) rename mpMultiInterfaceCongConfig.py => topos/multi_interface_cong.py (78%) rename mpTwoInterfaceCongestionConfig.py => topos/two_interface_congestion.py (76%) diff --git a/core/experience.py b/core/experience.py index cd4e343..1ea220e 100644 --- a/core/experience.py +++ b/core/experience.py @@ -1,5 +1,5 @@ from .parameter import ExperienceParameter -from mpMultiInterfaceTopo import MpMultiInterfaceTopo +from topos.multi_interface import MultiInterfaceTopo class Experience(object): PING = "ping" @@ -50,8 +50,8 @@ class Experience(object): self.mpTopo.notNSCommand("echo " + metric + " > /sys/module/mptcp_sched_metric/parameters/metric") def putPriorityOnPaths(self): - # Only meaningful if mpTopo is instance of MpMultiInterfaceTopo - if isinstance(self.mpTopo, MpMultiInterfaceTopo): + # Only meaningful if mpTopo is instance of MultiInterfaceTopo + if isinstance(self.mpTopo, MultiInterfaceTopo): prioPath0 = self.xpParam.getParam(ExperienceParameter.PRIOPATH0) prioPath1 = self.xpParam.getParam(ExperienceParameter.PRIOPATH1) if not prioPath0 == prioPath1: diff --git a/core/topo.py b/core/topo.py index 890f25e..71f084e 100644 --- a/core/topo.py +++ b/core/topo.py @@ -201,11 +201,13 @@ class TopoParameter(Parameter): return s class Topo(object): + """ + Base class to instantiate a topology. + + This class is not instantiable as it. You must define a child class with the + `NAME` attribute. + """ mininetBuilder = "mininet" - multiIfTopo = "MultiIf" - ECMPLikeTopo = "ECMPLike" - twoIfCongTopo = "twoIfCong" - multiIfCongTopo = "MultiIfCong" topoAttr = "topoType" switchNamePrefix = "s" routerNamePrefix = "r" @@ -261,6 +263,12 @@ class Topo(object): class TopoConfig(object): + """ + Base class to instantiate a topology. + + This class is not instantiable as it. You must define a child class with the + `NAME` attribute. + """ PING_OUTPUT = "ping.log" diff --git a/mpECMPSingleInterfaceTopo.py b/mpECMPSingleInterfaceTopo.py deleted file mode 100644 index 7b7b33f..0000000 --- a/mpECMPSingleInterfaceTopo.py +++ /dev/null @@ -1,44 +0,0 @@ -from core.topo import Topo - -class MpECMPSingleInterfaceTopo(Topo): - def __init__(self, topoBuilder, parameterFile): - super(MpECMPSingleInterfaceTopo, self).__init__(topoBuilder, parameterFile) - - print("Hello ECMP topo") - - self.client = self.addHost(Topo.clientName) - self.server = self.addHost(Topo.serverName) - self.lswitch = self.addSwitch(Topo.switchNamePrefix + "0") - self.rswitch = self.addSwitch(Topo.switchNamePrefix + "1") - - self.addLink( self.client, self.lswitch) - self.addLink( self.server, self.rswitch) - - self.routers = [] - for l in self.topoParam.linkCharacteristics: - self.routers.append(self.addOneRouterPerLink(l)) - print("added : " + self.routers[-1]) - self.addLink(self.lswitch, self.routers[-1]) - self.addLink(self.rswitch, self.routers[-1], **l.asDict()) - - def addOneRouterPerLink(self, link): - return self.addHost(Topo.routerNamePrefix + - str(link.id)) - - def __str__(self): - s = "Single if ECMP like env\n" - i = 0 - n = len(self.topoParam.linkCharacteristics) - for p in self.topoParam.linkCharacteristics: - if i == n // 2: - if n % 2 == 0: - s = s + "c---sw sw-----s\n" - s = s + " |-----R-----|\n" - else: - s = s + "c---sw----R-----sw-----s\n" - else: - s = s + " |-----R-----|\n" - - i = i + 1 - return s - diff --git a/mpExperienceQUIC.py b/mpExperienceQUIC.py index 88b9ac3..01f9828 100644 --- a/mpExperienceQUIC.py +++ b/mpExperienceQUIC.py @@ -1,5 +1,5 @@ from core.experience import Experience, ExperienceParameter -from mpMultiInterfaceCongConfig import MpMultiInterfaceCongConfig +from topos.multi_interface_cong import MultiInterfaceCongConfig import os @@ -93,7 +93,7 @@ class ExperienceQUIC(Experience): self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_before") self.mpTopo.commandTo(self.mpConfig.server, cmd) - if isinstance(self.mpConfig, MpMultiInterfaceCongConfig): + if isinstance(self.mpConfig, MultiInterfaceCongConfig): i = 0 for cs in self.mpConfig.cong_servers: cmd = self.getCongServerCmd(i) @@ -104,7 +104,7 @@ class ExperienceQUIC(Experience): self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_before") # First run congestion clients, then the main one - if isinstance(self.mpConfig, MpMultiInterfaceCongConfig): + if isinstance(self.mpConfig, MultiInterfaceCongConfig): i = 0 for cc in self.mpConfig.cong_clients: cmd = self.getCongClientCmd(i) @@ -116,12 +116,12 @@ class ExperienceQUIC(Experience): self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_after") self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_after") # Wait for congestion traffic to end - if isinstance(self.mpConfig, MpMultiInterfaceCongConfig): + if isinstance(self.mpConfig, MultiInterfaceCongConfig): for cc in self.mpConfig.cong_clients: self.mpTopo.commandTo(cc, "while pkill -f wget -0; do sleep 0.5; done") self.mpTopo.commandTo(self.mpConfig.server, "pkill -f " + ExperienceQUIC.SERVER_GO_FILE) - if isinstance(self.mpConfig, MpMultiInterfaceCongConfig): + if isinstance(self.mpConfig, MultiInterfaceCongConfig): for cs in self.mpConfig.cong_servers: self.mpTopo.commandTo(cs, "pkill -f https.py") diff --git a/mpMultiInterfaceCongTopo.py b/mpMultiInterfaceCongTopo.py deleted file mode 100644 index aa45ef5..0000000 --- a/mpMultiInterfaceCongTopo.py +++ /dev/null @@ -1,52 +0,0 @@ -from core.topo import Topo - -class MpMultiInterfaceCongTopo(Topo): - congClientName = "CCli" - congServerName = "CSer" - - def __init__(self, topoBuilder, parameterFile): - super(MpMultiInterfaceCongTopo, self).__init__(topoBuilder, parameterFile) - print("Hello from topo multi if") - self.client = self.addHost(Topo.clientName) - self.server = self.addHost(Topo.serverName) - self.router = self.addHost(Topo.routerName) - self.cong_clients = [] - self.cong_servers = [] - self.switch = [] - for l in self.topoParam.linkCharacteristics: - self.switch.append(self.addOneSwitchPerLink(l)) - self.addLink(self.client,self.switch[-1]) - self.cong_clients.append(self.addHost(MpMultiInterfaceCongTopo.congClientName + str(len(self.cong_clients)))) - self.addLink(self.cong_clients[-1], self.switch[-1]) - self.addLink(self.switch[-1],self.router, **l.asDict()) - self.addLink(self.router, self.server) - for i in range(len(self.cong_clients)): - self.cong_servers.append(self.addHost(MpMultiInterfaceCongTopo.congServerName + str(len(self.cong_servers)))) - self.addLink(self.router, self.cong_servers[-1]) - - def getCongClients(self): - return self.cong_clients - - def getCongServers(self): - return self.cong_servers - - def addOneSwitchPerLink(self, link): - return self.addSwitch(MpMultiInterfaceCongTopo.switchNamePrefix + - str(link.id)) - - def __str__(self): - s = "Simple multiple interface topology with congestion \n" - i = 0 - n = len(self.topoParam.linkCharacteristics) - for p in self.topoParam.linkCharacteristics: - if i == n // 2: - if n % 2 == 0: - s = s + "c r-----s\n" - s = s + "|-----sw-----|\n" - else: - s = s + "c-----sw-----r-----s\n" - else: - s = s + "|-----sw-----|\n" - - i = i + 1 - return s diff --git a/mpMultiInterfaceTopo.py b/mpMultiInterfaceTopo.py deleted file mode 100644 index 152d818..0000000 --- a/mpMultiInterfaceTopo.py +++ /dev/null @@ -1,44 +0,0 @@ -from core.topo import Topo - -class MpMultiInterfaceTopo(Topo): - def __init__(self, topoBuilder, parameterFile): - super(MpMultiInterfaceTopo, self).__init__(topoBuilder, parameterFile) - print("Hello from topo multi if") - self.client = self.addHost(Topo.clientName) - self.server = self.addHost(Topo.serverName) - self.router = self.addHost(Topo.routerName) - self.switchClient = [] - self.switchServer = [] - for l in self.topoParam.linkCharacteristics: - self.switchClient.append(self.addSwitch1ForLink(l)) - self.addLink(self.client,self.switchClient[-1]) - self.switchServer.append(self.addSwitch2ForLink(l)) - self.addLink(self.switchClient[-1], self.switchServer[-1], **l.asDict()) - self.addLink(self.switchServer[-1],self.router) - self.addLink(self.router, self.server) - - def addSwitch1ForLink(self, link): - return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix + - str(2 * link.id)) - - def addSwitch2ForLink(self, link): - return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix + - str(2 * link.id + 1)) - - def __str__(self): - s = "Simple multiple interface topolgy \n" - i = 0 - n = len(self.topoParam.linkCharacteristics) - for p in self.topoParam.linkCharacteristics: - if i == n // 2: - if n % 2 == 0: - s = s + "c r-----s\n" - s = s + "|--sw----sw--|\n" - else: - s = s + "c--sw----sw--r-----s\n" - else: - s = s + "|--sw----sw--|\n" - - i = i + 1 - return s - diff --git a/mpTwoInterfaceCongestionTopo.py b/mpTwoInterfaceCongestionTopo.py deleted file mode 100644 index 53778ce..0000000 --- a/mpTwoInterfaceCongestionTopo.py +++ /dev/null @@ -1,55 +0,0 @@ -from core.topo import Topo - -class MpTwoInterfaceCongestionTopo(Topo): - def __init__(self, topoBuilder, parameterFile): - super(MpTwoInterfaceCongestionTopo, self).__init__(topoBuilder, parameterFile) - - print("Hello from topo two ifs cong") - print("Expected topo:") - print("c1----link0--------------|") - print("|-------------r1--link1--r2-----s1") - print(" | |------s2") - print("c2----link2----") - - self.client = self.addHost(Topo.clientName) - self.clientCong = self.addHost(Topo.clientName + "Cong") - self.server = self.addHost(Topo.serverName) - self.serverCong = self.addHost(Topo.serverName + "Cong") - self.router = self.addHost(Topo.routerName) - self.routerCong = self.addHost(Topo.routerName + "Cong") - self.switch = [] - - # Link between c1 and r2 - self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[0])) - self.addLink(self.client, self.switch[-1]) - self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[0].asDict()) - - # Link between c1 and r1 - self.addLink(self.client, self.routerCong) - - # Link between c2 and r1 - self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[2])) - self.addLink(self.clientCong, self.switch[-1]) - self.addLink(self.switch[-1], self.routerCong, **self.topoParam.linkCharacteristics[2].asDict()) - - # Link between r1 and r2 - self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[1])) - self.addLink(self.routerCong, self.switch[-1]) - self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[1].asDict()) - - # Link between r2 and s1 - self.addLink(self.router, self.server) - - # Link between r2 and s2 - self.addLink(self.router, self.serverCong) - - def __str__(self): - s = "Hello from topo two ifs cong \n" - s = s + "c1----link0--------------| \n" - s = s + "|-------------r1--link1--r2-----s1 \n" - s = s + " | |------s2 \n" - s = s + "c2----link2---- \n" - return s - - def addOneSwitchPerLink(self, link): - return self.addSwitch(Topo.switchNamePrefix + str(link.id)) diff --git a/mpXpRunner.py b/mpXpRunner.py index 90dbfa2..c5984ac 100644 --- a/mpXpRunner.py +++ b/mpXpRunner.py @@ -3,12 +3,8 @@ from core.topo import Topo, TopoParameter from mininet_builder import MininetBuilder -from mpMultiInterfaceTopo import MpMultiInterfaceTopo -from mpMultiInterfaceConfig import MpMultiInterfaceConfig -from mpMultiInterfaceCongConfig import MpMultiInterfaceCongConfig -from mpMultiInterfaceCongTopo import MpMultiInterfaceCongTopo -from mpECMPSingleInterfaceConfig import MpECMPSingleInterfaceConfig -from mpTwoInterfaceCongestionConfig import MpTwoInterfaceCongestionConfig +import topos + from mpExperiencePing import ExperiencePing from mpExperienceNCPV import ExperienceNCPV from mpExperienceNC import ExperienceNC @@ -28,8 +24,6 @@ from mpExperienceSiriMsg import ExperienceSiriMsg from mpExperienceQUIC import ExperienceQUIC from mpExperienceQUICSiri import ExperienceQUICSiri from mpExperienceNone import ExperienceNone -from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo -from mpTwoInterfaceCongestionTopo import MpTwoInterfaceCongestionTopo class MpXpRunner: def __init__(self, builderType, topoParamFile, xpParamFile): @@ -53,40 +47,18 @@ class MpXpRunner: builderType) def defTopo(self): t = self.topoParam.getParam(Topo.topoAttr) - if t == Topo.multiIfTopo: - self.Topo = MpMultiInterfaceTopo(self.topoBuilder, - self.topoParam) - elif t == Topo.ECMPLikeTopo: - self.Topo = MpECMPSingleInterfaceTopo( - self.topoBuilder, - self.topoParam) - elif t == Topo.twoIfCongTopo: - self.Topo = MpTwoInterfaceCongestionTopo( - self.topoBuilder, self.topoParam) - elif t == Topo.multiIfCongTopo: - self.Topo = MpMultiInterfaceCongTopo(self.topoBuilder, - self.topoParam) + if t in topos.topos: + self.Topo = topos.topos[t](self.topoBuilder, self.topoParam) else: - raise Exception("Unfound Topo" + t) + raise Exception("Unknown topo: {}".format(t)) print(self.Topo) def defConfig(self): t = self.topoParam.getParam(Topo.topoAttr) - if t == Topo.multiIfTopo: - self.TopoConfig = MpMultiInterfaceConfig(self.Topo, - self.topoParam) - elif t == Topo.ECMPLikeTopo: - self.TopoConfig = MpECMPSingleInterfaceConfig( - self.Topo, - self.topoParam) - elif t == Topo.twoIfCongTopo: - self.TopoConfig = MpTwoInterfaceCongestionConfig( - self.Topo, self.topoParam) - elif t == Topo.multiIfCongTopo: - self.TopoConfig = MpMultiInterfaceCongConfig(self.Topo, - self.topoParam) + if t in topos.configs: + self.TopoConfig = topos.configs[t](self.Topo, self.topoParam) else: - raise Exception("Unfound Topo" + t) + raise Exception("Unknown topo config: {}".format(t)) def startTopo(self): self.Topo.startNetwork() diff --git a/topos/__init__.py b/topos/__init__.py new file mode 100644 index 0000000..353d9f1 --- /dev/null +++ b/topos/__init__.py @@ -0,0 +1,12 @@ +import importlib +import pkgutil +import os + +from core.topo import Topo, TopoConfig + +pkg_dir = os.path.dirname(__file__) +for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]): + importlib.import_module('.' + name, __package__) + +configs = {cls.NAME: cls for cls in TopoConfig.__subclasses__()} +topos = {cls.NAME: cls for cls in Topo.__subclasses__()} \ No newline at end of file diff --git a/mpECMPSingleInterfaceConfig.py b/topos/ecmp_single_interface.py similarity index 77% rename from mpECMPSingleInterfaceConfig.py rename to topos/ecmp_single_interface.py index dbb4860..4e6d3db 100644 --- a/mpECMPSingleInterfaceConfig.py +++ b/topos/ecmp_single_interface.py @@ -1,10 +1,56 @@ from core.topo import Topo, TopoConfig, TopoParameter -from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo from struct import * -class MpECMPSingleInterfaceConfig(TopoConfig): +class ECMPSingleInterfaceTopo(Topo): + NAME = "ECMPLike" + + def __init__(self, topoBuilder, parameterFile): + super(ECMPSingleInterfaceTopo, self).__init__(topoBuilder, parameterFile) + + print("Hello ECMP topo") + + self.client = self.addHost(Topo.clientName) + self.server = self.addHost(Topo.serverName) + self.lswitch = self.addSwitch(Topo.switchNamePrefix + "0") + self.rswitch = self.addSwitch(Topo.switchNamePrefix + "1") + + self.addLink( self.client, self.lswitch) + self.addLink( self.server, self.rswitch) + + self.routers = [] + for l in self.topoParam.linkCharacteristics: + self.routers.append(self.addOneRouterPerLink(l)) + print("added : " + self.routers[-1]) + self.addLink(self.lswitch, self.routers[-1]) + self.addLink(self.rswitch, self.routers[-1], **l.asDict()) + + def addOneRouterPerLink(self, link): + return self.addHost(Topo.routerNamePrefix + + str(link.id)) + + def __str__(self): + s = "Single if ECMP like env\n" + i = 0 + n = len(self.topoParam.linkCharacteristics) + for p in self.topoParam.linkCharacteristics: + if i == n // 2: + if n % 2 == 0: + s = s + "c---sw sw-----s\n" + s = s + " |-----R-----|\n" + else: + s = s + "c---sw----R-----sw-----s\n" + else: + s = s + " |-----R-----|\n" + + i = i + 1 + return s + + +class ECMPSingleInterfaceConfig(TopoConfig): + NAME = "ECMPLike" + def __init__(self, topo, param): - super(MpECMPSingleInterfaceConfig, self).__init__(topo, param) + super(ECMPSingleInterfaceConfig, self).__init__(topo, param) def configureRoute(self): i = 0 diff --git a/mpMultiInterfaceConfig.py b/topos/multi_interface.py similarity index 73% rename from mpMultiInterfaceConfig.py rename to topos/multi_interface.py index e0d04f9..58525da 100644 --- a/mpMultiInterfaceConfig.py +++ b/topos/multi_interface.py @@ -1,9 +1,54 @@ from core.topo import Topo, TopoConfig, TopoParameter -from mpMultiInterfaceTopo import MpMultiInterfaceTopo -class MpMultiInterfaceConfig(TopoConfig): +class MultiInterfaceTopo(Topo): + NAME = "MultiIf" + + def __init__(self, topoBuilder, parameterFile): + super(MultiInterfaceTopo, self).__init__(topoBuilder, parameterFile) + print("Hello from topo multi if") + self.client = self.addHost(Topo.clientName) + self.server = self.addHost(Topo.serverName) + self.router = self.addHost(Topo.routerName) + self.switchClient = [] + self.switchServer = [] + for l in self.topoParam.linkCharacteristics: + self.switchClient.append(self.addSwitch1ForLink(l)) + self.addLink(self.client,self.switchClient[-1]) + self.switchServer.append(self.addSwitch2ForLink(l)) + self.addLink(self.switchClient[-1], self.switchServer[-1], **l.asDict()) + self.addLink(self.switchServer[-1],self.router) + self.addLink(self.router, self.server) + + def addSwitch1ForLink(self, link): + return self.addSwitch(MultiInterfaceTopo.switchNamePrefix + + str(2 * link.id)) + + def addSwitch2ForLink(self, link): + return self.addSwitch(MultiInterfaceTopo.switchNamePrefix + + str(2 * link.id + 1)) + + def __str__(self): + s = "Simple multiple interface topolgy \n" + i = 0 + n = len(self.topoParam.linkCharacteristics) + for p in self.topoParam.linkCharacteristics: + if i == n // 2: + if n % 2 == 0: + s = s + "c r-----s\n" + s = s + "|--sw----sw--|\n" + else: + s = s + "c--sw----sw--r-----s\n" + else: + s = s + "|--sw----sw--|\n" + + i = i + 1 + return s + +class MultiInterfaceConfig(TopoConfig): + NAME = "MultiIf" + def __init__(self, topo, param): - super(MpMultiInterfaceConfig, self).__init__(topo, param) + super(MultiInterfaceConfig, self).__init__(topo, param) def configureRoute(self): i = 0 diff --git a/mpMultiInterfaceCongConfig.py b/topos/multi_interface_cong.py similarity index 78% rename from mpMultiInterfaceCongConfig.py rename to topos/multi_interface_cong.py index 925afd3..756e273 100644 --- a/mpMultiInterfaceCongConfig.py +++ b/topos/multi_interface_cong.py @@ -1,9 +1,65 @@ -from mpMultiInterfaceCongTopo import MpMultiInterfaceCongTopo from core.topo import TopoConfig, Topo, TopoParameter -class MpMultiInterfaceCongConfig(TopoConfig): + +class MultiInterfaceCongTopo(Topo): + NAME = "MultiIfCong" + + congClientName = "CCli" + congServerName = "CSer" + + def __init__(self, topoBuilder, parameterFile): + super(MultiInterfaceCongTopo, self).__init__(topoBuilder, parameterFile) + print("Hello from topo multi if") + self.client = self.addHost(Topo.clientName) + self.server = self.addHost(Topo.serverName) + self.router = self.addHost(Topo.routerName) + self.cong_clients = [] + self.cong_servers = [] + self.switch = [] + for l in self.topoParam.linkCharacteristics: + self.switch.append(self.addOneSwitchPerLink(l)) + self.addLink(self.client,self.switch[-1]) + self.cong_clients.append(self.addHost(MultiInterfaceCongTopo.congClientName + str(len(self.cong_clients)))) + self.addLink(self.cong_clients[-1], self.switch[-1]) + self.addLink(self.switch[-1],self.router, **l.asDict()) + self.addLink(self.router, self.server) + for i in range(len(self.cong_clients)): + self.cong_servers.append(self.addHost(MultiInterfaceCongTopo.congServerName + str(len(self.cong_servers)))) + self.addLink(self.router, self.cong_servers[-1]) + + def getCongClients(self): + return self.cong_clients + + def getCongServers(self): + return self.cong_servers + + def addOneSwitchPerLink(self, link): + return self.addSwitch(MultiInterfaceCongTopo.switchNamePrefix + + str(link.id)) + + def __str__(self): + s = "Simple multiple interface topology with congestion \n" + i = 0 + n = len(self.topoParam.linkCharacteristics) + for p in self.topoParam.linkCharacteristics: + if i == n // 2: + if n % 2 == 0: + s = s + "c r-----s\n" + s = s + "|-----sw-----|\n" + else: + s = s + "c-----sw-----r-----s\n" + else: + s = s + "|-----sw-----|\n" + + i = i + 1 + return s + + +class MultiInterfaceCongConfig(TopoConfig): + NAME = "MultiIfCong" + def __init__(self, topo, param): - super(MpMultiInterfaceCongConfig, self).__init__(topo, param) + super(MultiInterfaceCongConfig, self).__init__(topo, param) def configureRoute(self): i = 0 @@ -192,7 +248,7 @@ class MpMultiInterfaceCongConfig(TopoConfig): return Topo.clientName + "-eth" + str(interfaceID) def getCongClientInterface(self, interfaceID): - return MpMultiInterfaceCongTopo.congClientName + str(interfaceID) + "-eth0" + return MultiInterfaceCongConfig.congClientName + str(interfaceID) + "-eth0" def getRouterInterfaceSwitch(self, interfaceID): return Topo.routerName + "-eth" + str(interfaceID) @@ -201,7 +257,7 @@ class MpMultiInterfaceCongConfig(TopoConfig): return Topo.serverName + "-eth0" def getCongServerInterface(self, interfaceID): - return MpMultiInterfaceCongTopo.congServerName + str(interfaceID) + "-eth0" + return MultiInterfaceCongConfig.congServerName + str(interfaceID) + "-eth0" def getMidLeftName(self, id): return Topo.switchNamePrefix + str(id) diff --git a/mpTwoInterfaceCongestionConfig.py b/topos/two_interface_congestion.py similarity index 76% rename from mpTwoInterfaceCongestionConfig.py rename to topos/two_interface_congestion.py index 3bdc59b..e24e833 100644 --- a/mpTwoInterfaceCongestionConfig.py +++ b/topos/two_interface_congestion.py @@ -1,9 +1,68 @@ from core.topo import Topo, TopoConfig, TopoParameter -from mpTwoInterfaceCongestionTopo import MpTwoInterfaceCongestionTopo -class MpTwoInterfaceCongestionConfig(TopoConfig): + +class TwoInterfaceCongestionTopo(Topo): + NAME = "twoIfCong" + + def __init__(self, topoBuilder, parameterFile): + super(TwoInterfaceCongestionTopo, self).__init__(topoBuilder, parameterFile) + + print("Hello from topo two ifs cong") + print("Expected topo:") + print("c1----link0--------------|") + print("|-------------r1--link1--r2-----s1") + print(" | |------s2") + print("c2----link2----") + + self.client = self.addHost(Topo.clientName) + self.clientCong = self.addHost(Topo.clientName + "Cong") + self.server = self.addHost(Topo.serverName) + self.serverCong = self.addHost(Topo.serverName + "Cong") + self.router = self.addHost(Topo.routerName) + self.routerCong = self.addHost(Topo.routerName + "Cong") + self.switch = [] + + # Link between c1 and r2 + self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[0])) + self.addLink(self.client, self.switch[-1]) + self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[0].asDict()) + + # Link between c1 and r1 + self.addLink(self.client, self.routerCong) + + # Link between c2 and r1 + self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[2])) + self.addLink(self.clientCong, self.switch[-1]) + self.addLink(self.switch[-1], self.routerCong, **self.topoParam.linkCharacteristics[2].asDict()) + + # Link between r1 and r2 + self.switch.append(self.addOneSwitchPerLink(self.topoParam.linkCharacteristics[1])) + self.addLink(self.routerCong, self.switch[-1]) + self.addLink(self.switch[-1], self.router, **self.topoParam.linkCharacteristics[1].asDict()) + + # Link between r2 and s1 + self.addLink(self.router, self.server) + + # Link between r2 and s2 + self.addLink(self.router, self.serverCong) + + def __str__(self): + s = "Hello from topo two ifs cong \n" + s = s + "c1----link0--------------| \n" + s = s + "|-------------r1--link1--r2-----s1 \n" + s = s + " | |------s2 \n" + s = s + "c2----link2---- \n" + return s + + def addOneSwitchPerLink(self, link): + return self.addSwitch(Topo.switchNamePrefix + str(link.id)) + + +class TwoInterfaceCongestionConfig(TopoConfig): + NAME = "twoIfCong" + def __init__(self, topo, param): - super(MpTwoInterfaceCongestionConfig, self).__init__(topo, param) + super(TwoInterfaceCongestionConfig, self).__init__(topo, param) def configureRoute(self): # Client - Router