Mininet - Need custom tree topology script
Question: 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.


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

