From 588b99865eec7b8f445be53136a9d4815400af09 Mon Sep 17 00:00:00 2001 From: Quentin De Coninck Date: Tue, 24 May 2016 17:05:20 +0200 Subject: [PATCH] minitopo: added twoInterfaceCongestion topology --- src/mpConfig.py | 5 + src/mpTopo.py | 1 + src/mpTwoInterfaceCongestionConfig.py | 197 ++++++++++++++++++++++++++ src/mpTwoInterfaceCongestionTopo.py | 56 ++++++++ src/mpXpRunner.py | 8 ++ 5 files changed, 267 insertions(+) create mode 100644 src/mpTwoInterfaceCongestionConfig.py create mode 100644 src/mpTwoInterfaceCongestionTopo.py diff --git a/src/mpConfig.py b/src/mpConfig.py index cd3135e..8833a70 100644 --- a/src/mpConfig.py +++ b/src/mpConfig.py @@ -64,6 +64,11 @@ class MpConfig: print(s) return s + def arpCommand(self, ip, mac): + s = "arp -s " + ip + " " + mac + print(s) + return s + def addRouteDefaultSimple(self, via): s = "ip route add default via " + via print(s) diff --git a/src/mpTopo.py b/src/mpTopo.py index 5e4b48c..def62ab 100644 --- a/src/mpTopo.py +++ b/src/mpTopo.py @@ -4,6 +4,7 @@ class MpTopo: mininetBuilder = "mininet" multiIfTopo = "MultiIf" ECMPLikeTopo = "ECMPLike" + twoIfCongTopo = "twoIfCong" topoAttr = "topoType" switchNamePrefix = "s" routerNamePrefix = "r" diff --git a/src/mpTwoInterfaceCongestionConfig.py b/src/mpTwoInterfaceCongestionConfig.py new file mode 100644 index 0000000..f83dfdc --- /dev/null +++ b/src/mpTwoInterfaceCongestionConfig.py @@ -0,0 +1,197 @@ +from mpConfig import MpConfig +from mpTwoInterfaceCongestionTopo import MpTwoInterfaceCongestionTopo +from mpParamTopo import MpParamTopo +from mpTopo import MpTopo + + +class MpTwoInterfaceCongestionConfig(MpConfig): + def __init__(self, topo, param): + MpConfig.__init__(self, topo, param) + + def configureRoute(self): + # Client - Router + cmd = self.addRouteTableCommand("10.0.0.1", 0) + self.topo.commandTo(self.client, cmd) + cmd = self.addRouteScopeLinkCommand("10.0.0.0/24", MpTopo.clientName + "-eth0", 0) + self.topo.commandTo(self.client, cmd) + cmd = self.addRouteDefaultCommand("10.0.0.2", 0) + self.topo.commandTo(self.client, cmd) + + # Client -> Router cong + cmd = self.addRouteTableCommand("10.0.1.1", 1) + self.topo.commandTo(self.client, cmd) + cmd = self.addRouteScopeLinkCommand("10.0.1.0/24", MpTopo.clientName + "-eth1", 1) + self.topo.commandTo(self.client, cmd) + cmd = self.addRouteDefaultCommand("10.0.1.2", 1) + self.topo.commandTo(self.client, cmd) + + # Client cong -> Router cong + cmd = self.addRouteTableCommand("10.0.2.1", 0) + self.topo.commandTo(self.clientCong, cmd) + cmd = self.addRouteScopeLinkCommand("10.0.2.0/24", MpTopo.clientName + "Cong-eth0", 0) + self.topo.commandTo(self.clientCong, cmd) + cmd = self.addRouteDefaultCommand("10.0.2.2", 0) + self.topo.commandTo(self.clientCong, cmd) + + # Router cong -> Router + cmd = self.addRouteTableCommand("10.0.3.1", 0) + self.topo.commandTo(self.routerCong, cmd) + cmd = self.addRouteScopeLinkCommand("10.1.0.0/16", MpTopo.routerName + "Cong-eth2", 0) + self.topo.commandTo(self.routerCong, cmd) + cmd = self.addRouteDefaultCommand("10.0.3.2", 0) + self.topo.commandTo(self.routerCong, cmd) + + # Router -> Router cong + cmd = self.addRouteTableCommand("10.0.3.2", 0) + self.topo.commandTo(self.router, cmd) + cmd = self.addRouteScopeLinkCommand("10.0.0.0/16", MpTopo.routerName + "-eth1", 0) + self.topo.commandTo(self.router, cmd) + cmd = self.addRouteDefaultCommand("10.0.3.1", 0) + self.topo.commandTo(self.router, cmd) + + # Default route Client + cmd = self.addRouteDefaultGlobalCommand("10.0.0.2", MpTopo.clientName + "-eth0") + self.topo.commandTo(self.client, cmd) + + # Default route Client cong + cmd = self.addRouteDefaultGlobalCommand("10.0.2.2", MpTopo.clientName + "Cong-eth0") + self.topo.commandTo(self.clientCong, cmd) + + # Default route Router cong + cmd = self.addRouteDefaultGlobalCommand("10.0.3.2", MpTopo.routerName + "Cong-eth2") + self.topo.commandTo(self.routerCong, cmd) + + # Default route Router + cmd = self.addRouteDefaultGlobalCommand("10.0.3.1", MpTopo.routerName + "-eth1") + self.topo.commandTo(self.router, cmd) + + # Default route Server + cmd = self.addRouteDefaultGlobalCommand("10.1.0.2", MpTopo.serverName + "-eth0") + self.topo.commandTo(self.server, cmd) + + # Default route Server cong + cmd = self.addRouteDefaultGlobalCommand("10.1.1.2", MpTopo.serverName + "Cong-eth0") + self.topo.commandTo(self.serverCong, cmd) + + def configureInterface(self, srcHost, dstHost, srcInterfaceName, srcIP, netmask): + cmd = self.interfaceUpCommand(srcInterfaceName, srcIP, netmask) + self.topo.commandTo(srcHost, cmd) + mac = srcHost.intf(srcInterfaceName).MAC() + cmd = self.arpCommand(srcIP, mac) + self.topo.commandTo(dstHost, cmd) + + def configureInterfaces(self): + print("Configure interfaces for two inf cong") + self.client = self.topo.getHost(MpTopo.clientName) + self.clientCong = self.topo.getHost(MpTopo.clientName + "Cong") + self.server = self.topo.getHost(MpTopo.serverName) + self.serverCong = self.topo.getHost(MpTopo.serverName + "Cong") + self.router = self.topo.getHost(MpTopo.routerName) + self.routerCong = self.topo.getHost(MpTopo.routerName + "Cong") + netmask = "255.255.255.0" + links = self.topo.getLinkCharacteristics() + + # Link 0: Client - Router + self.configureInterface(self.client, self.router, MpTopo.clientName + "-eth0", "10.0.0.1", netmask) + + if(links[0].back_up): + cmd = self.interfaceBUPCommand(MpTopo.clientName + "-eth0") + self.topo.commandTo(self.client, cmd) + + self.configureInterface(self.router, self.client, MpTopo.routerName + "-eth0", "10.0.0.2", netmask) + print(str(links[0])) + + # Client - Router cong + self.configureInterface(self.client, self.routerCong, MpTopo.clientName + "-eth1", "10.0.1.1", netmask) + + if(links[1].back_up): + cmd = self.interfaceBUPCommand(MpTopo.clientName + "-eth1") + self.topo.commandTo(self.client, cmd) + + self.configureInterface(self.routerCong, self.client, MpTopo.routerName + "Cong-eth0", "10.0.1.2", netmask) + + # Link 1: Router - Router cong + self.configureInterface(self.routerCong, self.router, MpTopo.routerName + "Cong-eth2", "10.0.3.1", netmask) + self.configureInterface(self.router, self.routerCong, MpTopo.routerName + "-eth1", "10.0.3.2", netmask) + print(str(links[1])) + + # Link 2: Client cong - Router cong + self.configureInterface(self.clientCong, self.routerCong, MpTopo.clientName + "Cong-eth0", "10.0.2.1", netmask) + self.configureInterface(self.routerCong, self.clientCong, MpTopo.routerName + "Cong-eth1", "10.0.2.2", netmask) + print(str(links[2])) + + # Router - Server + self.configureInterface(self.server, self.router, MpTopo.serverName + "-eth0", "10.1.0.1", netmask) + self.configureInterface(self.router, self.server, MpTopo.routerName + "-eth2", "10.1.0.2", netmask) + + # Router - Server cong + self.configureInterface(self.serverCong, self.router, MpTopo.serverName + "Cong-eth0", "10.1.1.1", netmask) + self.configureInterface(self.router, self.serverCong, MpTopo.routerName + "-eth3", "10.1.1.2", netmask) + + def getClientIP(self, interfaceID): + lSubnet = self.param.getParam(MpParamTopo.LSUBNET) + clientIP = lSubnet + str(interfaceID) + ".1" + return clientIP + + def getClientSubnet(self, interfaceID): + lSubnet = self.param.getParam(MpParamTopo.LSUBNET) + clientSubnet = lSubnet + str(interfaceID) + ".0/24" + return clientSubnet + + def getClientCongIP(self): + lSubnet = self.param.getParam(MpParamTopo.LSUBNET) + clientIP = lSubnet + str(2) + ".1" + return clientIP + + def getClientCongSubnet(self, interfaceID): + lSubnet = self.param.getParam(MpParamTopo.LSUBNET) + clientSubnet = lSubnet + str(128) + ".0/24" + return clientSubnet + + def getRouterIPSwitch(self, interfaceID): + lSubnet = self.param.getParam(MpParamTopo.LSUBNET) + routerIP = lSubnet + str(interfaceID) + ".2" + return routerIP + + def getRouterIPServer(self): + rSubnet = self.param.getParam(MpParamTopo.RSUBNET) + routerIP = rSubnet + "0.2" + return routerIP + + def getServerIP(self): + rSubnet = self.param.getParam(MpParamTopo.RSUBNET) + serverIP = rSubnet + "0.1" + return serverIP + + def getClientInterfaceCount(self): + return len(self.topo.switch) + + def getRouterInterfaceServer(self): + return self.getRouterInterfaceSwitch(len(self.topo.switch)) + + def getClientInterface(self, interfaceID): + return MpTopo.clientName + "-eth" + str(interfaceID) + + def getRouterInterfaceSwitch(self, interfaceID): + return MpTopo.routerName + "-eth" + str(interfaceID) + + def getServerInterface(self): + return MpTopo.serverName + "-eth0" + + def getMidLeftName(self, id): + return MpTopo.switchNamePrefix + str(id) + + def getMidRightName(self, id): + if id == 2: + return MpTopo.routerName + "Cong" + + return MpTopo.routerName + + def getMidL2RInterface(self, id): + return self.getMidLeftName(id) + "-eth2" + + def getMidR2LInterface(self, id): + if id == 2: + return self.getMidRightName(id) + "-eth1" + + return self.getMidRightName(id) + "-eth" + str(id) diff --git a/src/mpTwoInterfaceCongestionTopo.py b/src/mpTwoInterfaceCongestionTopo.py new file mode 100644 index 0000000..e67d735 --- /dev/null +++ b/src/mpTwoInterfaceCongestionTopo.py @@ -0,0 +1,56 @@ +from mpTopo import MpTopo + + +class MpTwoInterfaceCongestionTopo(MpTopo): + def __init__(self, topoBuilder, parameterFile): + MpTopo.__init__(self, 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(MpTopo.clientName) + self.clientCong = self.addHost(MpTopo.clientName + "Cong") + self.server = self.addHost(MpTopo.serverName) + self.serverCong = self.addHost(MpTopo.serverName + "Cong") + self.router = self.addHost(MpTopo.routerName) + self.routerCong = self.addHost(MpTopo.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(MpTopo.switchNamePrefix + str(link.id)) diff --git a/src/mpXpRunner.py b/src/mpXpRunner.py index b32813e..26871c4 100644 --- a/src/mpXpRunner.py +++ b/src/mpXpRunner.py @@ -4,6 +4,7 @@ from mpParamXp import MpParamXp from mpMultiInterfaceTopo import MpMultiInterfaceTopo from mpMultiInterfaceConfig import MpMultiInterfaceConfig from mpECMPSingleInterfaceConfig import MpECMPSingleInterfaceConfig +from mpTwoInterfaceCongestionConfig import MpTwoInterfaceCongestionConfig from mpMininetBuilder import MpMininetBuilder from mpExperiencePing import MpExperiencePing from mpExperienceNCPV import MpExperienceNCPV @@ -19,6 +20,7 @@ from mpExperienceVLC import MpExperienceVLC from mpExperienceNone import MpExperienceNone from mpExperience import MpExperience from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo +from mpTwoInterfaceCongestionTopo import MpTwoInterfaceCongestionTopo class MpXpRunner: def __init__(self, builderType, topoParamFile, xpParamFile): @@ -49,6 +51,9 @@ class MpXpRunner: self.mpTopo = MpECMPSingleInterfaceTopo( self.topoBuilder, self.topoParam) + elif t == MpTopo.twoIfCongTopo: + self.mpTopo = MpTwoInterfaceCongestionTopo( + self.topoBuilder, self.topoParam) else: raise Exception("Unfound Topo" + t) print(self.mpTopo) @@ -62,6 +67,9 @@ class MpXpRunner: self.mpTopoConfig = MpECMPSingleInterfaceConfig( self.mpTopo, self.topoParam) + elif t == MpTopo.twoIfCongTopo: + self.mpTopoConfig = MpTwoInterfaceCongestionConfig( + self.mpTopo, self.topoParam) else: raise Exception("Unfound Topo" + t)