From 0a9ea29fd281e6b05c71e1672ad38c93871c8c8c Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Tue, 15 Dec 2009 19:53:22 -0800
Subject: [PATCH] Fixed problem for empty lists in cleanup. Added retry()
 function for createLink to see if it helps (probably won't.) Random edits to
 docs.

---
 INSTALL    |  2 +-
 README     |  3 ++-
 cleanup    |  4 ++--
 mininet.py | 19 ++++++++++++++-----
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/INSTALL b/INSTALL
index c8b99309..843f35ee 100644
--- a/INSTALL
+++ b/INSTALL
@@ -4,7 +4,7 @@ Preliminary Mininet Installation/Configuration Notes
 - This is not (yet) a 'release'; things may be broken.
 
 - Mininet is not currently 'installed.' If you want to install it,
-  so that you can 'import mininet', place it somewhere in your
+  so that you can 'import mininet', place mininet.py somewhere in your
   python path.
   
 - A functional netns binary is required to run mininet, but currently you
diff --git a/README b/README
index 59c19c14..2b2a0dfc 100644
--- a/README
+++ b/README
@@ -21,7 +21,8 @@ creation of OpenFlow networks of varying sizes and topologies.
 In order to run Mininet, you must have:
 
 * A Linux 2.6.26 or greater kernel compiled with network namespace support
-  enabled. (debian-testing seems to have such a kernel.)
+  enabled. (debian-testing seems to have such a kernel, but it doesn't
+  work for compiling nox, unfortunately.)
 
 * The OpenFlow reference implementation (either the user or kernel
   datapath may be used, and the tun or ofdatapath kernel modules must be
diff --git a/cleanup b/cleanup
index f3294b54..dedfb830 100755
--- a/cleanup
+++ b/cleanup
@@ -31,7 +31,7 @@ def cleanup():
    print "*** Removing all links of the pattern foo-ethX"
    links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
    for link in links: 
-      if link: sh( "ip link del " + link )
+      if link != '': sh( "ip link del " + link )
 
    print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
    zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core'
@@ -43,7 +43,7 @@ def cleanup():
    print "*** Removing excess kernel datapaths"
    dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
    for dp in dps: 
-      if dp: sh( 'ip link del ' + link )
+      if dp != '': sh( 'ip link del ' + link )
 
    print "*** Removing junk from /tmp"
    sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
diff --git a/mininet.py b/mininet.py
index f503cf79..3704a723 100755
--- a/mininet.py
+++ b/mininet.py
@@ -346,21 +346,30 @@ def makeIntfPair( intf1, intf2 ):
 def moveIntf( intf, node ):
    "Move intf to node."
    cmd = 'ip link set ' + intf + ' netns ' + `node.pid`
-   checkRun( cmd )
+   quietRun( cmd )
    links = node.cmd( 'ip link show' )
    if not intf in links:
       print "*** Error: moveIntf:", intf, "not successfully moved to",
       print node.name,":"
-      exit( 1 )
-   return
+      return False
+   return True
+
+def retry( n, fn, *args):
+   "Try something N times before giving up."
+   tries = 0
+   while not apply( fn, args ) and tries < 3:
+      sleep( 1 )
+      print "*** retrying..."; flush()
+      tries += 1
+   if tries > 3: exit( 1 )
    
 def createLink( node1, node2 ):
    "Create a link node1-intf1 <---> node2-intf2."
    intf1 = node1.newIntf()
    intf2 = node2.newIntf()
    makeIntfPair( intf1, intf2 )
-   if node1.inNamespace: moveIntf( intf1, node1 )
-   if node2.inNamespace: moveIntf( intf2, node2 )
+   if node1.inNamespace: retry( 3, moveIntf, intf1, node1 )
+   if node2.inNamespace: retry( 3, moveIntf, intf2, node2 )
    node1.connection[ intf1 ] = ( node2, intf2 )
    node2.connection[ intf2 ] = ( node1, intf1 )
    return intf1, intf2
-- 
GitLab