2020-06-24 08:36:26 +00:00
|
|
|
from core.topo import Topo, TopoConfig, TopoParameter
|
2015-01-07 13:44:44 +00:00
|
|
|
|
2020-06-24 10:28:44 +00:00
|
|
|
class MultiInterfaceTopo(Topo):
|
|
|
|
NAME = "MultiIf"
|
|
|
|
|
|
|
|
def __init__(self, topoBuilder, parameterFile):
|
|
|
|
super(MultiInterfaceTopo, self).__init__(topoBuilder, parameterFile)
|
|
|
|
print("Hello from topo multi if")
|
|
|
|
self.client = self.addHost(Topo.clientName)
|
|
|
|
self.server = self.addHost(Topo.serverName)
|
|
|
|
self.router = self.addHost(Topo.routerName)
|
|
|
|
self.switchClient = []
|
|
|
|
self.switchServer = []
|
|
|
|
for l in self.topoParam.linkCharacteristics:
|
|
|
|
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)
|
|
|
|
self.addLink(self.router, self.server)
|
|
|
|
|
|
|
|
def addSwitch1ForLink(self, link):
|
|
|
|
return self.addSwitch(MultiInterfaceTopo.switchNamePrefix +
|
|
|
|
str(2 * link.id))
|
|
|
|
|
|
|
|
def addSwitch2ForLink(self, link):
|
|
|
|
return self.addSwitch(MultiInterfaceTopo.switchNamePrefix +
|
|
|
|
str(2 * link.id + 1))
|
|
|
|
|
|
|
|
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"
|
|
|
|
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
|
|
|
|
|
|
|
def configureRoute(self):
|
|
|
|
i = 0
|
|
|
|
for l in self.topo.switchClient:
|
|
|
|
cmd = self.addRouteTableCommand(self.getClientIP(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
|
|
|
|
|
|
|
cmd = self.addRouteScopeLinkCommand(
|
|
|
|
self.getClientSubnet(i),
|
|
|
|
self.getClientInterface(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
|
|
|
|
|
|
|
cmd = self.addRouteDefaultCommand(self.getRouterIPSwitch(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
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(0),
|
|
|
|
self.getClientInterface(0))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.addRouteDefaultSimple(self.getRouterIPServer())
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def configureInterfaces(self):
|
|
|
|
print("Configure interfaces for multi inf")
|
2020-06-25 08:53:56 +00:00
|
|
|
self.client = self.topo.get_host(Topo.clientName)
|
|
|
|
self.server = self.topo.get_host(Topo.serverName)
|
|
|
|
self.router = self.topo.get_host(Topo.routerName)
|
2020-06-23 11:20:07 +00:00
|
|
|
i = 0
|
|
|
|
netmask = "255.255.255.0"
|
|
|
|
links = self.topo.getLinkCharacteristics()
|
|
|
|
for l in self.topo.switchClient:
|
|
|
|
cmd = self.interfaceUpCommand(
|
|
|
|
self.getClientInterface(i),
|
|
|
|
self.getClientIP(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
clientIntfMac = self.client.intf(self.getClientInterface(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getClientIP(i) + " " + clientIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
if(links[i].back_up):
|
|
|
|
cmd = self.interfaceBUPCommand(
|
|
|
|
self.getClientInterface(i))
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
for l in self.topo.switchServer:
|
|
|
|
cmd = self.interfaceUpCommand(
|
|
|
|
self.getRouterInterfaceSwitch(i),
|
|
|
|
self.getRouterIPSwitch(i), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceSwitch(i)).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.client, "arp -s " + self.getRouterIPSwitch(i) + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
print(str(links[i]))
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(),
|
|
|
|
self.getRouterIPServer(), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
cmd = self.interfaceUpCommand(self.getServerInterface(),
|
|
|
|
self.getServerIP(), netmask)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.server, cmd)
|
2020-06-23 11:20:07 +00:00
|
|
|
serverIntfMac = self.server.intf(self.getServerInterface()).MAC()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getClientIP(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientSubnet(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
2020-06-25 08:53:56 +00:00
|
|
|
lSubnet = self.param.get(TopoParameter.LSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIP = lSubnet + str(interfaceID) + ".2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getRouterIPServer(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
routerIP = rSubnet + "0.2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getServerIP(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
rSubnet = self.param.get(TopoParameter.RSUBNET)
|
2020-06-23 11:20:07 +00:00
|
|
|
serverIP = rSubnet + "0.1"
|
|
|
|
return serverIP
|
|
|
|
|
|
|
|
def getClientInterfaceCount(self):
|
|
|
|
return len(self.topo.switchClient)
|
|
|
|
|
|
|
|
def getRouterInterfaceServer(self):
|
|
|
|
return self.getRouterInterfaceSwitch(len(self.topo.switchServer))
|
|
|
|
|
|
|
|
def getClientInterface(self, interfaceID):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.clientName + "-eth" + str(interfaceID)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getRouterInterfaceSwitch(self, interfaceID):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.routerName + "-eth" + str(interfaceID)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getServerInterface(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.serverName + "-eth0"
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getSwitchClientName(self, id):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.switchNamePrefix + str(2 * id)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getSwitchServerName(self, id):
|
2020-06-24 08:36:26 +00:00
|
|
|
return Topo.switchNamePrefix + str(2 * id + 1)
|
2020-06-23 11:20:07 +00:00
|
|
|
|
|
|
|
def getMidLeftName(self, id):
|
|
|
|
return self.getSwitchClientName(id)
|
|
|
|
|
|
|
|
def getMidRightName(self, id):
|
|
|
|
return self.getSwitchServerName(id)
|
|
|
|
|
|
|
|
def getMidL2RInterface(self, id):
|
|
|
|
return self.getMidLeftName(id) + "-eth2"
|
|
|
|
|
|
|
|
def getMidR2LInterface(self, id):
|
|
|
|
return self.getMidRightName(id) + "-eth1"
|
|
|
|
|
|
|
|
def getMidL2RIncomingInterface(self, id):
|
|
|
|
return self.getMidLeftName(id) + "-eth1"
|
|
|
|
|
|
|
|
def getMidR2LIncomingInterface(self, id):
|
|
|
|
return self.getMidRightName(id) + "-eth2"
|