Signed-off-by: Benjamin Hesmans <benjamin.hesmans@uclouvain.be>
This commit is contained in:
Benjamin Hesmans 2015-01-07 14:44:44 +01:00
parent 0974ce2afc
commit 454ac02886
9 changed files with 219 additions and 18 deletions

View File

@ -1,6 +1,6 @@
desc:Simple configuration with two para link desc:Simple configuration with two para link
leftSubnet:xxx leftSubnet:5.5.
rightSubnet:yyy rightSubnet:6.6.
midSubnet:zzz midSubnet:zzz
#path_x:delay,queueSize(may be calc),bw #path_x:delay,queueSize(may be calc),bw
error error

38
src/mpConfig.py Normal file
View File

@ -0,0 +1,38 @@
class MpConfig:
def __init__(self, topo, param):
self.topo = topo
self.param = param
def interfaceUpCommand(self, interfaceName, ip, subnet):
s = "ifconfig " + interfaceName + " " + ip + " netmask " + \
subnet
print(s)
return s
def addRouteTableCommand(self, fromIP, id):
s = "ip rule add from " + fromIP + " table " + str(id + 1)
print(s)
return s
def addRouteScopeLinkCommand(self, network, interfaceName, id):
s = "ip route add " + network + " dev " + interfaceName + \
" scope link table " + str(id + 1)
print(s)
return s
def addRouteDefaultCommand(self, via, id):
s = "ip route add default via " + via + " table " + str(id + 1)
print(s)
return s
def addRouteDefaultGlobalCommand(self, via, interfaceName):
s = "ip route add default scope global nexthop via " + via + \
" dev " + interfaceName
print(s)
return s
def addRouteDefaultSimple(self, via):
s = "ip route add default via " + via
print(s)
return s

View File

@ -7,6 +7,13 @@ class MpLinkCharacteristics:
self.delay = delay self.delay = delay
self.queueSize = queueSize self.queueSize = queueSize
self.bandwidth = bandwidth self.bandwidth = bandwidth
def asDict(self):
d = {}
d['delay'] = self.delay
d['queueSize'] = self.queueSize
d['bandwidth'] = self.bandwidth
return d
def __str__(self): def __str__(self):
s = "Link id : " + str(self.id) + "\n" s = "Link id : " + str(self.id) + "\n"

View File

@ -1,5 +1,36 @@
from mininet.topo import Topo from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.cli import CLI
class MpMininetBuilder(Topo): class MpMininetBuilder(Topo):
def __init__(self): def __init__(self):
Topo.__init__( self ) Topo.__init__( self )
self.net = None
def commandTo(self, who, cmd):
who.cmd(cmd)
def startNetwork(self):
self.net = Mininet(topo=self,link=TCLink)
self.net.start()
def getCLI(self):
if self.net is None:
print("Can not get the CLI")
else:
CLI(self.net)
def getHost(self, who):
if self.net is None:
print("Network not available....")
raise Exception("Network not ready");
else:
return self.net.getNodeByName(who)
def stopNetwork(self):
if self.net is None:
print("Could not stop network... Nothing to stop)")
else:
self.net.stop()

View File

@ -0,0 +1,99 @@
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 configureNetwork(self):
self.configureInterfaces()
self.configureRoute()
def configureRoute(self):
i = 0
for l in self.topo.switch:
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):
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"
for l in self.topo.switch:
cmd = self.interfaceUpCommand(
self.getClientInterface(i),
self.getClientIP(i), netmask)
self.topo.commandTo(self.client, cmd)
cmd = self.interfaceUpCommand(
self.getRouterInterfaceSwitch(i),
self.getRouterIPSwitch(i), netmask)
self.topo.commandTo(self.router, cmd)
i = i + 1
cmd = self.interfaceUpCommand(self.getRouterInterfaceServer(),
self.getRouterIPServer(), netmask)
self.topo.commandTo(self.router, cmd)
cmd = self.interfaceUpCommand(self.getServerInterface(),
self.getServerIP(), netmask)
self.topo.commandTo(self.server, cmd)
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
def getServerIP(self):
rSubnet = self.param.getParam(MpParamTopo.RSUBNET)
serverIP = rSubnet + "0.1"
return serverIP
def getRouterInterfaceServer(self):
return self.getRouterInterfaceSwitch(len(self.topo.switch))
def getClientInterface(self, interfaceID):
return MpTopo.clientName + "-eth" + str(interfaceID)
def getRouterInterfaceSwitch(self, interfaceID):
return MpTopo.routerName + "-eth" + str(interfaceID)
def getServerInterface(self):
return MpTopo.serverName + "-eth0"

View File

