From c771b2d75aec973253674bc15fef6bdd3d11b5b4 Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Sun, 24 Mar 2013 16:14:04 -0700
Subject: [PATCH] Add source node option to moveIntf() (note: low-level API!!)
 In the future we may wish to enable moving interfaces across nodes which are
 not in the root NS, and this would provide the low-level mechanism to do so.
 closes #122

---
 mininet/util.py | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/mininet/util.py b/mininet/util.py
index 8ae96b5f..da55eaad 100644
--- a/mininet/util.py
+++ b/mininet/util.py
@@ -171,27 +171,35 @@ def retry( retries, delaySecs, fn, *args, **keywords ):
         error( "*** gave up after %i retries\n" % tries )
         exit( 1 )
 
-def moveIntfNoRetry( intf, node, printError=False ):
+def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
     """Move interface to node, without retrying.
        intf: string, interface
-       node: Node object
-       printError: if true, print error"""
-    cmd = 'ip link set ' + intf + ' netns ' + repr( node.pid )
-    quietRun( cmd )
-    links = node.cmd( 'ip link show' )
+        dstNode: destination Node
+        srcNode: source Node or None (default) for root ns
+        printError: if true, print error"""
+    intf = str( intf )
+    cmd = 'ip link set %s netns %s' % ( intf, dstNode.pid )
+    if srcNode:
+        srcNode.cmd( cmd )
+    else:
+        quietRun( cmd )
+    links = dstNode.cmd( 'ip link show' )
     if not ( ' %s:' % intf ) in links:
         if printError:
             error( '*** Error: moveIntf: ' + intf +
-                   ' not successfully moved to ' + node.name + '\n' )
+                   ' not successfully moved to ' + dstNode.name + '\n' )
         return False
     return True
 
-def moveIntf( intf, node, printError=False, retries=3, delaySecs=0.001 ):
+def moveIntf( intf, dstNode, srcNode=None, printError=False,
+             retries=3, delaySecs=0.001 ):
     """Move interface to node, retrying on failure.
        intf: string, interface
-       node: Node object
+       dstNode: destination Node
+       srcNode: source Node or None (default) for root ns
        printError: if true, print error"""
-    retry( retries, delaySecs, moveIntfNoRetry, intf, node, printError )
+    retry( retries, delaySecs, moveIntfNoRetry, intf, dstNode,
+          srcNode=srcNode, printError=printError )
 
 # Support for dumping network
 
-- 
GitLab