Statistics
| Branch: | Tag: | Revision:

mininet / mininet / topolib.py @ 80be5642

History | View | Annotate | Download (967 Bytes)

1
"Library of potentially useful topologies for Mininet"
2

    
3
from mininet.topo import Topo, Node
4

    
5
class TreeTopo( Topo ):
6
    "Topology for a tree network with a given depth and fanout."
7

    
8
    def __init__( self, depth=1, fanout=2 ):
9
        super( TreeTopo, self ).__init__()
10
        # Build topology
11
        self.addTree( 1, depth, fanout )
12
        # Consider all switches and hosts 'on'
13
        self.enable_all()
14

    
15
    # It is OK that i is "unused" in the for loop.
16
    # pylint: disable-msg=W0612
17

    
18
    def addTree( self, n, depth, fanout ):
19
        """Add a subtree starting with node n.
20
           returns: last node added"""
21
        me = n
22
        isSwitch = depth > 0
23
        self.add_node( me, Node( is_switch=isSwitch ) )
24
        if isSwitch:
25
            for i in range( 0, fanout ):
26
                child = n + 1
27
                self.add_edge( me, child )
28
                n = self.addTree( child, depth-1, fanout )
29
        return n
30

    
31
    # pylint: enable-msg=W0612