Clean up standard topologies to use build
This commit is contained in:
+11
-31
@@ -201,19 +201,13 @@ class Topo(object):
|
|||||||
"Items sorted in natural (i.e. alphabetical) order"
|
"Items sorted in natural (i.e. alphabetical) order"
|
||||||
return sorted(items, key=natural)
|
return sorted(items, key=natural)
|
||||||
|
|
||||||
|
|
||||||
class SingleSwitchTopo( Topo ):
|
class SingleSwitchTopo( Topo ):
|
||||||
'''Single switch connected to k hosts.'''
|
"Single switch connected to k hosts."
|
||||||
|
|
||||||
def __init__(self, k=2, **opts):
|
|
||||||
'''Init.
|
|
||||||
|
|
||||||
@param k number of hosts
|
|
||||||
@param enable_all enables all nodes and switches?
|
|
||||||
'''
|
|
||||||
super(SingleSwitchTopo, self).__init__(**opts)
|
|
||||||
|
|
||||||
|
def build( self, k=2, **opts ):
|
||||||
|
"k: number of hosts"
|
||||||
self.k = k
|
self.k = k
|
||||||
|
|
||||||
switch = self.addSwitch( 's1' )
|
switch = self.addSwitch( 's1' )
|
||||||
for h in irange( 1, k ):
|
for h in irange( 1, k ):
|
||||||
host = self.addHost( 'h%s' % h )
|
host = self.addHost( 'h%s' % h )
|
||||||
@@ -221,19 +215,12 @@ class SingleSwitchTopo(Topo):
|
|||||||
|
|
||||||
|
|
||||||
class SingleSwitchReversedTopo( Topo ):
|
class SingleSwitchReversedTopo( Topo ):
|
||||||
'''Single switch connected to k hosts, with reversed ports.
|
"""Single switch connected to k hosts, with reversed ports.
|
||||||
|
|
||||||
The lowest-numbered host is connected to the highest-numbered port.
|
The lowest-numbered host is connected to the highest-numbered port.
|
||||||
|
Useful to verify that Mininet properly handles custom port numberings."""
|
||||||
|
|
||||||
Useful to verify that Mininet properly handles custom port numberings.
|
def build( self, k=2 ):
|
||||||
'''
|
"k: number of hosts"
|
||||||
def __init__(self, k=2, **opts):
|
|
||||||
'''Init.
|
|
||||||
|
|
||||||
@param k number of hosts
|
|
||||||
@param enable_all enables all nodes and switches?
|
|
||||||
'''
|
|
||||||
super(SingleSwitchReversedTopo, self).__init__(**opts)
|
|
||||||
self.k = k
|
self.k = k
|
||||||
switch = self.addSwitch( 's1' )
|
switch = self.addSwitch( 's1' )
|
||||||
for h in irange( 1, k ):
|
for h in irange( 1, k ):
|
||||||
@@ -244,15 +231,9 @@ class SingleSwitchReversedTopo(Topo):
|
|||||||
class LinearTopo( Topo ):
|
class LinearTopo( Topo ):
|
||||||
"Linear topology of k switches, with n hosts per switch."
|
"Linear topology of k switches, with n hosts per switch."
|
||||||
|
|
||||||
def __init__(self, k=2, n=1, **opts):
|
def build( self, k=2, n=1, **opts):
|
||||||
"""Init.
|
"""k: number of switches
|
||||||
k: number of switches
|
n: number of hosts per switch"""
|
||||||
n: number of hosts per switch
|
|
||||||
hconf: host configuration options
|
|
||||||
lconf: link configuration options"""
|
|
||||||
|
|
||||||
super(LinearTopo, self).__init__(**opts)
|
|
||||||
|
|
||||||
self.k = k
|
self.k = k
|
||||||
self.n = n
|
self.n = n
|
||||||
|
|
||||||
@@ -261,7 +242,6 @@ class LinearTopo(Topo):
|
|||||||
else:
|
else:
|
||||||
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
|
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
|
||||||
|
|
||||||
|
|
||||||
lastSwitch = None
|
lastSwitch = None
|
||||||
for i in irange( 1, k ):
|
for i in irange( 1, k ):
|
||||||
# Add switch
|
# Add switch
|
||||||
|
|||||||
+3
-4
@@ -6,8 +6,7 @@ from mininet.net import Mininet
|
|||||||
class TreeTopo( Topo ):
|
class TreeTopo( Topo ):
|
||||||
"Topology for a tree network with a given depth and fanout."
|
"Topology for a tree network with a given depth and fanout."
|
||||||
|
|
||||||
def __init__( self, depth=1, fanout=2 ):
|
def build( self, depth=1, fanout=2 ):
|
||||||
super( TreeTopo, self ).__init__()
|
|
||||||
# Numbering: h1..N, s1..M
|
# Numbering: h1..N, s1..M
|
||||||
self.hostNum = 1
|
self.hostNum = 1
|
||||||
self.switchNum = 1
|
self.switchNum = 1
|
||||||
@@ -42,8 +41,8 @@ class TorusTopo( Topo ):
|
|||||||
with the default controller or any Ethernet bridge
|
with the default controller or any Ethernet bridge
|
||||||
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 __init__( self, x, y, *args, **kwargs ):
|
|
||||||
Topo.__init__( self, *args, **kwargs )
|
def build( self, x, y ):
|
||||||
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 Mininet 2.1.0' )
|
'with Mininet 2.1.0' )
|
||||||
|
|||||||
Reference in New Issue
Block a user