Can someone show me a python script that creates a simple custom topology in Mininet, that uses a tree topology with a depth and fanout of 2? It would be greatly appreciated.
Asked
Active
Viewed 1,237 times
0
-
Could you post what you've done so far? People at SO will likely help you if you show some effort. – Mateusz Piotrowski Jun 09 '15 at 20:52
2 Answers
0
Example:
from mininet.topo import Topo
class CustomTopo(Topo):
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
Topo.__init__(self, **opts)
self.fanout = fanout
self.linkopts1 = linkopts1
self.linkopts2 = linkopts2
self.linkopts3 = linkopts3
self.coreNumbering = 1
self.aggNumbering = 1
self.edgNumbering = 1
self.hosNumbering = 1
depth = 3
self.createTreeTopo(depth, fanout)
def createTreeTopo(self, depth, fanout):
thisCore = depth == 3
thisAggregation = depth == 2
thisEdge = depth == 1
if depth > 0:
linkopts = dict()
if thisCore:
node = self.addSwitch('c%s' % self.coreNumbering)
self.coreNumbering += 1
linkopts = self.linkopts1
if thisAggregation:
node = self.addSwitch('a%s' % self.aggNumbering)
self.aggNumbering += 1
linkopts = self.linkopts2
if thisEdge:
node = self.addSwitch('e%s' % self.edgNumbering)
self.edgNumbering += 1
linkopts = self.linkopts3
for _ in range(fanout):
child = self.createTreeTopo(depth - 1, fanout)
self.addLink(node, child, **linkopts)
else:
node = self.addHost('h%s' % self.hosNumbering)
self.hosNumbering += 1
return node
topos = { 'custom': ( lambda: CustomTopo() ) }

ErikSorensen
- 215
- 1
- 16
0
If you want to use TreeNet
class from mininet.topolib
:
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.node import OVSKernelSwitch
from mininet.topolib import TreeNet
from mininet.net import Mininet
from mininet.node import RemoteController
if __name__ == '__main__':
setLogLevel( 'info' )
print "Input Depth :"
_depth = int(raw_input())
print "Input fanout :"
_fanout = int(raw_input())
network = TreeNet( depth= _depth, fanout= _fanout, controller= RemoteController, autoSetMacs = True, cleanup = True, switch=OVSKernelSwitch)
print network.topo.links()
# network.startTerms()
network.run(CLI, network)

sinhayash
- 2,693
- 4
- 19
- 51