From fb2f652319fc6a2e45a72728ee91f5d6bff58b91 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Tue, 23 Mar 2010 15:05:55 -0700 Subject: [PATCH] Changed mininet.link() to support multiple links. It should also probably be renamed to something like: configLinks(src, dst, status). --- mininet/net.py | 13 ++++--------- mininet/node.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index 8fdc07c..f4a6cc3 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -521,16 +521,11 @@ class Mininet( object ): elif dst not in self.nameToNode: error( 'dst not in network: %s\n' % dst ) else: - srcNode = self.nameToNode[ src ] - dstNode = self.nameToNode[ dst ] - srcID = int( src[ 1: ] ) - dstID = int( dst[ 1: ] ) - if self.topo.port( srcID, dstID ) is None: + srcNode, dstNode = self.nameToNode[ src ], self.nameToNode[ dst ] + connections = srcNode.connectionsTo( dstNode ) + if len( connections ) == 0: error( 'src and dst not connected: %s %s\n' % ( src, dst) ) - else: - srcPort, dstPort = self.topo.port( srcID, dstID ) - srcIntf = srcNode.intfs[ srcPort ] - dstIntf = dstNode.intfs[ dstPort ] + for srcIntf, dstIntf in connections: result = srcNode.cmd( [ 'ifconfig', srcIntf, status ] ) if result: error( 'link src status change failed: %s\n' % result ) diff --git a/mininet/node.py b/mininet/node.py index 18b65d1..fc5d4ff 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -261,6 +261,16 @@ class Node( object ): "Register connection of intf to dstIntf on dstNode." self.connection[ intf ] = ( dstNode, dstIntf ) + def connectionsTo( self, node): + "Return [(srcIntf, dstIntf)..] for connections to dstNode." + # We could optimize this if it is important + connections = [] + for intf in self.connection.keys(): + dstNode, dstIntf = self.connection[ intf ] + if dstNode == node: + connections.append( ( intf, dstIntf ) ) + return connections + # This is a symmetric operation, but it makes sense to put # the code here since it is tightly coupled to routines in # this class. For a more symmetric API, you can use