blob: 63ba36deb3d51e5a246545e7bfe8782ed4a3848e [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001"Library of potentially useful topologies for Mininet"
2
3from mininet.topo import Topo
4from mininet.net import Mininet
5
6class TreeTopo( Topo ):
7 "Topology for a tree network with a given depth and fanout."
8
9 def __init__( self, depth=1, fanout=2 ):
10 super( TreeTopo, self ).__init__()
11 # Numbering: h1..N, s1..M
12 self.hostNum = 1
13 self.switchNum = 1
14 # Build topology
15 self.addTree( depth, fanout )
16
17 def addTree( self, depth, fanout ):
18 """Add a subtree starting with node n.
19 returns: last node added"""
20 isSwitch = depth > 0
21 if isSwitch:
22 node = self.addSwitch( 's%s' % self.switchNum )
23 self.switchNum += 1
24 for _ in range( fanout ):
25 child = self.addTree( depth - 1, fanout )
26 self.addLink( node, child )
27 else:
28 node = self.addHost( 'h%s' % self.hostNum )
29 self.hostNum += 1
30 return node
31
32
33def TreeNet( depth=1, fanout=2, **kwargs ):
34 "Convenience function for creating tree networks."
35 topo = TreeTopo( depth, fanout )
36 return Mininet( topo, **kwargs )