Skip to content
Snippets Groups Projects
Commit 38ce329e authored by Bob Lantz's avatar Bob Lantz
Browse files

Allow Mininet() to accept multi-link topos w/correct params.

parent 94f088d7
No related branches found
No related tags found
No related merge requests found
...@@ -337,18 +337,18 @@ def addLink( self, node1, node2, port1=None, port2=None, ...@@ -337,18 +337,18 @@ def addLink( self, node1, node2, port1=None, port2=None,
paramDict: dictionary of additional link params (optional) paramDict: dictionary of additional link params (optional)
params: additional link params (optional) params: additional link params (optional)
returns: link object""" returns: link object"""
mac1 = self.randMac()
mac2 = self.randMac()
paramDict = {} if paramDict is None else paramDict
paramDict.update( params )
# Ugly: try to ensure that node1 and node2 line up correctly with # Ugly: try to ensure that node1 and node2 line up correctly with
# other link parameters # other link parameters, and allow either nodes or names
node1 = self[ paramDict.pop( 'node1', node1.name ) ] paramDict = {} if paramDict is None else dict( paramDict )
node2 = self[ paramDict.pop( 'node2', node2.name ) ] paramDict.update( params )
node1 = paramDict.pop( 'node1', node1 )
node2 = paramDict.pop( 'node2', node1 )
node1 = node1 if type( node1 ) != str else self[ node1 ]
node2 = node2 if type( node2 ) != str else self[ node2 ]
paramDict.setdefault( 'port1', port1 ) paramDict.setdefault( 'port1', port1 )
paramDict.setdefault( 'port2', port2 ) paramDict.setdefault( 'port2', port2 )
paramDict.setdefault( 'addr1', mac1 ) paramDict.setdefault( 'addr1', self.randMac() )
paramDict.setdefault( 'addr2', mac2 ) paramDict.setdefault( 'addr2', self.randMac() )
cls = self.link if cls is None else cls cls = self.link if cls is None else cls
link = cls( node1, node2, **paramDict ) link = cls( node1, node2, **paramDict )
self.links.append( link ) self.links.append( link )
...@@ -408,12 +408,10 @@ def buildFromTopo( self, topo=None ): ...@@ -408,12 +408,10 @@ def buildFromTopo( self, topo=None ):
info( switchName + ' ' ) info( switchName + ' ' )
info( '\n*** Adding links:\n' ) info( '\n*** Adding links:\n' )
for srcName, dstName in topo.links( sort=True ): for srcName, dstName, params in topo.links(
src, dst = self.nameToNode[ srcName ], self.nameToNode[ dstName ] sort=True, withInfo=True ):
params = topo.linkInfo( srcName, dstName ) self.addLink( srcName, dstName, paramDict=params )
srcPort, dstPort = topo.port( srcName, dstName ) info( '(%s, %s) ' % ( srcName, dstName ) )
self.addLink( src, dst, srcPort, dstPort, paramDict=params )
info( '(%s, %s) ' % ( src.name, dst.name ) )
info( '\n' ) info( '\n' )
......
...@@ -53,22 +53,24 @@ def nodes( self, data=False): ...@@ -53,22 +53,24 @@ def nodes( self, data=False):
data: return list of ( node, attrs)""" data: return list of ( node, attrs)"""
return self.node.items() if data else self.node.keys() return self.node.items() if data else self.node.keys()
def edges_iter( self, data=False ): def edges_iter( self, data=False, key=False):
"Iterator: return graph edges" "Iterator: return graph edges"
for src, entry in self.edge.iteritems(): for src, entry in self.edge.iteritems():
for dst, keys in entry.iteritems(): for dst, keys in entry.iteritems():
if [ src, dst ] != sorted( [ src, dst ] ): if [ src, dst ] != sorted( [ src, dst ] ):
# Skip duplicate edges # Skip duplicate edges
continue continue
for key, attrs in keys.iteritems(): for k, attrs in keys.iteritems():
if data: if data:
yield( ( src, dst, attrs ) ) yield( ( src, dst, attrs ) )
elif key:
yield( ( src, dst, k ) )
else: else:
yield( ( src, dst ) ) yield( ( src, dst ) )
def edges( self, data=False ): def edges( self, data=False, key=False ):
"Return list of graph edges" "Return list of graph edges"
return list( self.edges_iter( data ) ) return list( self.edges_iter( data=data, key=key ) )
def __getitem__( self, node ): def __getitem__( self, node ):
...@@ -88,7 +90,7 @@ def convertTo( self, cls, data=False ): ...@@ -88,7 +90,7 @@ def convertTo( self, cls, data=False ):
return g return g
class Topo(object): class Topo( object ):
"Data center network representation for structured multi-trees." "Data center network representation for structured multi-trees."
def __init__( self, *args, **params ): def __init__( self, *args, **params ):
...@@ -146,6 +148,7 @@ def addLink( self, node1, node2, port1=None, port2=None, ...@@ -146,6 +148,7 @@ def addLink( self, node1, node2, port1=None, port2=None,
opts = self.lopts opts = self.lopts
port1, port2 = self.addPort(node1, node2, port1, port2) port1, port2 = self.addPort(node1, node2, port1, port2)
opts.update( node1=node1, node2=node2, port1=port1, port2=port2 ) opts.update( node1=node1, node2=node2, port1=port1, port2=port2 )
assert 'node1' in opts
self.g.add_edge(node1, node2, key, opts ) self.g.add_edge(node1, node2, key, opts )
return key return key
...@@ -172,20 +175,24 @@ def hosts( self, sort=True ): ...@@ -172,20 +175,24 @@ def hosts( self, sort=True ):
returns: list of hosts""" returns: list of hosts"""
return [ n for n in self.nodes( sort ) if not self.isSwitch( n ) ] return [ n for n in self.nodes( sort ) if not self.isSwitch( n ) ]
def links( self, sort=True, withKeys=False ): def links( self, sort=True, withInfo=False, withKeys=False ):
"""Return links. """Return links.
sort: sort links alphabetically sort: sort links alphabetically
withKeys: return key in tuple withKeys: return key in tuple
@return links list of ( src, dst [,key ] )""" @return links list of ( src, dst [,key ] )"""
if not sort: if not sort:
return self.g.edges( withKeys ) return self.g.edges( data=withInfo, key=withKeys )
else: else:
if withKeys: if withInfo:
links = [ tuple( self.sorted( ( s, d ) ) ) + [ k ] links = [ tuple( self.sorted( ( s, d ) ) + [ info ] )
for s, d, k in self.g.edges( data=True ) ] for s, d, info in self.g.edges( data=True ) ]
elif withKeys:
links = [ tuple( self.sorted( ( s, d ) ) + [ key ] )
for s, d, key in self.g.edges( key=True ) ]
else: else:
links = [ tuple ( self.sorted( e ) ) for e in self.g.edges() ] links = [ tuple ( self.sorted( e ) )
return sorted( links, key=naturalSeq ) for e in self.g.edges() ]
return self.sorted( links )
# This legacy port management mechanism is clunky and will probably # This legacy port management mechanism is clunky and will probably
# be removed at some point. # be removed at some point.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment