From 11a6d400c57c3ab90af52d4dd1329c71425e00e0 Mon Sep 17 00:00:00 2001 From: Bob Lantz <rlantz@cs.stanford.edu> Date: Fri, 5 Mar 2010 15:07:00 -0800 Subject: [PATCH] Added mininet.topolib to store useful topologies. --- mininet/topolib.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 mininet/topolib.py diff --git a/mininet/topolib.py b/mininet/topolib.py new file mode 100644 index 00000000..ad012670 --- /dev/null +++ b/mininet/topolib.py @@ -0,0 +1,31 @@ +"Library of potentially useful topologies for Mininet" + +from mininet.topo import Topo, Node + +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__() + # Build topology + self.addTree( 1, depth, fanout ) + # Consider all switches and hosts 'on' + self.enable_all() + + # It is OK that i is "unused" in the for loop. + # pylint: disable-msg=W0612 + + def addTree( self, n, depth, fanout ): + """Add a subtree starting with node n. + returns: last node added""" + me = n + isSwitch = depth > 0 + self._add_node( me, Node( is_switch=isSwitch ) ) + if isSwitch: + for i in range( 0, fanout ): + child = n + 1 + self._add_edge( me, child ) + n = self.addTree( child, depth-1, fanout ) + return n + + # pylint: enable-msg=W0612 -- GitLab