2020-06-24 08:36:26 +00:00
|
|
|
from core.topo import Topo, TopoConfig, TopoParameter
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def __init__(self, topo, param):
|
2020-06-24 10:28:44 +00:00
|
|
|
super(TwoInterfaceCongestionConfig, self).__init__(topo, param)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
def configureRoute(self):
|
|
|
|
# Client - Router
|
|
|
|
cmd = self.addRouteTableCommand("10.0.0.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteScopeLinkCommand("10.0.0.0/24", Topo.clientName + "-eth0", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteDefaultCommand("10.0.0.2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Client -> Router cong
|
|
|
|
cmd = self.addRouteTableCommand("10.0.1.1", 1)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteScopeLinkCommand("10.0.1.0/24", Topo.clientName + "-eth1", 1)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteDefaultCommand("10.0.1.2", 1)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Client cong -> Router cong
|
|
|
|
cmd = self.addRouteTableCommand("10.0.2.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteScopeLinkCommand("10.0.2.0/24", Topo.clientName + "Cong-eth0", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteDefaultCommand("10.0.2.2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Router cong -> Router
|
|
|
|
cmd = self.addRouteTableCommand("10.0.3.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteScopeLinkCommand("10.1.0.0/16", Topo.routerName + "Cong-eth2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteDefaultCommand("10.0.3.2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Router -> Router cong
|
|
|
|
cmd = self.addRouteTableCommand("10.0.3.2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteScopeLinkCommand("10.0.0.0/16", Topo.routerName + "-eth1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
cmd = self.addRouteDefaultCommand("10.0.3.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Client
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.0.0.2", Topo.clientName + "-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Client cong
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.0.2.2", Topo.clientName + "Cong-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Router cong
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.0.3.2", Topo.routerName + "Cong-eth2")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Router
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.0.3.1", Topo.routerName + "-eth1")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Server
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.1.0.2", Topo.serverName + "-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Default route Server cong
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand("10.1.1.2", Topo.serverName + "Cong-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.serverCong, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
def configureInterface(self, srcHost, dstHost, srcInterfaceName, srcIP, netmask):
|
|
|
|
cmd = self.interfaceUpCommand(srcInterfaceName, srcIP, netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(srcHost, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
mac = srcHost.intf(srcInterfaceName).MAC()
|
|
|
|
cmd = self.arpCommand(srcIP, mac)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(dstHost, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
def configureInterfaces(self):
|
|
|
|
print("Configure interfaces for two inf cong")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.client = self.topo.get_host(Topo.clientName)
|
|
|
|
self.clientCong = self.topo.get_host(Topo.clientName + "Cong")
|
|
|
|
self.server = self.topo.get_host(Topo.serverName)
|
|
|
|
self.serverCong = self.topo.get_host(Topo.serverName + "Cong")
|
|
|
|
self.router = self.topo.get_host(Topo.routerName)
|
|
|
|
self.routerCong = self.topo.get_host(Topo.routerName + "Cong")
|
2020-06-24 08:36:26 +00:00
|
|
|
netmask = "255.255.255.0"
|
|
|
|
links = self.topo.getLinkCharacteristics()
|
|
|
|
|
|
|
|
# Link 0: Client - Router
|
|
|
|
self.configureInterface(self.client, self.router, Topo.clientName + "-eth0", "10.0.0.1", netmask)
|
|
|
|
|
|
|
|
if(links[0].back_up):
|
|
|
|
cmd = self.interfaceBUPCommand(Topo.clientName + "-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
self.configureInterface(self.router, self.client, Topo.routerName + "-eth0", "10.0.0.2", netmask)
|
|
|
|
print(str(links[0]))
|
|
|
|
|
|
|
|
# Client - Router cong
|
|
|
|
self.configureInterface(self.client, self.routerCong, Topo.clientName + "-eth1", "10.0.1.1", netmask)
|
|
|
|
|
|
|
|
if(links[1].back_up):
|
|
|
|
cmd = self.interfaceBUPCommand(Topo.clientName + "-eth1")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
self.configureInterface(self.routerCong, self.client, Topo.routerName + "Cong-eth0", "10.0.1.2", netmask)
|
|
|
|
|
|
|
|
# Link 1: Router - Router cong
|
|
|
|
self.configureInterface(self.routerCong, self.router, Topo.routerName + "Cong-eth2", "10.0.3.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.routerCong, Topo.routerName + "-eth1", "10.0.3.2", netmask)
|
|
|
|
print(str(links[1]))
|
|
|
|
|
|
|
|
# Link 2: Client cong - Router cong
|
|
|
|
self.configureInterface(self.clientCong, self.routerCong, Topo.clientName + "Cong-eth0", "10.0.2.1", netmask)
|
|
|
|
self.configureInterface(self.routerCong, self.clientCong, Topo.routerName + "Cong-eth1", "10.0.2.2", netmask)
|
|
|
|
print(str(links[2]))
|
|
|
|
|
|
|
|
# Router - Server
|
|
|
|
self.configureInterface(self.server, self.router, Topo.serverName + "-eth0", "10.1.0.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.server, Topo.routerName + "-eth2", "10.1.0.2", netmask)
|
|
|
|
|
|
|
|
# Router - Server cong
|
|
|
|
self.configureInterface(self.serverCong, self.router, Topo.serverName + "Cong-eth0", "10.1.1.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.serverCong, Topo.routerName + "-eth3", "10.1.1.2", netmask)
|
|
|
|
|
|
|
|
def getClientIP(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientSubnet(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getClientCongIP(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientIP = lSubnet + str(2) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientCongSubnet(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientSubnet = lSubnet + str(128) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
routerIP = lSubnet + str(interfaceID) + ".2"
|
|
|
|
return routerIP
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getRouterIPServer(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
routerIP = rSubnet + "0.2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getServerIP(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
serverIP = rSubnet + "0.1"
|
|
|
|
return serverIP
|
|
|
|
|
|
|
|
def getClientInterfaceCount(self):
|
|
|
|
return len(self.topo.switch)
|
|
|
|
|
|
|
|
def getRouterInterfaceServer(self):
|
|
|
|
return self.getRouterInterfaceSwitch(len(self.topo.switch))
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getClientInterface(self, interfaceID):
|
|
|
|
return Topo.clientName + "-eth" + str(interfaceID)
|
|
|
|
|
|
|
|
def getRouterInterfaceSwitch(self, interfaceID):
|
|
|
|
return Topo.routerName + "-eth" + str(interfaceID)
|
|
|
|
|
|
|
|
def getServerInterface(self):
|
|
|
|
return Topo.serverName + "-eth0"
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getMidLeftName(self, id):
|
|
|
|
return Topo.switchNamePrefix + str(id)
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getMidRightName(self, id):
|
|
|
|
if id == 2:
|
|
|
|
return Topo.routerName + "Cong"
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.routerName
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getMidL2RInterface(self, id):
|
|
|
|
return self.getMidLeftName(id) + "-eth2"
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getMidR2LInterface(self, id):
|
|
|
|
if id == 2:
|
|
|
|
return self.getMidRightName(id) + "-eth1"
|
|
|
|
|
|
|
|
return self.getMidRightName(id) + "-eth" + str(id)
|