2015-01-06 14:47:15 +00:00
|
|
|
from mpTopo import MpTopo
|
|
|
|
|
|
|
|
class MpMultiInterfaceTopo(MpTopo):
|
|
|
|
def __init__(self, topoBuilder, parameterFile):
|
|
|
|
MpTopo.__init__(self,topoBuilder, parameterFile)
|
|
|
|
print("Hello from topo multi if")
|
2015-01-07 13:44:44 +00:00
|
|
|
self.client = self.addHost(MpTopo.clientName)
|
|
|
|
self.server = self.addHost(MpTopo.serverName)
|
|
|
|
self.router = self.addHost(MpTopo.routerName)
|
2019-11-28 08:32:49 +00:00
|
|
|
self.switchClient = []
|
|
|
|
self.switchServer = []
|
2015-01-06 14:47:15 +00:00
|
|
|
for l in self.topoParam.linkCharacteristics:
|
2019-11-28 08:32:49 +00:00
|
|
|
self.switchClient.append(self.addSwitch1ForLink(l))
|
|
|
|
self.addLink(self.client,self.switchClient[-1])
|
|
|
|
self.switchServer.append(self.addSwitch2ForLink(l))
|
|
|
|
self.addLink(self.switchClient[-1], self.switchServer[-1], **l.asDict())
|
|
|
|
self.addLink(self.switchServer[-1],self.router)
|
2015-01-07 13:44:44 +00:00
|
|
|
self.addLink(self.router, self.server)
|
2015-01-06 14:47:15 +00:00
|
|
|
|
2019-11-28 08:32:49 +00:00
|
|
|
def addSwitch1ForLink(self, link):
|
2015-01-07 13:44:44 +00:00
|
|
|
return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix +
|
2019-11-28 08:32:49 +00:00
|
|
|
str(2 * link.id))
|
|
|
|
|
|
|
|
def addSwitch2ForLink(self, link):
|
|
|
|
return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix +
|
|
|
|
str(2 * link.id + 1))
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2015-01-06 14:47:15 +00:00
|
|
|
def __str__(self):
|
|
|
|
s = "Simple multiple interface topolgy \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"
|
2019-11-28 08:32:49 +00:00
|
|
|
s = s + "|--sw----sw--|\n"
|
2015-01-06 14:47:15 +00:00
|
|
|
else:
|
2019-11-28 08:32:49 +00:00
|
|
|
s = s + "c--sw----sw--r-----s\n"
|
2015-01-06 14:47:15 +00:00
|
|
|
else:
|
2019-11-28 08:32:49 +00:00
|
|
|
s = s + "|--sw----sw--|\n"
|
2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
return s
|
|
|
|
|