Attempt at revised/simplified topo class:
- keys are strings - metadata is simply a dict - buildFromTopo greatly simplified
This commit is contained in:
+10
-19
@@ -1,6 +1,6 @@
|
||||
"Library of potentially useful topologies for Mininet"
|
||||
|
||||
from mininet.topo import Topo, Node
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
|
||||
class TreeTopo( Topo ):
|
||||
@@ -8,36 +8,27 @@ class TreeTopo( Topo ):
|
||||
|
||||
def __init__( self, depth=1, fanout=2 ):
|
||||
super( TreeTopo, self ).__init__()
|
||||
# Numbering: h1..N, sN+1..M
|
||||
hostCount = fanout ** depth
|
||||
# Numbering: h1..N, s1..M
|
||||
self.hostNum = 1
|
||||
self.switchNum = hostCount + 1
|
||||
self.switchNum = 1
|
||||
# Build topology
|
||||
self.addTree( 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, depth, fanout ):
|
||||
"""Add a subtree starting with node n.
|
||||
returns: last node added"""
|
||||
isSwitch = depth > 0
|
||||
if isSwitch:
|
||||
num = self.switchNum
|
||||
node = self.add_switch( 's%s' % self.switchNum )
|
||||
self.switchNum += 1
|
||||
else:
|
||||
num = self.hostNum
|
||||
self.hostNum += 1
|
||||
self.add_node( num, Node( is_switch=isSwitch ) )
|
||||
if isSwitch:
|
||||
for i in range( 0, fanout ):
|
||||
for _ in range( fanout ):
|
||||
child = self.addTree( depth - 1, fanout )
|
||||
self.add_edge( num, child )
|
||||
return num
|
||||
self.add_link( node, child )
|
||||
else:
|
||||
node = self.add_host( 'h%s' % self.hostNum )
|
||||
self.hostNum += 1
|
||||
return node
|
||||
|
||||
# pylint: enable-msg=W0612
|
||||
|
||||
def TreeNet( depth=1, fanout=2, **kwargs ):
|
||||
"Convenience function for creating tree networks."
|
||||
|
||||
Reference in New Issue
Block a user