Adding number of hosts per switch option to torus topo
This commit is contained in:
+12
-3
@@ -45,10 +45,18 @@ class TorusTopo( Topo ):
|
|||||||
without STP turned on! It can be used with STP, e.g.:
|
without STP turned on! It can be used with STP, e.g.:
|
||||||
# mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall"""
|
# mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall"""
|
||||||
|
|
||||||
def build( self, x, y ):
|
def build( self, x, y, n=1 ):
|
||||||
|
"""x: dimension of torus in x-direction
|
||||||
|
y: dimension of torus in y-direction
|
||||||
|
n: number of hosts per switch"""
|
||||||
if x < 3 or y < 3:
|
if x < 3 or y < 3:
|
||||||
raise Exception( 'Please use 3x3 or greater for compatibility '
|
raise Exception( 'Please use 3x3 or greater for compatibility '
|
||||||
'with 2.1' )
|
'with 2.1' )
|
||||||
|
if n == 1:
|
||||||
|
genHostName = lambda loc, k: 'h%s' % ( loc )
|
||||||
|
else:
|
||||||
|
genHostName = lambda loc, k: 'h%sx%d' % ( loc, k )
|
||||||
|
|
||||||
hosts, switches, dpid = {}, {}, 0
|
hosts, switches, dpid = {}, {}, 0
|
||||||
# Create and wire interior
|
# Create and wire interior
|
||||||
for i in range( 0, x ):
|
for i in range( 0, x ):
|
||||||
@@ -58,8 +66,9 @@ class TorusTopo( Topo ):
|
|||||||
dpid = ( i + 1 ) * 256 + ( j + 1 )
|
dpid = ( i + 1 ) * 256 + ( j + 1 )
|
||||||
switch = switches[ i, j ] = self.addSwitch(
|
switch = switches[ i, j ] = self.addSwitch(
|
||||||
's' + loc, dpid='%016x' % dpid )
|
's' + loc, dpid='%016x' % dpid )
|
||||||
host = hosts[ i, j ] = self.addHost( 'h' + loc )
|
for k in range( 0, n ):
|
||||||
self.addLink( host, switch )
|
host = hosts[ i, j, k ] = self.addHost( genHostName( loc, k + 1 ) )
|
||||||
|
self.addLink( host, switch )
|
||||||
# Connect switches
|
# Connect switches
|
||||||
for i in range( 0, x ):
|
for i in range( 0, x ):
|
||||||
for j in range( 0, y ):
|
for j in range( 0, y ):
|
||||||
|
|||||||
Reference in New Issue
Block a user