mininet-sample/mpMultiInterfaceCongTopo.py

53 lines
2.0 KiB
Python
Raw Normal View History

2020-06-24 08:36:26 +00:00
from core.topo import Topo
2017-06-12 07:34:28 +00:00
2020-06-24 08:36:26 +00:00
class MpMultiInterfaceCongTopo(Topo):
2020-06-23 11:20:07 +00:00
congClientName = "CCli"
congServerName = "CSer"
2017-06-12 07:53:30 +00:00
2020-06-23 11:20:07 +00:00
def __init__(self, topoBuilder, parameterFile):
2020-06-24 08:36:26 +00:00
super().__init__(topoBuilder, parameterFile)
2020-06-23 11:20:07 +00:00
print("Hello from topo multi if")
2020-06-24 08:36:26 +00:00
self.client = self.addHost(Topo.clientName)
self.server = self.addHost(Topo.serverName)
self.router = self.addHost(Topo.routerName)
2020-06-23 11:20:07 +00:00
self.cong_clients = []
self.cong_servers = []
self.switch = []
for l in self.topoParam.linkCharacteristics:
self.switch.append(self.addOneSwitchPerLink(l))
self.addLink(self.client,self.switch[-1])
self.cong_clients.append(self.addHost(MpMultiInterfaceCongTopo.congClientName + str(len(self.cong_clients))))
self.addLink(self.cong_clients[-1], self.switch[-1])
self.addLink(self.switch[-1],self.router, **l.asDict())
self.addLink(self.router, self.server)
for i in range(len(self.cong_clients)):
self.cong_servers.append(self.addHost(MpMultiInterfaceCongTopo.congServerName + str(len(self.cong_servers))))
self.addLink(self.router, self.cong_servers[-1])
2017-06-12 07:34:28 +00:00
2020-06-23 11:20:07 +00:00
def getCongClients(self):
return self.cong_clients
2017-06-12 07:34:28 +00:00
2020-06-23 11:20:07 +00:00
def getCongServers(self):
return self.cong_servers
2017-06-12 07:34:28 +00:00
2020-06-23 11:20:07 +00:00
def addOneSwitchPerLink(self, link):
return self.addSwitch(MpMultiInterfaceCongTopo.switchNamePrefix +
str(link.id))
2017-06-12 07:34:28 +00:00
2020-06-23 11:20:07 +00:00
def __str__(self):
s = "Simple multiple interface topology with congestion \n"
i = 0
n = len(self.topoParam.linkCharacteristics)
for p in self.topoParam.linkCharacteristics:
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"
2017-06-12 07:34:28 +00:00
2020-06-23 11:20:07 +00:00
i = i + 1
return s