rewrite topos to have inheritance

This commit is contained in:
Quentin De Coninck 2020-07-08 14:25:24 +02:00
parent 2331f5218d
commit 8a234d870f
4 changed files with 42 additions and 139 deletions

View File

@ -8,7 +8,7 @@ pkg_dir = os.path.dirname(__file__)
for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]):
importlib.import_module('.' + name, __package__)
# Track direct inheritance
# Track indirect inheritance
EXPERIMENTS = {}
def _get_all_subclasses(BaseClass):

View File

@ -8,5 +8,16 @@ pkg_dir = os.path.dirname(__file__)
for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]):
importlib.import_module('.' + name, __package__)
TOPO_CONFIGS = {cls.NAME: cls for cls in TopoConfig.__subclasses__()}
TOPOS = {cls.NAME: cls for cls in Topo.__subclasses__()}
# Track indirect inheritance
TOPO_CONFIGS = {}
TOPOS = {}
def _get_all_subclasses(BaseClass, dico):
for cls in BaseClass.__subclasses__():
if hasattr(cls, "NAME"):
dico[cls.NAME] = cls
_get_all_subclasses(cls, dico)
_get_all_subclasses(TopoConfig, TOPO_CONFIGS)
_get_all_subclasses(Topo, TOPOS)

View File

