2020-06-24 08:36:26 +00:00
|
|
|
from core.topo import Topo, TopoConfig, TopoParameter
|
2020-06-29 14:23:39 +00:00
|
|
|
import logging
|
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
|
2020-06-24 10:28:44 +00:00
|
|
|
class MultiInterfaceTopo(Topo):
|
|
|
|
NAME = "MultiIf"
|
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def __init__(self, topo_builder, parameterFile):
|
2020-06-29 14:23:39 +00:00
|
|
|
logging.info("Initializing MultiInterfaceTopo...")
|
2020-06-29 07:51:55 +00:00
|
|
|
super(MultiInterfaceTopo, self).__init__(topo_builder, parameterFile)
|
2020-06-29 14:02:17 +00:00
|
|
|
self.client = self.add_client()
|
|
|
|
self.server = self.add_server()
|
|
|
|
self.router = self.add_router()
|
2020-06-29 14:23:39 +00:00
|
|
|
self.client_switches = []
|
|
|
|
self.server_switches = []
|
2020-06-29 07:51:55 +00:00
|
|
|
for l in self.topo_parameter.link_characteristics:
|
2020-06-29 14:23:39 +00:00
|
|
|
self.client_switches.append(self.add_client_side_switch(l))
|
|
|
|
self.add_link(self.client,self.client_switches[-1])
|
|
|
|
self.server_switches.append(self.add_router_side_switch(l))
|
|
|
|
self.add_bottleneck_link(self.client_switches[-1], self.server_switches[-1], link_characteristics=l)
|
|
|
|
self.add_link(self.server_switches[-1],self.router)
|
2020-07-02 14:33:42 +00:00
|
|
|
|
|
|
|
for i in range(int(self.topo_parameter.get(TopoParameter.SERVER_PATHS))):
|
|
|
|
self.add_link(self.router, self.server)
|
2020-06-29 07:51:55 +00:00
|
|
|
|
2020-06-29 14:23:39 +00:00
|
|
|
def add_client_side_switch(self, link):
|
|
|
|
return self.add_switch("{}{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id))
|
2020-06-24 10:28:44 +00:00
|
|
|
|
2020-06-29 14:23:39 +00:00
|
|
|
def add_router_side_switch(self, link):
|
|
|
|
return self.add_switch("{}{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id + 1))
|
2020-06-24 10:28:44 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
s = "Simple multiple interface topolgy \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----sw--|\n"
|
|
|
|
else:
|
|
|
|
s = s + "c--sw----sw--r-----s\n"
|
|
|
|
else:
|
|
|
|
s = s + "|--sw----sw--|\n"
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
return s
|
|
|
|
|
|
|
|
class MultiInterfaceConfig(TopoConfig):
|
|
|
|
NAME = "MultiIf"
|
|
|
|
|
2020-06-23 11:20:07 +00:00
|
|
|
def __init__(self, topo, param):
|
2020-06-24 10:28:44 +00:00
|
|
|
super(MultiInterfaceConfig, 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-30 09:23:25 +00:00
|
|
|
for i, l in enumerate(self.topo.client_switches):
|
2020-06-29 14:23:39 +00:00
|
|
|
cmd = self.add_table_route_command(self.get_client_ip(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
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.add_link_scope_route_command(
|
2020-06-29 14:23:39 +00:00
|
|
|
self.get_client_subnet(i),
|
2020-06-29 14:02:17 +00:00
|
|
|
self.get_client_interface(0, 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
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
cmd = self.add_table_default_route_command(self.get_router_ip_to_client_switch(i),
|
2020-06-23 11:20:07 +00:00
|
|
|
i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:36:49 +00:00
|
|
|
for i in range(int(self.topo.topo_parameter.get(TopoParameter.SERVER_PATHS))):
|
2020-07-02 14:33:42 +00:00
|
|
|
cmd = self.add_table_route_command(self.get_server_ip(i), i)
|
|
|
|
self.topo.command_to(self.server, cmd)
|
|
|
|
|
|
|
|
cmd = self.add_link_scope_route_command(
|
|
|
|
self.get_server_subnet(i),
|
|
|
|
self.get_server_interface(0, i), i)
|
|
|
|
self.topo.command_to(self.server, cmd)
|
|
|
|
|
|
|
|
cmd = self.add_table_default_route_command(self.get_router_ip_to_server_switch(i),
|
|
|
|
i)
|
|
|
|
self.topo.command_to(self.server, cmd)
|
|
|
|
|
|
|
|
cmd = self.add_global_default_route_command(self.get_router_ip_to_client_switch(0),
|
2020-06-29 14:02:17 +00:00
|
|
|
self.get_client_interface(0, 0))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
cmd = self.add_simple_default_route_command(self.get_router_ip_to_server_switch(0))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def configure_interfaces(self):
|
2020-06-29 14:23:39 +00:00
|
|
|
logging.info("Configure interfaces using MultiInterfaceConfig...")
|
2020-06-29 14:02:17 +00:00
|
|
|
super(MultiInterfaceConfig, self).configure_interfaces()
|
|
|
|
self.client = self.topo.get_client(0)
|
|
|
|
self.server = self.topo.get_server(0)
|
|
|
|
self.router = self.topo.get_router(0)
|
2020-06-23 11:20:07 +00:00
|
|
|
netmask = "255.255.255.0"
|
2020-06-29 14:02:17 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
links = self.topo.get_link_characteristics()
|
2020-06-30 09:23:25 +00:00
|
|
|
for i, l in enumerate(self.topo.client_switches):
|
|
|
|
cmd = self.interface_up_command(self.get_client_interface(0, i), self.get_client_ip(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-30 09:23:25 +00:00
|
|
|
client_interface_mac = self.client.intf(self.get_client_interface(0, i)).MAC()
|
|
|
|
self.topo.command_to(self.router, "arp -s {} {}".format(self.get_client_ip(i), client_interface_mac))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-26 10:04:09 +00:00
|
|
|
if(links[i].backup):
|
2020-06-30 09:23:25 +00:00
|
|
|
cmd = self.interface_backup_command(self.get_client_interface(0, i))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-30 09:23:25 +00:00
|
|
|
for i, l in enumerate(self.topo.server_switches):
|
|
|
|
cmd = self.interface_up_command(self.get_router_interface_to_switch(i),
|
2020-07-02 14:33:42 +00:00
|
|
|
self.get_router_ip_to_client_switch(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-30 09:23:25 +00:00
|
|
|
router_interface_mac = self.router.intf(self.get_router_interface_to_switch(i)).MAC()
|
|
|
|
self.topo.command_to(self.client, "arp -s {} {}".format(
|
2020-07-02 14:33:42 +00:00
|
|
|
self.get_router_ip_to_client_switch(i), router_interface_mac))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:36:49 +00:00
|
|
|
for i in range(int(self.topo.topo_parameter.get(TopoParameter.SERVER_PATHS))):
|
2020-07-02 14:33:42 +00:00
|
|
|
cmd = self.interface_up_command(self.get_router_interface_to_server(i),
|
|
|
|
self.get_router_ip_to_server_switch(i), netmask)
|
|
|
|
self.topo.command_to(self.router, cmd)
|
|
|
|
router_interface_mac = self.router.intf(self.get_router_interface_to_server(i)).MAC()
|
|
|
|
self.topo.command_to(self.server, "arp -s {} {}".format(
|
|
|
|
self.get_router_ip_to_server_switch(i), router_interface_mac))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:36:49 +00:00
|
|
|
for i in range(int(self.topo.topo_parameter.get(TopoParameter.SERVER_PATHS))):
|
2020-07-02 14:38:45 +00:00
|
|
|
cmd = self.interface_up_command(self.get_server_interface(0, i), self.get_server_ip(i), netmask)
|
2020-07-02 14:33:42 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-07-02 14:38:45 +00:00
|
|
|
server_interface_mac = self.server.intf(self.get_server_interface(0, i)).MAC()
|
2020-07-02 14:33:42 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s {} {}".format(
|
|
|
|
self.get_server_ip(i), server_interface_mac))
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-29 14:23:39 +00:00
|
|
|
def get_client_ip(self, interface_index):
|
|
|
|
return "{}{}.1".format(self.param.get(TopoParameter.LEFT_SUBNET), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-29 14:23:39 +00:00
|
|
|
def get_client_subnet(self, interface_index):
|
|
|
|
return "{}{}.0/24".format(self.param.get(TopoParameter.LEFT_SUBNET), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
def get_router_ip_to_client_switch(self, switch_index):
|
2020-06-29 14:23:39 +00:00
|
|
|
return "{}{}.2".format(self.param.get(TopoParameter.LEFT_SUBNET), switch_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
def get_router_ip_to_server_switch(self, switch_index):
|
2020-07-02 14:38:45 +00:00
|
|
|
return "{}{}.2".format(self.param.get(TopoParameter.RIGHT_SUBNET), switch_index)
|
2020-07-02 14:33:42 +00:00
|
|
|
|
2020-07-02 14:41:08 +00:00
|
|
|
def get_server_ip(self, interface_index=0):
|
2020-07-02 14:38:45 +00:00
|
|
|
return "{}{}.1".format(self.param.get(TopoParameter.RIGHT_SUBNET), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
def get_server_subnet(self, interface_index):
|
|
|
|
return "{}{}.0/24".format(self.param.get(TopoParameter.RIGHT_SUBNET), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-26 09:17:00 +00:00
|
|
|
def client_interface_count(self):
|
2020-06-29 14:23:39 +00:00
|
|
|
return len(self.topo.client_switches)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:33:42 +00:00
|
|
|
def get_router_interface_to_server(self, switch_index):
|
|
|
|
return self.get_router_interface_to_switch(len(self.topo.server_switches) + switch_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-29 14:02:17 +00:00
|
|
|
def get_client_interface(self, client_index, interface_index):
|
|
|
|
return "{}-eth{}".format(self.topo.get_client_name(client_index), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-06-29 14:02:17 +00:00
|
|
|
def get_router_interface_to_switch(self, interface_index):
|
|
|
|
return "{}-eth{}".format(self.topo.get_router_name(0), interface_index)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
2020-07-02 14:38:45 +00:00
|
|
|
def get_server_interface(self, server_index, interface_index):
|
|
|
|
return "{}-eth{}".format(self.topo.get_server_name(server_index), interface_index)
|