@ -4,13 +4,19 @@ class MpMultiInterfaceTopo(MpTopo):
def __init__(self, topoBuilder, parameterFile): def __init__(self, topoBuilder, parameterFile):
MpTopo.__init__(self,topoBuilder, parameterFile) MpTopo.__init__(self,topoBuilder, parameterFile)
print("Hello from topo multi if") print("Hello from topo multi if")
self.addHost("Client") self.client = self.addHost(MpTopo.clientName)
self.addHost("Server") self.server = self.addHost(MpTopo.serverName)
self.router = self.addHost(MpTopo.routerName)
self.switch = []
for l in self.topoParam.linkCharacteristics: for l in self.topoParam.linkCharacteristics:
self.addOneSwitchPerLink(l) self.switch.append(self.addOneSwitchPerLink(l))
self.addLink(self.client,self.switch[-1])
self.addLink(self.switch[-1],self.router, **l.asDict())
self.addLink(self.router, self.server)
def addOneSwitchPerLink(self, link): def addOneSwitchPerLink(self, link):
self.addSwitch("sw" + str(link.id)) return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix +
str(link.id))
def __str__(self): def __str__(self):
s = "Simple multiple interface topolgy \n" s = "Simple multiple interface topolgy \n"

View File

@ -2,6 +2,12 @@ from mpLinkCharacteristics import MpLinkCharacteristics
class MpParamTopo: class MpParamTopo:
LSUBNET = "leftSubnet"
RSUBNET = "rightSubnet"
defaultValue = {}
defaultValue[LSUBNET] = "10.1."
defaultValue[RSUBNET] = "10.2."
def __init__(self, paramFile): def __init__(self, paramFile):
self.paramDic = {} self.paramDic = {}
self.linkCharacteristics = [] self.linkCharacteristics = []
@ -43,6 +49,8 @@ class MpParamTopo:
def getParam(self, key): def getParam(self, key):
if key in self.paramDic: if key in self.paramDic:
return self.paramDic[key] return self.paramDic[key]
elif key in MpParamTopo.defaultValue:
return MpParamTopo[key]
else: else:
raise Exception("Param not found " + key) raise Exception("Param not found " + key)

View File

@ -3,6 +3,7 @@
import sys, getopt import sys, getopt
from mpParamTopo import MpParamTopo from mpParamTopo import MpParamTopo
from mpMultiInterfaceTopo import MpMultiInterfaceTopo from mpMultiInterfaceTopo import MpMultiInterfaceTopo
from mpMultiInterfaceConfig import MpMultiInterfaceConfig
from mpMininetBuilder import MpMininetBuilder from mpMininetBuilder import MpMininetBuilder
topoParamFile = None topoParamFile = None
@ -38,7 +39,11 @@ if __name__ == '__main__':
if topoType == "mininet": if topoType == "mininet":
if param.getParam('topoType') == "MultiIf": if param.getParam('topoType') == "MultiIf":
mpTopo = MpMultiInterfaceTopo(MpMininetBuilder(), param) mpTopo = MpMultiInterfaceTopo(MpMininetBuilder(), param)
mpConfig = MpMultiInterfaceConfig(mpTopo, param)
mpTopo.startNetwork()
mpConfig.configureNetwork()
mpTopo.getCLI()
mpTopo.stopNetwork()
else: else:
print("Unrecognized topo type") print("Unrecognized topo type")
print(mpTopo) print(mpTopo)

View File

@ -1,28 +1,35 @@
class MpTopo: class MpTopo:
switchNamePrefix = "s"
clientName = "Client"
serverName = "Server"
routerName = "Router"
"""Simple MpTopo""" """Simple MpTopo"""
def __init__(self, topoBuilder, topoParam): def __init__(self, topoBuilder, topoParam):
self.topoBuilder = topoBuilder self.topoBuilder = topoBuilder
self.topoParam = topoParam self.topoParam = topoParam
def commandTo(self, who, cmd): def commandTo(self, who, cmd):
pass self.topoBuilder.commandTo(who, cmd)
def getHost(self, who): def getHost(self, who):
pass return self.topoBuilder.getHost(who)
def addHost(self, host): def addHost(self, host):
print("TODO, add host " + host) return self.topoBuilder.addHost(host)
self.topoBuilder.addHost(host)
pass
def addSwitch(self, switch): def addSwitch(self, switch):
print("TODO, add switchi " + switch) return self.topoBuilder.addSwitch(switch)
self.topoBuilder.addSwitch(switch)
pass
def addLink(self, fromA, toB, **kwargs): def addLink(self, fromA, toB, **kwargs):
#todo check syntax for **kwargs print(kwargs)
self.topoBuilder.addLink(fromA,toB,**kwargs) self.topoBuilder.addLink(fromA,toB,**kwargs)
pass
def getCLI(self):
self.topoBuilder.getCLI()
def startNetwork(self):
self.topoBuilder.startNetwork()
def stopNetwork(self):
self.topoBuilder.stopNetwork()