141 lines
5.2 KiB
Python
141 lines
5.2 KiB
Python
from core.topo import Topo, TopoConfig, TopoParameter
|
|
from mpMultiInterfaceTopo import MpMultiInterfaceTopo
|
|
|
|
class MpMultiInterfaceConfig(TopoConfig):
|
|
def __init__(self, topo, param):
|
|
super(MpMultiInterfaceConfig, self).__init__(topo, param)
|
|
|
|
def configureRoute(self):
|
|
i = 0
|
|
for l in self.topo.switchClient:
|
|
cmd = self.addRouteTableCommand(self.getClientIP(i), i)
|
|
self.topo.commandTo(self.client, cmd)
|
|
|
|
cmd = self.addRouteScopeLinkCommand(
|
|
self.getClientSubnet(i),
|
|
self.getClientInterface(i), i)
|
|
self.topo.commandTo(self.client, cmd)
|
|
|
|
cmd = self.addRouteDefaultCommand(self.getRouterIPSwitch(i),
|
|
i)
|
|
self.topo.commandTo(self.client, cmd)
|
|
i = i + 1
|
|
|
|
cmd = self.addRouteDefaultGlobalCommand(self.getRouterIPSwitch(0),
|
|
self.getClientInterface(0))
|
|
self.topo.commandTo(self.client, cmd)
|
|
|
|
cmd = self.addRouteDefaultSimple(self.getRouterIPServer())
|
|
self.topo.commandTo(self.server, cmd)
|
|
|
|
|
|
def configureInterfaces(self):
|
|
print("Configure interfaces for multi inf")
|
|
self.client = self.topo.getHost(Topo.clientName)
|
|
self.server = self.topo.getHost(Topo.serverName)
|
|
self.router = self.topo.getHost(Topo.routerName)
|
|
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)
|
|
self.topo.commandTo(self.client, cmd)
|
|
clientIntfMac = self.client.intf(self.getClientInterface(i)).MAC()
|
|
self.topo.commandTo(self.router, "arp -s " + self.getClientIP(i) + " " + clientIntfMac)
|
|
|
|
if(links[i].back_up):
|
|
cmd = self.interfaceBUPCommand(
|
|
self.getClientInterface(i))
|
|
self.topo.commandTo(self.client, cmd)
|
|
|
|
i = i + 1
|
|
|
|
i = 0
|
|
for l in self.topo.switchServer:
|
|
cmd = self.interfaceUpCommand(
|
|
self.getRouterInterfaceSwitch(i),
|
|
self.getRouterIPSwitch(i), netmask)
|
|
self.topo.commandTo(self.router, cmd)
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceSwitch(i)).MAC()
|
|
self.topo.commandTo(self.client, "arp -s " + self.getRouterIPSwitch(i) + " " + routerIntfMac)
|
|
print(str(links[i]))
|
|
i = i + 1
|
|
|
|
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(),
|
|
self.getRouterIPServer(), netmask)
|
|
self.topo.commandTo(self.router, cmd)
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
|
|
self.topo.commandTo(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
|
|
|
|
cmd = self.interfaceUpCommand(self.getServerInterface(),
|
|
self.getServerIP(), netmask)
|
|
self.topo.commandTo(self.server, cmd)
|
|
serverIntfMac = self.server.intf(self.getServerInterface()).MAC()
|
|
self.topo.commandTo(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
|
|
|
|
def getClientIP(self, interfaceID):
|
|
lSubnet = self.param.getParam(TopoParameter.LSUBNET)
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
return clientIP
|
|
|
|
def getClientSubnet(self, interfaceID):
|
|
lSubnet = self.param.getParam(TopoParameter.LSUBNET)
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
return clientSubnet
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
|
lSubnet = self.param.getParam(TopoParameter.LSUBNET)
|
|
routerIP = lSubnet + str(interfaceID) + ".2"
|
|
return routerIP
|
|
|
|
def getRouterIPServer(self):
|
|
rSubnet = self.param.getParam(TopoParameter.RSUBNET)
|
|
routerIP = rSubnet + "0.2"
|
|
return routerIP
|
|
|
|
def getServerIP(self):
|
|
rSubnet = self.param.getParam(TopoParameter.RSUBNET)
|
|
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):
|
|
return Topo.clientName + "-eth" + str(interfaceID)
|
|
|
|
def getRouterInterfaceSwitch(self, interfaceID):
|
|
return Topo.routerName + "-eth" + str(interfaceID)
|
|
|
|
def getServerInterface(self):
|
|
return Topo.serverName + "-eth0"
|
|
|
|
def getSwitchClientName(self, id):
|
|
return Topo.switchNamePrefix + str(2 * id)
|
|
|
|
def getSwitchServerName(self, id):
|
|
return Topo.switchNamePrefix + str(2 * id + 1)
|
|
|
|
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"
|