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"
|
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def __init__(self, topo_builder, parameterFile):
|
|
|
|
super(TwoInterfaceCongestionTopo, self).__init__(topo_builder, parameterFile)
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
print("Hello from topo two ifs cong")
|
|
|
|
print("Expected topo:")
|
|
|
|
print("c1----link0--------------|")
|
|
|
|
print("|-------------r1--link1--r2-----s1")
|
|
|
|
print(" | |------s2")
|
|
|
|
print("c2----link2----")
|
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
self.client = self.add_host(Topo.CLIENT_NAME)
|
|
|
|
self.clientCong = self.add_host(Topo.CLIENT_NAME + "Cong")
|
|
|
|
self.server = self.add_host(Topo.SERVER_NAME)
|
|
|
|
self.serverCong = self.add_host(Topo.SERVER_NAME + "Cong")
|
|
|
|
self.router = self.add_host(Topo.ROUTER_NAME)
|
|
|
|
self.routerCong = self.add_host(Topo.ROUTER_NAME + "Cong")
|
2020-06-24 10:28:44 +00:00
|
|
|
self.switch = []
|
|
|
|
|
|
|
|
# Link between c1 and r2
|
2020-06-29 07:51:55 +00:00
|
|
|
self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[0]))
|
|
|
|
self.add_link(self.client, self.switch[-1])
|
|
|
|
self.add_link(self.switch[-1], self.router, **self.topo_parameter.link_characteristics[0].as_dict())
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
# Link between c1 and r1
|
2020-06-29 07:51:55 +00:00
|
|
|
self.add_link(self.client, self.routerCong)
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
# Link between c2 and r1
|
2020-06-29 07:51:55 +00:00
|
|
|
self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[2]))
|
|
|
|
self.add_link(self.clientCong, self.switch[-1])
|
|
|
|
self.add_link(self.switch[-1], self.routerCong, **self.topo_parameter.link_characteristics[2].as_dict())
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
# Link between r1 and r2
|
2020-06-29 07:51:55 +00:00
|
|
|
self.switch.append(self.addOneSwitchPerLink(self.topo_parameter.link_characteristics[1]))
|
|
|
|
self.add_link(self.routerCong, self.switch[-1])
|
|
|
|
self.add_link(self.switch[-1], self.router, **self.topo_parameter.link_characteristics[1].as_dict())
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
# Link between r2 and s1
|
2020-06-29 07:51:55 +00:00
|
|
|
self.add_link(self.router, self.server)
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
# Link between r2 and s2
|
2020-06-29 07:51:55 +00:00
|
|
|
self.add_link(self.router, self.serverCong)
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
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):
|
2020-06-29 07:51:55 +00:00
|
|
|
return self.add_switch(Topo.SWITCH_NAME_PREFIX + str(link.id))
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def configure_routing(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
# Client - Router
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_route_command("10.0.0.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command("10.0.0.0/24", Topo.CLIENT_NAME + "-eth0", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_default_route_command("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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_route_command("10.0.1.1", 1)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command("10.0.1.0/24", Topo.CLIENT_NAME + "-eth1", 1)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_default_route_command("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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_route_command("10.0.2.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command("10.0.2.0/24", Topo.CLIENT_NAME + "Cong-eth0", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.clientCong, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_default_route_command("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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_route_command("10.0.3.1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command("10.1.0.0/16", Topo.ROUTER_NAME + "Cong-eth2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.routerCong, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_default_route_command("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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_route_command("10.0.3.2", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command("10.0.0.0/16", Topo.ROUTER_NAME + "-eth1", 0)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_table_default_route_command("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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.0.0.2", Topo.CLIENT_NAME + "-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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.0.2.2", Topo.CLIENT_NAME + "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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.0.3.2", Topo.ROUTER_NAME + "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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.0.3.1", Topo.ROUTER_NAME + "-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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.1.0.2", Topo.SERVER_NAME + "-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
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_global_default_route_command("10.1.1.2", Topo.SERVER_NAME + "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):
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.interface_up_command(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()
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.arp_command(srcIP, mac)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(dstHost, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def configure_interfaces(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
print("Configure interfaces for two inf cong")
|
2020-06-29 07:51:55 +00:00
|
|
|
self.client = self.topo.get_host(Topo.CLIENT_NAME)
|
|
|
|
self.clientCong = self.topo.get_host(Topo.CLIENT_NAME + "Cong")
|
|
|
|
self.server = self.topo.get_host(Topo.SERVER_NAME)
|
|
|
|
self.serverCong = self.topo.get_host(Topo.SERVER_NAME + "Cong")
|
|
|
|
self.router = self.topo.get_host(Topo.ROUTER_NAME)
|
|
|
|
self.routerCong = self.topo.get_host(Topo.ROUTER_NAME + "Cong")
|
2020-06-24 08:36:26 +00:00
|
|
|
netmask = "255.255.255.0"
|
2020-06-29 07:51:55 +00:00
|
|
|
links = self.topo.get_link_characteristics()
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Link 0: Client - Router
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.client, self.router, Topo.CLIENT_NAME + "-eth0", "10.0.0.1", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-26 10:04:09 +00:00
|
|
|
if(links[0].backup):
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.interface_backup_command(Topo.CLIENT_NAME + "-eth0")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.router, self.client, Topo.ROUTER_NAME + "-eth0", "10.0.0.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
print(str(links[0]))
|
|
|
|
|
|
|
|
# Client - Router cong
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.client, self.routerCong, Topo.CLIENT_NAME + "-eth1", "10.0.1.1", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-26 10:04:09 +00:00
|
|
|
if(links[1].backup):
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.interface_backup_command(Topo.CLIENT_NAME + "-eth1")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.routerCong, self.client, Topo.ROUTER_NAME + "Cong-eth0", "10.0.1.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Link 1: Router - Router cong
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.routerCong, self.router, Topo.ROUTER_NAME + "Cong-eth2", "10.0.3.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.routerCong, Topo.ROUTER_NAME + "-eth1", "10.0.3.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
print(str(links[1]))
|
|
|
|
|
|
|
|
# Link 2: Client cong - Router cong
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.clientCong, self.routerCong, Topo.CLIENT_NAME + "Cong-eth0", "10.0.2.1", netmask)
|
|
|
|
self.configureInterface(self.routerCong, self.clientCong, Topo.ROUTER_NAME + "Cong-eth1", "10.0.2.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
print(str(links[2]))
|
|
|
|
|
|
|
|
# Router - Server
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.server, self.router, Topo.SERVER_NAME + "-eth0", "10.1.0.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.server, Topo.ROUTER_NAME + "-eth2", "10.1.0.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
# Router - Server cong
|
2020-06-29 07:51:55 +00:00
|
|
|
self.configureInterface(self.serverCong, self.router, Topo.SERVER_NAME + "Cong-eth0", "10.1.1.1", netmask)
|
|
|
|
self.configureInterface(self.router, self.serverCong, Topo.ROUTER_NAME + "-eth3", "10.1.1.2", netmask)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
|
|
|
def getClientIP(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientSubnet(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getClientCongIP(self):
|
2020-06-29 07:51:55 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientIP = lSubnet + str(2) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientCongSubnet(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
clientSubnet = lSubnet + str(128) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
|
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-29 07:51:55 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
routerIP = rSubnet + "0.2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getServerIP(self):
|
2020-06-29 07:51:55 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
|
2020-06-24 08:36:26 +00:00
|
|
|
serverIP = rSubnet + "0.1"
|
|
|
|
return serverIP
|
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def client_interface_count(self):
|
2020-06-24 08:36:26 +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))
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def get_client_interface(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
return Topo.CLIENT_NAME + "-eth" + str(interfaceID)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def get_router_interface_to_switch(self, interfaceID):
|
2020-06-29 07:51:55 +00:00
|
|
|
return Topo.ROUTER_NAME + "-eth" + str(interfaceID)
|
2020-06-24 08:36:26 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def get_server_interface(self):
|
|
|
|
return Topo.SERVER_NAME + "-eth0"
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
def getMidLeftName(self, id):
|
2020-06-29 07:51:55 +00:00
|
|
|
return Topo.SWITCH_NAME_PREFIX + 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:
|
2020-06-29 07:51:55 +00:00
|
|
|
return Topo.ROUTER_NAME + "Cong"
|
2016-05-24 15:05:20 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
return Topo.ROUTER_NAME
|