Statistics
| Branch: | Tag: | Revision:

## mininet / mininet / topolib.py @ 32507498

1 2 3 11a6d400 Bob Lantz ```"Library of potentially useful topologies for Mininet" ``` 5a8bb489 Bob Lantz ```from mininet.topo import Topo ``` cd745748 Bob Lantz ```from mininet.net import Mininet ``` 11a6d400 Bob Lantz ```class TreeTopo( Topo ): ``` ``` "Topology for a tree network with a given depth and fanout." ``` ``` def __init__( self, depth=1, fanout=2 ): ``` ``` super( TreeTopo, self ).__init__() ``` 5a8bb489 Bob Lantz ``` # Numbering: h1..N, s1..M ``` 06b8210e Bob Lantz ``` self.hostNum = 1 ``` 5a8bb489 Bob Lantz ``` self.switchNum = 1 ``` 11a6d400 Bob Lantz ``` # Build topology ``` 06b8210e Bob Lantz ``` self.addTree( depth, fanout ) ``` 11a6d400 Bob Lantz 06b8210e Bob Lantz ``` def addTree( self, depth, fanout ): ``` 11a6d400 Bob Lantz ``` """Add a subtree starting with node n. ``` ``` returns: last node added""" ``` ``` isSwitch = depth > 0 ``` 06b8210e Bob Lantz ``` if isSwitch: ``` ce15c4f6 Bob Lantz ``` node = self.addSwitch( 's%s' % self.switchNum ) ``` 06b8210e Bob Lantz ``` self.switchNum += 1 ``` 5a8bb489 Bob Lantz ``` for _ in range( fanout ): ``` ``` child = self.addTree( depth - 1, fanout ) ``` ce15c4f6 Bob Lantz ``` self.addLink( node, child ) ``` 06b8210e Bob Lantz ``` else: ``` ce15c4f6 Bob Lantz ``` node = self.addHost( 'h%s' % self.hostNum ) ``` 06b8210e Bob Lantz ``` self.hostNum += 1 ``` 5a8bb489 Bob Lantz ``` return node ``` 11a6d400 Bob Lantz cd745748 Bob Lantz ```def TreeNet( depth=1, fanout=2, **kwargs ): ``` ``` "Convenience function for creating tree networks." ``` ``` topo = TreeTopo( depth, fanout ) ``` ` return Mininet( topo, **kwargs )`