Revision 5a8bb489 mininet/topolib.py

View differences:

mininet/topolib.py
1 1
"Library of potentially useful topologies for Mininet"
2 2

  
3
from mininet.topo import Topo, Node
3
from mininet.topo import Topo
4 4
from mininet.net import Mininet
5 5

  
6 6
class TreeTopo( Topo ):
......
8 8

  
9 9
    def __init__( self, depth=1, fanout=2 ):
10 10
        super( TreeTopo, self ).__init__()
11
        # Numbering:  h1..N, sN+1..M
12
        hostCount = fanout ** depth
11
        # Numbering:  h1..N, s1..M
13 12
        self.hostNum = 1
14
        self.switchNum = hostCount + 1
13
        self.switchNum = 1
15 14
        # Build topology
16 15
        self.addTree( depth, fanout )
17
        # Consider all switches and hosts 'on'
18
        self.enable_all()
19

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

  
23 17
    def addTree( self, depth, fanout ):
24 18
        """Add a subtree starting with node n.
25 19
           returns: last node added"""
26 20
        isSwitch = depth > 0
27 21
        if isSwitch:
28
            num = self.switchNum
22
            node = self.add_switch( 's%s' % self.switchNum )
29 23
            self.switchNum += 1
24
            for _ in range( fanout ):
25
                child = self.addTree( depth - 1, fanout )
26
                self.add_link( node, child )
30 27
        else:
31
            num = self.hostNum
28
            node = self.add_host( 'h%s' % self.hostNum )
32 29
            self.hostNum += 1
33
        self.add_node( num, Node( is_switch=isSwitch ) )
34
        if isSwitch:
35
            for i in range( 0, fanout ):
36
                child = self.addTree( depth - 1, fanout )
37
                self.add_edge( num, child )
38
        return num
30
        return node
39 31

  
40
    # pylint: enable-msg=W0612
41 32

  
42 33
def TreeNet( depth=1, fanout=2, **kwargs ):
43 34
    "Convenience function for creating tree networks."

Also available in: Unified diff