2015-01-07 13:44:44 +00:00
|
|
|
from mpConfig import MpConfig
|
|
|
|
from mpMultiInterfaceTopo import MpMultiInterfaceTopo
|
|
|
|
from mpParamTopo import MpParamTopo
|
|
|
|
from mpTopo import MpTopo
|
|
|
|
|
|
|
|
class MpMultiInterfaceConfig(MpConfig):
|
|
|
|
def __init__(self, topo, param):
|
|
|
|
MpConfig.__init__(self, topo, param)
|
|
|
|
|
|
|
|
def configureRoute(self):
|
|
|
|
i = 0
|
2019-11-28 08:32:49 +00:00
|
|
|
for l in self.topo.switchClient:
|
2015-01-07 13:44:44 +00:00
|
|
|
cmd = self.addRouteTableCommand(self.getClientIP(i), i)
|
|
|
|
self.topo.commandTo(self.client, cmd)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
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
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
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)
|
|
|
|
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def configureInterfaces(self):
|
2015-01-20 10:04:36 +00:00
|
|
|
print("Configure interfaces for multi inf")
|
2015-01-07 13:44:44 +00:00
|
|
|
self.client = self.topo.getHost(MpTopo.clientName)
|
|
|
|
self.server = self.topo.getHost(MpTopo.serverName)
|
|
|
|
self.router = self.topo.getHost(MpTopo.routerName)
|
|
|
|
i = 0
|
|
|
|
netmask = "255.255.255.0"
|
2015-05-18 14:54:18 +00:00
|
|
|
links = self.topo.getLinkCharacteristics()
|
2019-11-28 08:32:49 +00:00
|
|
|
for l in self.topo.switchClient:
|
2015-01-07 13:44:44 +00:00
|
|
|
cmd = self.interfaceUpCommand(
|
|
|
|
self.getClientInterface(i),
|
|
|
|
self.getClientIP(i), netmask)
|
|
|
|
self.topo.commandTo(self.client, cmd)
|
2016-05-05 08:21:32 +00:00
|
|
|
clientIntfMac = self.client.intf(self.getClientInterface(i)).MAC()
|
|
|
|
self.topo.commandTo(self.router, "arp -s " + self.getClientIP(i) + " " + clientIntfMac)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-05-18 14:54:18 +00:00
|
|
|
if(links[i].back_up):
|
|
|
|
cmd = self.interfaceBUPCommand(
|
|
|
|
self.getClientInterface(i))
|
|
|
|
self.topo.commandTo(self.client, cmd)
|
|
|
|
|
2019-11-28 08:32:49 +00:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
for l in self.topo.switchServer:
|
2015-01-07 13:44:44 +00:00
|
|
|
cmd = self.interfaceUpCommand(
|
|
|
|
self.getRouterInterfaceSwitch(i),
|
|
|
|
self.getRouterIPSwitch(i), netmask)
|
|
|
|
self.topo.commandTo(self.router, cmd)
|
2016-05-05 08:21:32 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceSwitch(i)).MAC()
|
|
|
|
self.topo.commandTo(self.client, "arp -s " + self.getRouterIPSwitch(i) + " " + routerIntfMac)
|
2015-05-18 14:54:18 +00:00
|
|
|
print(str(links[i]))
|
2015-01-07 13:44:44 +00:00
|
|
|
i = i + 1
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(),
|
|
|
|
self.getRouterIPServer(), netmask)
|
|
|
|
self.topo.commandTo(self.router, cmd)
|
2016-05-05 08:21:32 +00:00
|
|
|
routerIntfMac = self.router.intf(self.getRouterInterfaceServer()).MAC()
|
|
|
|
self.topo.commandTo(self.server, "arp -s " + self.getRouterIPServer() + " " + routerIntfMac)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
cmd = self.interfaceUpCommand(self.getServerInterface(),
|
|
|
|
self.getServerIP(), netmask)
|
|
|
|
self.topo.commandTo(self.server, cmd)
|
2016-05-05 08:21:32 +00:00
|
|
|
serverIntfMac = self.server.intf(self.getServerInterface()).MAC()
|
|
|
|
self.topo.commandTo(self.router, "arp -s " + self.getServerIP() + " " + serverIntfMac)
|
2015-01-07 13:44:44 +00:00
|
|
|
|
|
|
|
def getClientIP(self, interfaceID):
|
|
|
|
lSubnet = self.param.getParam(MpParamTopo.LSUBNET)
|
|
|
|
clientIP = lSubnet + str(interfaceID) + ".1"
|
|
|
|
return clientIP
|
|
|
|
|
|
|
|
def getClientSubnet(self, interfaceID):
|
|
|
|
lSubnet = self.param.getParam(MpParamTopo.LSUBNET)
|
|
|
|
clientSubnet = lSubnet + str(interfaceID) + ".0/24"
|
|
|
|
return clientSubnet
|
|
|
|
|
|
|
|
def getRouterIPSwitch(self, interfaceID):
|
|
|
|
lSubnet = self.param.getParam(MpParamTopo.LSUBNET)
|
|
|
|
routerIP = lSubnet + str(interfaceID) + ".2"
|
|
|
|
return routerIP
|
|
|
|
|
|
|
|
def getRouterIPServer(self):
|
|
|
|
rSubnet = self.param.getParam(MpParamTopo.RSUBNET)
|
|
|
|
routerIP = rSubnet + "0.2"
|
|
|
|
return routerIP
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def getServerIP(self):
|
|
|
|
rSubnet = self.param.getParam(MpParamTopo.RSUBNET)
|
|
|
|
serverIP = rSubnet + "0.1"
|
|
|
|
return serverIP
|
|
|
|
|
2015-01-08 18:52:45 +00:00
|
|
|
def getClientInterfaceCount(self):
|
2019-11-28 08:32:49 +00:00
|
|
|
return len(self.topo.switchClient)
|
2015-01-08 18:52:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def getRouterInterfaceServer(self):
|
2019-11-28 08:32:49 +00:00
|
|
|
return self.getRouterInterfaceSwitch(len(self.topo.switchServer))
|
2015-01-07 13:44:44 +00:00
|
|
|
|
|
|
|
def getClientInterface(self, interfaceID):
|
|
|
|
return MpTopo.clientName + "-eth" + str(interfaceID)
|
|
|
|
|
|
|
|
def getRouterInterfaceSwitch(self, interfaceID):
|
|
|
|
return MpTopo.routerName + "-eth" + str(interfaceID)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def getServerInterface(self):
|
|
|
|
return MpTopo.serverName + "-eth0"
|
2015-01-07 15:00:15 +00:00
|
|
|
|
2019-11-28 08:32:49 +00:00
|
|
|
def getSwitchClientName(self, id):
|
|
|
|
return MpTopo.switchNamePrefix + str(2 * id)
|
|
|
|
|
|
|
|
def getSwitchServerName(self, id):
|
|
|
|
return MpTopo.switchNamePrefix + str(2 * id + 1)
|
|
|
|
|
2015-01-20 10:04:36 +00:00
|
|
|
def getMidLeftName(self, id):
|
2019-11-28 08:32:49 +00:00
|
|
|
return self.getSwitchClientName(id)
|
2015-01-20 10:04:36 +00:00
|
|
|
|
|
|
|
def getMidRightName(self, id):
|
2019-11-28 08:32:49 +00:00
|
|
|
return self.getSwitchServerName(id)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-20 10:04:36 +00:00
|
|
|
def getMidL2RInterface(self, id):
|
2015-01-20 11:23:57 +00:00
|
|
|
return self.getMidLeftName(id) + "-eth2"
|
2015-01-20 10:04:36 +00:00
|
|
|
|
|
|
|
def getMidR2LInterface(self, id):
|
2019-11-28 08:32:49 +00:00
|
|
|
return self.getMidRightName(id) + "-eth1"
|
|
|
|
|
|
|
|
def getMidL2RIncomingInterface(self, id):
|
|
|
|
return self.getMidLeftName(id) + "-eth1"
|
|
|
|
|
|
|
|
def getMidR2LIncomingInterface(self, id):
|
|
|
|
return self.getMidRightName(id) + "-eth2"
|