Mininet - Need custom tree topology script

1.3k views Asked by At

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.

2

There are 2 answers

0
sinhayash On

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)
0
ErikSorensen On

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() ) }