2020-06-24 08:36:26 +00:00
|
|
|
from core.topo import TopoConfig, Topo, TopoParameter
|
2017-06-12 07:34:28 +00:00
|
|
|
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
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])
|
2020-06-26 10:04:09 +00:00
|
|
|
self.addLink(self.switch[-1],self.router, **l.as_dict())
|
2020-06-24 10:28:44 +00:00
|
|
|
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"
|
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def __init__(self, topo, param):
|
2020-06-24 10:28:44 +00:00
|
|
|
super(MultiInterfaceCongConfig, self).__init__(topo, param)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def configureRoute(self):
|
|
|
|
i = 0
|
|
|
|
for l in self.topo.switch:
|
|
|
|
cmd = self.addRouteTableCommand(self.getClientIP(i), i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion client
|
|
|
|
cmd = self.addRouteTableCommand(self.getCongClientIP(i), i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.cong_clients[i], cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.addRouteScopeLinkCommand(
|
|
|
|
self.getClientSubnet(i),
|
2020-06-26 09:17:00 +00:00
|
|
|
self.get_client_interface(i), i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion client
|
|
|
|
cmd = self.addRouteScopeLinkCommand(
|
|
|
|
self.getClientSubnet(i),
|
|
|
|
self.getCongClientInterface(i), i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.cong_clients[i], cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.addRouteDefaultCommand(self.getRouterIPSwitch(i),
|
|
|
|
i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion client
|
|
|
|
# Keep the same command
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.cong_clients[i], cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion client
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(i),
|
|
|
|
self.getCongClientInterface(i))
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(0),
|
2020-06-26 09:17:00 +00:00
|
|
|
self.get_client_interface(0))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion Client
|
|
|
|
i = 0
|
|
|
|
for c in self.cong_clients:
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(i),
|
|
|
|
self.getCongClientInterface(i))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(c, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
cmd = self.addRouteDefaultSimple(self.getRouterIPServer())
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
# Congestion servers
|
|
|
|
i = 0
|
|
|
|
for s in self.cong_servers:
|
|
|
|
cmd = self.addRouteDefaultSimple(self.getRouterIPCongServer(i))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(s, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
i += 1
|
|
|
|
|
|
|
|
|
|
|
|
def configureInterfaces(self):
|
|
|
|
print("Configure interfaces for multi inf")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.client = self.topo.get_host(Topo.clientName)
|
|
|
|
self.server = self.topo.get_host(Topo.serverName)
|
|
|
|
self.router = self.topo.get_host(Topo.routerName)
|
2020-06-23 11:20:07 +00:00
|
|
|
cong_client_names = self.topo.getCongClients()
|
|
|
|
self.cong_clients = []
|
|
|
|
for cn in cong_client_names:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.cong_clients.append(self.topo.get_host(cn))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cong_server_names = self.topo.getCongServers()
|
|
|
|
self.cong_servers = []
|
|
|
|
for sn in cong_server_names:
|
2020-06-25 08:53:56 +00:00
|
|
|
self.cong_servers.append(self.topo.get_host(sn))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
i = 0
|
|
|
|
netmask = "255.255.255.0"
|
|
|
|
links = self.topo.getLinkCharacteristics()
|
|
|
|
for l in self.topo.switch:
|
|
|
|
cmd = self.interfaceUpCommand(
|
2020-06-26 09:17:00 +00:00
|
|
|
self.get_client_interface(i),
|
2020-06-23 11:20:07 +00:00
|
|
|
self.getClientIP(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-26 09:17:00 +00:00
|
|
|
clientIntfMac = self.client.intf(self.get_client_interface(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getClientIP(i) + " " + clientIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-26 10:04:09 +00:00
|
|
|
if(links[i].backup):
|
2020-06-26 09:17:00 +00:00
|
|
|
cmd = self.interface_backup_command(
|
|
|
|
self.get_client_interface(i))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion client
|
|
|
|
cmd = self.interfaceUpCommand(
|
|
|
|
self.getCongClientInterface(i),
|
|
|
|
self.getCongClientIP(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.cong_clients[i], cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
congClientIntfMac = self.cong_clients[i].intf(self.getCongClientInterface(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getCongClientIP(i) + " " + congClientIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(
|
2020-06-26 09:17:00 +00:00
|
|
|
self.get_router_interface_to_switch(i),
|
2020-06-23 11:20:07 +00:00
|
|
|
self.getRouterIPSwitch(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-26 09:17:00 +00:00
|
|
|
routerIntfMac = self.router.intf(self.get_router_interface_to_switch(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, "arp -s " + self.getRouterIPSwitch(i) + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
# Don't forget the congestion client
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.cong_clients[i], "arp -s " + self.getRouterIPSwitch(i) + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
print(str(links[i]))
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(),
|
|
|
|
self.getRouterIPServer(), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(self.getServerInterface(),
|
|
|
|
self.getServerIP(), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
serverIntfMac = self.server.intf(self.getServerInterface()).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
# Congestion servers
|
|
|
|
i = 0
|
|
|
|
for s in self.cong_servers:
|
|
|
|
cmd = self.interfaceUpCommand(self.getRouterInterfaceCongServer(i),
|
|
|
|
self.getRouterIPCongServer(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceCongServer(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(s, "arp -s " + self.getRouterIPCongServer(i) + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(self.getCongServerInterface(i),
|
|
|
|
self.getCongServerIP(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(s, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
congServerIntfMac = s.intf(self.getCongServerInterface(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getCongServerIP(i) + " " + congServerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
def getClientIP(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getCongClientIP(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
congClientIP = lSubnet + str(interfaceID) + ".127"
|
|
|
|
return congClientIP
|
|
|
|
|
|
|
|
def getClientSubnet(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIP = lSubnet + str(interfaceID) + ".2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getRouterIPServer(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIP = rSubnet + "0.2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getRouterIPCongServer(self, congID):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIP = rSubnet + str(1 + congID) + ".2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getServerIP(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
serverIP = rSubnet + "0.1"
|
|
|
|
return serverIP
|
|
|
|
|
|
|
|
def getCongServerIP(self, congID):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
serverIP = rSubnet + str(1 + congID) + ".1"
|
|
|
|
return serverIP
|
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def client_interface_count(self):
|
2020-06-23 11:20:07 +00:00
|
|
|
return len(self.topo.switch)
|
|
|
|
|
|
|
|
def getRouterInterfaceServer(self):
|
2020-06-26 09:17:00 +00:00
|
|
|
return self.get_router_interface_to_switch(len(self.topo.switch))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getRouterInterfaceCongServer(self, congID):
|
2020-06-26 09:17:00 +00:00
|
|
|
return self.get_router_interface_to_switch(len(self.topo.switch) + 1 + congID)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def get_client_interface(self, interfaceID):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.clientName + "-eth" + str(interfaceID)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getCongClientInterface(self, interfaceID):
|
2020-06-24 10:28:44 +00:00
|
|
|
return MultiInterfaceCongConfig.congClientName + str(interfaceID) + "-eth0"
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def get_router_interface_to_switch(self, interfaceID):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.routerName + "-eth" + str(interfaceID)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getServerInterface(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.serverName + "-eth0"
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getCongServerInterface(self, interfaceID):
|
2020-06-24 10:28:44 +00:00
|
|
|
return MultiInterfaceCongConfig.congServerName + str(interfaceID) + "-eth0"
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getMidLeftName(self, id):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.switchNamePrefix + str(id)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getMidRightName(self, id):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.routerName
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getMidL2RInterface(self, id):
|
|
|
|
return self.getMidLeftName(id) + "-eth2"
|
|
|
|
|
|
|
|
def getMidR2LInterface(self, id):
|
|
|
|
return self.getMidRightName(id) + "-eth" + str(id)
|