mininet-sample/topos/multi_interface_multi_client.py

110 lines
4.7 KiB
Python
Raw Normal View History

2020-07-08 12:25:24 +00:00
from core.topo import TopoParameter
from .multi_interface import MultiInterfaceTopo, MultiInterfaceConfig
import logging
2020-07-08 12:25:24 +00:00
class MultiInterfaceMultiClientTopo(MultiInterfaceTopo):
NAME = "MultiIfMultiClient"
def __init__(self, topo_builder, parameterFile):
2020-07-08 12:25:24 +00:00
logging.info("Initializing MultiInterfaceMultiClientTopo...")
2022-02-16 04:26:18 +00:00
super(MultiInterfaceMultiClientTopo, self).__init__(
topo_builder, parameterFile)
# For each client-router, add a client, a bottleneck link, and a server
2020-07-08 12:25:24 +00:00
for bl in self.c2r_links:
client = self.add_client()
2020-07-08 12:25:24 +00:00
self.add_link(client, bl.get_left())
2022-02-16 04:26:18 +00:00
self.add_server()
# And connect the router to all servers
2020-07-08 12:25:24 +00:00
for s in self.servers[1:]:
self.add_link(self.router, s)
def __str__(self):
s = "Multiple interface topology with several clients and servers\n"
i = 0
nc = len(self.get_client_to_router_links())
2022-02-16 04:26:18 +00:00
for i in range(0, nc):
if i == nc // 2:
2022-02-16 04:26:18 +00:00
s = s + " r--s\n"
s = s + "c-\sw---bl---sw-/ \-s\n"
2022-02-16 04:26:18 +00:00
elif i < nc // 2:
s = s + "c-/sw---bl---sw-\ /-s\n"
2022-02-16 04:26:18 +00:00
else:
s = s + "c-\sw---bl---sw-/ \-s\n"
return s
2020-07-08 12:25:24 +00:00
class MultiInterfaceMultiClientConfig(MultiInterfaceConfig):
NAME = "MultiIfMultiClient"
def __init__(self, topo, param):
super(MultiInterfaceMultiClientConfig, self).__init__(topo, param)
def configure_routing(self):
2020-07-08 12:25:24 +00:00
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),
2022-02-16 04:26:18 +00:00
self.get_client_interface(i+1, 0))
self.topo.command_to(self.clients[i+1], cmd)
for i, s in enumerate(self.topo.servers):
2020-07-08 12:25:24 +00:00
# Routing for the congestion server
2022-02-16 04:26:18 +00:00
cmd = self.add_simple_default_route_command(
self.get_router_ip_to_server_switch(i))
self.topo.command_to(s, cmd)
def configure_interfaces(self):
2022-02-16 04:26:18 +00:00
logging.info(
"Configure interfaces using MultiInterfaceMultiClientConfig...")
super(MultiInterfaceMultiClientConfig, self).configure_interfaces()
2022-02-16 04:26:18 +00:00
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())]
netmask = "255.255.255.0"
2020-07-08 12:25:24 +00:00
for i, _ in enumerate(self.topo.c2r_links):
# Congestion client
2022-02-16 04:26:18 +00:00
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)
2022-02-16 04:26:18 +00:00
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))
2022-02-16 04:26:18 +00:00
router_interface_mac = self.router.intf(
self.get_router_interface_to_client_switch(i)).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))
for i, s in enumerate(self.servers):
cmd = self.interface_up_command(self.get_router_interface_to_server_switch(i),
2022-02-16 04:26:18 +00:00
self.get_router_ip_to_server_switch(i), netmask)
self.topo.command_to(self.router, cmd)
2022-02-16 04:26:18 +00:00
router_interface_mac = self.router.intf(
self.get_router_interface_to_server_switch(i)).MAC()
self.topo.command_to(s, "arp -s {} {}".format(
self.get_router_ip_to_server_switch(i), router_interface_mac))
2022-02-16 04:26:18 +00:00
cmd = self.interface_up_command(self.get_server_interface(
i, 0), self.get_server_ip(interface_index=i), netmask)
self.topo.command_to(s, cmd)
2022-02-16 04:26:18 +00:00
server_interface_mac = s.intf(
self.get_server_interface(i, 0)).MAC()
self.topo.command_to(self.router, "arp -s {} {}".format(
self.get_server_ip(interface_index=i), server_interface_mac))
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")
2022-02-16 04:26:18 +00:00
def server_interface_count(self):
return max(len(self.servers), 1)