From b27cce08afd2201326ffb5a2376567ea43bf582b Mon Sep 17 00:00:00 2001 From: Brian O'Connor Date: Wed, 27 May 2015 23:44:41 -0700 Subject: [PATCH] Adding number of hosts per switch option to torus topo --- mininet/topolib.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mininet/topolib.py b/mininet/topolib.py index e459bcf..efebe3a 100644 --- a/mininet/topolib.py +++ b/mininet/topolib.py @@ -45,10 +45,18 @@ class TorusTopo( Topo ): without STP turned on! It can be used with STP, e.g.: # 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: raise Exception( 'Please use 3x3 or greater for compatibility ' '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 # Create and wire interior for i in range( 0, x ): @@ -58,8 +66,9 @@ class TorusTopo( Topo ): dpid = ( i + 1 ) * 256 + ( j + 1 ) switch = switches[ i, j ] = self.addSwitch( 's' + loc, dpid='%016x' % dpid ) - host = hosts[ i, j ] = self.addHost( 'h' + loc ) - self.addLink( host, switch ) + for k in range( 0, n ): + host = hosts[ i, j, k ] = self.addHost( genHostName( loc, k + 1 ) ) + self.addLink( host, switch ) # Connect switches for i in range( 0, x ): for j in range( 0, y ):