@ -11,27 +11,17 @@ class MultiInterfaceTopo(Topo):
self.client = self.add_client()
self.server = self.add_server()
self.router = self.add_router()
self.c2r_client_switches = []
self.c2r_router_switches = []
self.r2s_router_switches = []
self.r2s_server_switches = []
self.c2r_links = []
self.r2s_links = []
# Add client - router links
for l in self.get_client_to_router_links():
self.c2r_client_switches.append(self.add_c2r_client_side_switch(l))
self.add_link(self.client, self.c2r_client_switches[-1])
self.c2r_router_switches.append(self.add_c2r_router_side_switch(l))
self.add_bottleneck_link(self.c2r_client_switches[-1], self.c2r_router_switches[-1], link_characteristics=l)
self.add_link(self.c2r_router_switches[-1], self.router)
self.c2r_links.append(self.add_bottleneck_link(self.client, self.router, link_characteristics=l))
# Special case: if there is no specified link between router and server, directly connect them!
if len(self.get_router_to_server_links()) > 0:
for l in self.get_router_to_server_links():
self.r2s_router_switches.append(self.add_r2s_router_side_switch(l))
self.add_link(self.router, self.r2s_router_switches[-1])
self.r2s_server_switches.append(self.add_r2s_server_side_switch(l))
self.add_bottleneck_link(self.r2s_router_switches[-1], self.r2s_server_switches[-1], link_characteristics=l)
self.add_link(self.r2s_server_switches[-1], self.server)
self.r2s_links.append(self.add_bottleneck_link(self.router, self.server, link_characteristics=l))
else:
self.add_link(self.router, self.server)
@ -42,18 +32,6 @@ class MultiInterfaceTopo(Topo):
def get_router_to_server_links(self):
return [l for l in self.topo_parameter.link_characteristics if l.link_type == "r2s"]
def add_c2r_client_side_switch(self, link):
return self.add_switch("{}c2r{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id))
def add_c2r_router_side_switch(self, link):
return self.add_switch("{}c2r{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id + 1))
def add_r2s_router_side_switch(self, link):
return self.add_switch("{}r2s{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id))
def add_r2s_server_side_switch(self, link):
return self.add_switch("{}r2s{}".format(MultiInterfaceTopo.SWITCH_NAME_PREFIX, 2 * link.id + 1))
def __str__(self):
s = "Simple multiple interface topology \n"
i = 0
@ -98,7 +76,7 @@ class MultiInterfaceConfig(TopoConfig):
super(MultiInterfaceConfig, self).__init__(topo, param)
def configure_routing(self):
for i, l in enumerate(self.topo.c2r_client_switches):
for i, _ in enumerate(self.topo.c2r_links):
cmd = self.add_table_route_command(self.get_client_ip(i), i)
self.topo.command_to(self.client, cmd)
@ -111,7 +89,7 @@ class MultiInterfaceConfig(TopoConfig):
i)
self.topo.command_to(self.client, cmd)
for i, l in enumerate(self.topo.r2s_server_switches):
for i, _ in enumerate(self.topo.r2s_links):
cmd = self.add_table_route_command(self.get_server_ip(i), i)
self.topo.command_to(self.server, cmd)
@ -140,7 +118,7 @@ class MultiInterfaceConfig(TopoConfig):
self.router = self.topo.get_router(0)
netmask = "255.255.255.0"
for i, l in enumerate(self.topo.c2r_client_switches):
for i, _ in enumerate(self.topo.c2r_links):
cmd = self.interface_up_command(self.get_client_interface(0, i), self.get_client_ip(i), netmask)
self.topo.command_to(self.client, cmd)
client_interface_mac = self.client.intf(self.get_client_interface(0, i)).MAC()
@ -150,7 +128,7 @@ class MultiInterfaceConfig(TopoConfig):
cmd = self.interface_backup_command(self.get_client_interface(0, i))
self.topo.command_to(self.client, cmd)
for i, l in enumerate(self.topo.c2r_router_switches):
for i, _ in enumerate(self.topo.c2r_links):
cmd = self.interface_up_command(self.get_router_interface_to_client_switch(i),
self.get_router_ip_to_client_switch(i), netmask)
self.topo.command_to(self.router, cmd)
@ -158,7 +136,7 @@ class MultiInterfaceConfig(TopoConfig):
self.topo.command_to(self.client, "arp -s {} {}".format(
self.get_router_ip_to_client_switch(i), router_interface_mac))
if len(self.topo.r2s_router_switches) == 0:
if len(self.topo.r2s_links) == 0:
# Case no server param is specified
cmd = self.interface_up_command(self.get_router_interface_to_server_switch(0),
self.get_router_ip_to_server_switch(0), netmask)
@ -173,7 +151,7 @@ class MultiInterfaceConfig(TopoConfig):
self.topo.command_to(self.router, "arp -s {} {}".format(
self.get_server_ip(0), server_interface_mac))
for i, l in enumerate(self.topo.r2s_router_switches):
for i, _ in enumerate(self.topo.r2s_links):
cmd = self.interface_up_command(self.get_router_interface_to_server_switch(i),
self.get_router_ip_to_server_switch(i), netmask)
self.topo.command_to(self.router, cmd)
@ -181,7 +159,7 @@ class MultiInterfaceConfig(TopoConfig):
self.topo.command_to(self.server, "arp -s {} {}".format(
self.get_router_ip_to_server_switch(i), router_interface_mac))
for i, l in enumerate(self.topo.r2s_server_switches):
for i, _ in enumerate(self.topo.r2s_links):
cmd = self.interface_up_command(self.get_server_interface(0, i), self.get_server_ip(i), netmask)
self.topo.command_to(self.server, cmd)
server_interface_mac = self.server.intf(self.get_server_interface(0, i)).MAC()
@ -207,13 +185,13 @@ class MultiInterfaceConfig(TopoConfig):
return "{}{}.0/24".format(self.param.get(TopoParameter.RIGHT_SUBNET), interface_index)
def client_interface_count(self):
return max(len(self.topo.c2r_client_switches), 1)
return max(len(self.topo.c2r_links), 1)
def server_interface_count(self):
return max(len(self.topo.r2s_server_switches), 1)
return max(len(self.topo.r2s_links), 1)
def get_router_interface_to_server_switch(self, switch_index):
return self.get_router_interface_to_client_switch(len(self.topo.c2r_router_switches) + switch_index)
return self.get_router_interface_to_client_switch(len(self.topo.c2r_links) + switch_index)
def get_client_interface(self, client_index, interface_index):
return "{}-eth{}".format(self.topo.get_client_name(client_index), interface_index)

View File

@ -1,45 +1,25 @@
from core.topo import Topo, TopoConfig, TopoParameter
from core.topo import TopoParameter
from .multi_interface import MultiInterfaceTopo, MultiInterfaceConfig
import logging
class MultiInterfaceMultiClientTopo(Topo):
class MultiInterfaceMultiClientTopo(MultiInterfaceTopo):
NAME = "MultiIfMultiClient"
def __init__(self, topo_builder, parameterFile):
logging.info("Initializing MultiInterfaceTopo...")
logging.info("Initializing MultiInterfaceMultiClientTopo...")
super(MultiInterfaceMultiClientTopo, self).__init__(topo_builder, parameterFile)
self.router = self.add_router()
self.c2r_client_switches = []
self.c2r_router_switches = []
# First add the base client and server
self.client = self.add_client()
self.server = self.add_server()
# For each client-router, add a client, a bottleneck link, and a server
for l in self.get_client_to_router_links():
for bl in self.c2r_links:
client = self.add_client()
server = self.add_server()
self.c2r_client_switches.append(self.add_c2r_client_side_switch(l))
self.add_link(self.client, self.c2r_client_switches[-1])
self.add_link(client, self.c2r_client_switches[-1])
self.c2r_router_switches.append(self.add_c2r_router_side_switch(l))
self.add_bottleneck_link(self.c2r_client_switches[-1], self.c2r_router_switches[-1], link_characteristics=l)
self.add_link(self.c2r_router_switches[-1], self.router)
self.add_server()
self.add_link(client, bl.get_left())
# And connect the router to all servers
for s in self.servers:
for s in self.servers[1:]:
self.add_link(self.router, s)
def get_client_to_router_links(self):
return [l for l in self.topo_parameter.link_characteristics if l.link_type == "c2r"]
def add_c2r_client_side_switch(self, link):
return self.add_switch("{}c2r{}".format(MultiInterfaceMultiClientTopo.SWITCH_NAME_PREFIX, 2 * link.id))
def add_c2r_router_side_switch(self, link):
return self.add_switch("{}c2r{}".format(MultiInterfaceMultiClientTopo.SWITCH_NAME_PREFIX, 2 * link.id + 1))
def __str__(self):
s = "Multiple interface topology with several clients and servers\n"
i = 0
@ -54,37 +34,22 @@ class MultiInterfaceMultiClientTopo(Topo):
return s
class MultiInterfaceMultiClientConfig(TopoConfig):
class MultiInterfaceMultiClientConfig(MultiInterfaceConfig):
NAME = "MultiIfMultiClient"
def __init__(self, topo, param):
super(MultiInterfaceMultiClientConfig, self).__init__(topo, param)
def configure_routing(self):
for i, l in enumerate(self.topo.c2r_client_switches):
# Routing for the core client
cmd = self.add_table_route_command(self.get_client_ip(i), i)
self.topo.command_to(self.client, cmd)
cmd = self.add_link_scope_route_command(
self.get_client_subnet(i),
self.get_client_interface(0, i), i)
self.topo.command_to(self.client, cmd)
cmd = self.add_table_default_route_command(self.get_router_ip_to_client_switch(i),
i)
self.topo.command_to(self.client, cmd)
super(MultiInterfaceMultiClientConfig, self).configure_routing()
for i, _ in enumerate(self.topo.c2r_links):
# Routing for the congestion client
cmd = self.add_global_default_route_command(self.get_router_ip_to_client_switch(i),
self.get_client_interface(i+1, 0))
self.topo.command_to(self.clients[i+1], cmd)
cmd = self.add_global_default_route_command(self.get_router_ip_to_client_switch(0),
self.get_client_interface(0, 0))
self.topo.command_to(self.client, cmd)
for i, s in enumerate(self.topo.servers):
# Routing for the congestion server
cmd = self.add_simple_default_route_command(self.get_router_ip_to_server_switch(i))
self.topo.command_to(s, cmd)
@ -93,37 +58,16 @@ class MultiInterfaceMultiClientConfig(TopoConfig):
super(MultiInterfaceMultiClientConfig, self).configure_interfaces()
self.clients = [self.topo.get_client(i) for i in range(0, self.topo.client_count())]
self.servers = [self.topo.get_server(i) for i in range(0, self.topo.server_count())]
self.client = self.clients[0]
self.server = self.servers[0]
self.router = self.topo.get_router(0)
netmask = "255.255.255.0"
for i, l in enumerate(self.topo.c2r_client_switches):
# Core client
cmd = self.interface_up_command(self.get_client_interface(0, i), self.get_client_ip(i), netmask)
self.topo.command_to(self.client, cmd)
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))
if self.topo.get_client_to_router_links()[i].backup:
cmd = self.interface_backup_command(self.get_client_interface(0, i))
self.topo.command_to(self.client, cmd)
for i, _ in enumerate(self.topo.c2r_links):
# Congestion client
cmd = self.interface_up_command(self.get_client_interface(i + 1, 0), self.get_client_ip(i, congestion_client=True), netmask)
self.topo.command_to(self.clients[i+1], cmd)
client_interface_mac = self.clients[i+1].intf(self.get_client_interface(i + 1, 0)).MAC()
self.topo.command_to(self.router, "arp -s {} {}".format(self.get_client_ip(i, congestion_client=True), client_interface_mac))
for i, l in enumerate(self.topo.c2r_router_switches):
cmd = self.interface_up_command(self.get_router_interface_to_client_switch(i),
self.get_router_ip_to_client_switch(i), netmask)
self.topo.command_to(self.router, cmd)
router_interface_mac = self.router.intf(self.get_router_interface_to_client_switch(i)).MAC()
# Core client
self.topo.command_to(self.client, "arp -s {} {}".format(
self.get_router_ip_to_client_switch(i), router_interface_mac))
# Congestion client
self.topo.command_to(self.clients[i+1], "arp -s {} {}".format(
self.get_router_ip_to_client_switch(i), router_interface_mac))
@ -144,35 +88,5 @@ class MultiInterfaceMultiClientConfig(TopoConfig):
def get_client_ip(self, interface_index, congestion_client=False):
return "{}{}.{}".format(self.param.get(TopoParameter.LEFT_SUBNET), interface_index, "10" if congestion_client else "1")
def get_client_subnet(self, interface_index):
return "{}{}.0/24".format(self.param.get(TopoParameter.LEFT_SUBNET), interface_index)
def get_router_ip_to_client_switch(self, switch_index):
return "{}{}.2".format(self.param.get(TopoParameter.LEFT_SUBNET), switch_index)
def get_router_ip_to_server_switch(self, switch_index):
return "{}{}.2".format(self.param.get(TopoParameter.RIGHT_SUBNET), switch_index)
def get_server_ip(self, interface_index=0):
return "{}{}.1".format(self.param.get(TopoParameter.RIGHT_SUBNET), interface_index)
def get_server_subnet(self, interface_index):
return "{}{}.0/24".format(self.param.get(TopoParameter.RIGHT_SUBNET), interface_index)
def client_interface_count(self):
return max(len(self.topo.c2r_client_switches), 1)
def server_interface_count(self):
return max(len(self.servers), 1)
def get_router_interface_to_server_switch(self, switch_index):
return self.get_router_interface_to_client_switch(len(self.topo.c2r_router_switches) + switch_index)
def get_client_interface(self, client_index, interface_index):
return "{}-eth{}".format(self.topo.get_client_name(client_index), interface_index)
def get_router_interface_to_client_switch(self, interface_index):
return "{}-eth{}".format(self.topo.get_router_name(0), interface_index)
def get_server_interface(self, server_index, interface_index):
return "{}-eth{}".format(self.topo.get_server_name(server_index), interface_index)
return max(len(self.servers), 1)