mininet-sample/topos/multi_interface_cong.py

267 lines
11 KiB
Python
Raw Normal View History

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"
2020-06-29 07:51:55 +00:00
def __init__(self, topo_builder, parameterFile):
2020-06-29 14:02:17 +00:00
raise Exception("Broken")
2020-06-29 07:51:55 +00:00
super(MultiInterfaceCongTopo, self).__init__(topo_builder, parameterFile)
2020-06-24 10:28:44 +00:00
print("Hello from topo multi if")
2020-06-29 07:51:55 +00:00
self.client = self.add_host(Topo.CLIENT_NAME)
self.server = self.add_host(Topo.SERVER_NAME)
self.router = self.add_host(Topo.ROUTER_NAME)
2020-06-24 10:28:44 +00:00
self.cong_clients = []
self.cong_servers = []
self.switch = []
2020-06-29 07:51:55 +00:00
for l in self.topo_parameter.link_characteristics:
2020-06-24 10:28:44 +00:00
self.switch.append(self.addOneSwitchPerLink(l))
2020-06-29 07:51:55 +00:00
self.add_link(self.client,self.switch[-1])
self.cong_clients.append(self.add_host(MultiInterfaceCongTopo.congClientName + str(len(self.cong_clients))))
self.add_link(self.cong_clients[-1], self.switch[-1])
self.add_link(self.switch[-1],self.router, **l.as_dict())
self.add_link(self.router, self.server)
2020-06-24 10:28:44 +00:00
for i in range(len(self.cong_clients)):
2020-06-29 07:51:55 +00:00
self.cong_servers.append(self.add_host(MultiInterfaceCongTopo.congServerName + str(len(self.cong_servers))))
self.add_link(self.router, self.cong_servers[-1])
2020-06-24 10:28:44 +00:00
def getCongClients(self):
return self.cong_clients
def getCongServers(self):
return self.cong_servers
def addOneSwitchPerLink(self, link):
2020-06-29 07:51:55 +00:00
return self.add_switch(MultiInterfaceCongTopo.SWITCH_NAME_PREFIX +
2020-06-24 10:28:44 +00:00
str(link.id))
def __str__(self):
s = "Simple multiple interface topology with congestion \n"
i = 0
2020-06-29 07:51:55 +00:00
n = len(self.topo_parameter.link_characteristics)
for p in self.topo_parameter.link_characteristics:
2020-06-24 10:28:44 +00:00
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
2020-06-29 07:51:55 +00:00
def configure_routing(self):
2020-06-23 11:20:07 +00:00
i = 0
for l in self.topo.switch:
2020-06-29 14:23:39 +00:00
cmd = self.add_table_route_command(self.get_client_ip(i), i)
self.topo.command_to(self.client, cmd)
2020-06-23 11:20:07 +00:00
# Congestion client
2020-06-29 07:51:55 +00:00
cmd = self.add_table_route_command(self.getCongClientIP(i), i)
self.topo.command_to(self.cong_clients[i], cmd)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
cmd = self.add_link_scope_route_command(
2020-06-23 11:20:07 +00:00
self.getClientSubnet(i),
2020-06-26 09:17:00 +00:00
self.get_client_interface(i), i)
self.topo.command_to(self.client, cmd)
2020-06-23 11:20:07 +00:00
# Congestion client
2020-06-29 07:51:55 +00:00
cmd = self.add_link_scope_route_command(
2020-06-23 11:20:07 +00:00
self.getClientSubnet(i),
self.getCongClientInterface(i), i)
self.topo.command_to(self.cong_clients[i], cmd)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
cmd = self.add_table_default_route_command(self.getRouterIPSwitch(i),
2020-06-23 11:20:07 +00:00
i)
self.topo.command_to(self.client, cmd)
2020-06-23 11:20:07 +00:00
# Congestion client
# Keep the same command
self.topo.command_to(self.cong_clients[i], cmd)
2020-06-23 11:20:07 +00:00
# Congestion client
2020-06-29 07:51:55 +00:00
cmd = self.add_global_default_route_command(self.getRouterIPSwitch(i),
2020-06-23 11:20:07 +00:00
self.getCongClientInterface(i))
i = i + 1
2020-06-29 07:51:55 +00:00
cmd = self.add_global_default_route_command(self.getRouterIPSwitch(0),
2020-06-26 09:17:00 +00:00
self.get_client_interface(0))
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:
2020-06-29 07:51:55 +00:00
cmd = self.add_global_default_route_command(self.getRouterIPSwitch(i),
2020-06-23 11:20:07 +00:00
self.getCongClientInterface(i))
self.topo.command_to(c, cmd)
2020-06-23 11:20:07 +00:00
i = i + 1
2020-06-29 07:51:55 +00:00
cmd = self.add_simple_default_route_command(self.getRouterIPServer())
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:
2020-06-29 07:51:55 +00:00
cmd = self.add_simple_default_route_command(self.getRouterIPCongServer(i))
self.topo.command_to(s, cmd)
2020-06-23 11:20:07 +00:00
i += 1
2020-06-29 07:51:55 +00:00
def configure_interfaces(self):
2020-06-23 11:20:07 +00:00
print("Configure interfaces for multi inf")
2020-06-29 07:51:55 +00:00
self.client = self.topo.get_host(Topo.CLIENT_NAME)
self.server = self.topo.get_host(Topo.SERVER_NAME)
self.router = self.topo.get_host(Topo.ROUTER_NAME)
2020-06-23 11:20:07 +00:00
cong_client_names = self.topo.getCongClients()
self.cong_clients = []
for cn in cong_client_names:
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:
self.cong_servers.append(self.topo.get_host(sn))
2020-06-23 11:20:07 +00:00
i = 0
netmask = "255.255.255.0"
2020-06-29 07:51:55 +00:00
links = self.topo.get_link_characteristics()
2020-06-23 11:20:07 +00:00
for l in self.topo.switch:
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(
2020-06-26 09:17:00 +00:00
self.get_client_interface(i),
2020-06-29 14:23:39 +00:00
self.get_client_ip(i), netmask)
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-29 14:23:39 +00:00
self.topo.command_to(self.router, "arp -s " + self.get_client_ip(i) + " " + clientIntfMac)
2020-06-23 11:20:07 +00:00
if(links[i].backup):
2020-06-26 09:17:00 +00:00
cmd = self.interface_backup_command(
self.get_client_interface(i))
self.topo.command_to(self.client, cmd)
2020-06-23 11:20:07 +00:00
# Congestion client
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(
2020-06-23 11:20:07 +00:00
self.getCongClientInterface(i),
self.getCongClientIP(i), netmask)
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()
self.topo.command_to(self.router, "arp -s " + self.getCongClientIP(i) + " " + congClientIntfMac)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(
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)
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()
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
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
2020-06-30 09:23:25 +00:00
cmd = self.interface_up_command(self.get_router_interface_to_server(),
2020-06-23 11:20:07 +00:00
self.getRouterIPServer(), netmask)
self.topo.command_to(self.router, cmd)
2020-06-30 09:23:25 +00:00
routerIntfMac = self.router.intf(self.get_router_interface_to_server()).MAC()
self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(self.get_server_interface(),
2020-06-29 14:23:39 +00:00
self.get_server_ip(), netmask)
self.topo.command_to(self.server, cmd)
2020-06-29 07:51:55 +00:00
serverIntfMac = self.server.intf(self.get_server_interface()).MAC()
2020-06-29 14:23:39 +00:00
self.topo.command_to(self.router, "arp -s " + self.get_server_ip() + " " + serverIntfMac)
2020-06-23 11:20:07 +00:00
# Congestion servers
i = 0
for s in self.cong_servers:
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(self.getRouterInterfaceCongServer(i),
2020-06-23 11:20:07 +00:00
self.getRouterIPCongServer(i), netmask)
self.topo.command_to(self.router, cmd)
2020-06-23 11:20:07 +00:00
routerIntfMac = self.router.intf(self.getRouterInterfaceCongServer(i)).MAC()
self.topo.command_to(s, "arp -s " + self.getRouterIPCongServer(i) + " " + routerIntfMac)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
cmd = self.interface_up_command(self.getCongServerInterface(i),
2020-06-23 11:20:07 +00:00
self.getCongServerIP(i), netmask)
self.topo.command_to(s, cmd)
2020-06-23 11:20:07 +00:00
congServerIntfMac = s.intf(self.getCongServerInterface(i)).MAC()
self.topo.command_to(self.router, "arp -s " + self.getCongServerIP(i) + " " + congServerIntfMac)
2020-06-23 11:20:07 +00:00
i = i + 1
2020-06-29 14:23:39 +00:00
def get_client_ip(self, interfaceID):
2020-06-29 07:51:55 +00:00
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
2020-06-23 11:20:07 +00:00
clientIP = lSubnet + str(interfaceID) + ".1"
return clientIP
def getCongClientIP(self, interfaceID):
2020-06-29 07:51:55 +00:00
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
2020-06-23 11:20:07 +00:00
congClientIP = lSubnet + str(interfaceID) + ".127"
return congClientIP
def getClientSubnet(self, interfaceID):
2020-06-29 07:51:55 +00:00
lSubnet = self.param.get(TopoParameter.LEFT_SUBNET)
2020-06-23 11:20:07 +00:00
clientSubnet = lSubnet + str(interfaceID) + ".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-23 11:20:07 +00:00
routerIP = lSubnet + str(interfaceID) + ".2"
return routerIP
def getRouterIPServer(self):
2020-06-29 07:51:55 +00:00
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
2020-06-23 11:20:07 +00:00
routerIP = rSubnet + "0.2"
return routerIP
def getRouterIPCongServer(self, congID):
2020-06-29 07:51:55 +00:00
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
2020-06-23 11:20:07 +00:00
routerIP = rSubnet + str(1 + congID) + ".2"
return routerIP
2020-06-29 14:23:39 +00:00
def get_server_ip(self):
2020-06-29 07:51:55 +00:00
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
2020-06-23 11:20:07 +00:00
serverIP = rSubnet + "0.1"
return serverIP
def getCongServerIP(self, congID):
2020-06-29 07:51:55 +00:00
rSubnet = self.param.get(TopoParameter.RIGHT_SUBNET)
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)
2020-06-30 09:23:25 +00:00
def get_router_interface_to_server(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-29 07:51:55 +00:00
return Topo.CLIENT_NAME + "-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-29 07:51:55 +00:00
return Topo.ROUTER_NAME + "-eth" + str(interfaceID)
2020-06-23 11:20:07 +00:00
2020-06-29 07:51:55 +00:00
def get_server_interface(self):
return Topo.SERVER_NAME + "-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-29 07:51:55 +00:00
return Topo.SWITCH_NAME_PREFIX + str(id)
2020-06-23 11:20:07 +00:00
def getMidRightName(self, id):
2020-06-29 10:46:07 +00:00
return Topo.ROUTER_NAME