mininet / mininet / topolib.py @ 824afb84
History | View | Annotate | Download (1.12 KB)
1 | 11a6d400 | Bob Lantz | "Library of potentially useful topologies for Mininet"
|
---|---|---|---|
2 | |||
3 | 5a8bb489 | Bob Lantz | from mininet.topo import Topo |
4 | cd745748 | Bob Lantz | from mininet.net import Mininet |
5 | 11a6d400 | Bob Lantz | |
6 | class 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 | 5a8bb489 | Bob Lantz | # Numbering: h1..N, s1..M
|
12 | 06b8210e | Bob Lantz | self.hostNum = 1 |
13 | 5a8bb489 | Bob Lantz | self.switchNum = 1 |
14 | 11a6d400 | Bob Lantz | # Build topology
|
15 | 06b8210e | Bob Lantz | self.addTree( depth, fanout )
|
16 | 11a6d400 | Bob Lantz | |
17 | 06b8210e | Bob Lantz | def addTree( self, depth, fanout ): |
18 | 11a6d400 | Bob Lantz | """Add a subtree starting with node n.
|
19 | returns: last node added"""
|
||
20 | isSwitch = depth > 0
|
||
21 | 06b8210e | Bob Lantz | if isSwitch:
|
22 | ce15c4f6 | Bob Lantz | node = self.addSwitch( 's%s' % self.switchNum ) |
23 | 06b8210e | Bob Lantz | self.switchNum += 1 |
24 | 5a8bb489 | Bob Lantz | for _ in range( fanout ): |
25 | child = self.addTree( depth - 1, fanout ) |
||
26 | ce15c4f6 | Bob Lantz | self.addLink( node, child )
|
27 | 06b8210e | Bob Lantz | else:
|
28 | ce15c4f6 | Bob Lantz | node = self.addHost( 'h%s' % self.hostNum ) |
29 | 06b8210e | Bob Lantz | self.hostNum += 1 |
30 | 5a8bb489 | Bob Lantz | return node
|
31 | 11a6d400 | Bob Lantz | |
32 | cd745748 | Bob Lantz | |
33 | def TreeNet( depth=1, fanout=2, **kwargs ): |
||
34 | "Convenience function for creating tree networks."
|
||
35 | topo = TreeTopo( depth, fanout ) |
||
36 | return Mininet( topo, **kwargs ) |