From 08cef003f7e11e9d8ee6df3390b7a7979f172f4e Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Fri, 11 Dec 2009 06:17:42 -0800
Subject: [PATCH] Changed cleanup to vaporize zombie screen sessions. Other
 minor cleanup.

---
 README             |  6 +++---
 cleanup            |  2 ++
 examples/sshd.py   | 13 +++++-------
 examples/xterms.py |  3 ++-
 mininet.py         | 50 ++++++++++++++++++++++++++--------------------
 5 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/README b/README
index e9ae2572..daba8521 100644
--- a/README
+++ b/README
@@ -31,8 +31,8 @@ In order to run Mininet, you must have:
 
 * Root privileges (required for network device access)
 
-* The netns program (included as netns.c), or an equivalent program called
-  'netns', installed in an appropriate path location.
+* The netns program (included as netns.c), or an equivalent program
+  of the same name, installed in an appropriate path location.
   
 * mininet.py installed in an appropriate Python path location.
 
@@ -43,7 +43,7 @@ Currently mininet includes:
 	
 - A simple network infrastructure (class Network and its descendants
   TreeNet, GridNet and LinearNet) for creating scalable topologies and
-  running experiments (using someNetwork.run( test ) )
+  running experiments (e.g. TreeNet(2,3).run(pingTest) )
   
 - Some simple tests which can be run using someNetwork.run( test )
 	
diff --git a/cleanup b/cleanup
index 4c0a553d..263f9b3d 100755
--- a/cleanup
+++ b/cleanup
@@ -17,4 +17,6 @@ ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/' | xargs -l1 echo dpctl deldp
 echo "Removing vconn junk in /tmp"
 rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
 
+echo "Removing old screen sessions"
+screen -ls | egrep -o '[0-9]+\.[hsc][0-9]+' | sed 's/\.[hsc][0-9]*//g' | kill -9
 
diff --git a/examples/sshd.py b/examples/sshd.py
index 1dac53ca..f2840a50 100755
--- a/examples/sshd.py
+++ b/examples/sshd.py
@@ -1,13 +1,10 @@
 #!/usr/bin/python
 
 """Create a network and start sshd(8) on the hosts.
-   This is probably overkill - rshd(8) would be
-   perfectly adequate, considering that the openflow
-   network is private to the machine it's running on.
-   It would also be lighter weight/faster.
-   Nonetheless, most people already have sshd installed,
-   and it's a good demo to show that mininet makes a
-   'real', usable network! """
+   While something like rshd(8) would be lighter and faster,
+   (and perfectly adequate on an in-machine network)
+   the advantage of running sshd is that scripts can work
+   unchanged on mininet and hardware."""
 
 from mininet import init, Node, createLink, TreeNet, Cli
 
@@ -16,7 +13,7 @@ def nets( hosts ):
    nets = {}
    for host in hosts:
       net = host.IP().split( '.' )[ : -1 ]
-      net = '.'.join ( net ) + '.0/24'
+      net = '.'.join( net ) + '.0/24'
       nets[ net ] = True
    return nets.keys()
    
diff --git a/examples/xterms.py b/examples/xterms.py
index 20800969..c8410fed 100755
--- a/examples/xterms.py
+++ b/examples/xterms.py
@@ -20,9 +20,10 @@ def makeXterm( node, title ):
    return Popen( cmd )
 
 def cleanUpScreens():
-   "Remove moldy old screen sessions."
+   "Remove moldy old screen sessions."      
    # XXX We need to implement this - otherwise those darned
    # screen sessions will just accumulate
+   output = quietRun( 'screen -ls' )
    pass
    
 def makeXterms( nodes, title ):
diff --git a/mininet.py b/mininet.py
index 12cb92ee..7fdb5896 100755
--- a/mininet.py
+++ b/mininet.py
@@ -3,14 +3,9 @@
 """
 Mininet: A simple networking testbed for OpenFlow!
 
-Mininet creates simple OpenFlow test networks by using
+Mininet creates scalable OpenFlow test networks by using
 process-based virtualization and network namespaces. 
 
-This file supports use of either the kernel or user space datapath
-from the OpenFlow reference implementation. Up to 32 switches are
-supported using the kernel datapath, and 512 (or more) switches are
-supported via the user datapath.
-
 Simulated hosts are created as processes in separate network
 namespaces. This allows a complete OpenFlow network to be simulated on
 top of a single Linux kernel.
@@ -23,6 +18,9 @@
 Hosts have a network interface which is configured via ifconfig/ip
 link/etc. with data network IP addresses (e.g. 192.168.123.2 )
 
+This version supports both the kernel or user space datapaths
+from the OpenFlow reference implementation.
+
 In kernel datapath mode, the controller and switches are simply
 processes in the root namespace.
 
@@ -48,15 +46,15 @@
 Thoughts/TBD:
 
    It should be straightforward to add a function to read
-   OpenFlowVMS  spec files, but I haven't done so yet.
+   OpenFlowVMS spec files, but I haven't done so yet.
    For the moment, specifying configurations and tests in Python
-   is straightforward and concise.
-   Soon, we'll want to split the various subsystems (core,
+   is straightforward and relatively concise.
+   Soon, we may want to split the various subsystems (core,
    cli, tests, etc.) into multiple modules.
-   We may be able to get better performance by using the kernel
-   datapath (using its multiple datapath feature on multiple 
-   interfaces.) This would eliminate the ofdatapath user processes.
-   OpenVSwitch would still run at user level.
+   We don't support nox nicely just yet - you have to hack this file
+   or subclass things aggressively.
+   We'd like to support OpenVSwitch as well as the reference
+   implementation.
    
 Bob Lantz
 rlantz@cs.stanford.edu
@@ -65,6 +63,7 @@
 11/19/09 Initial revision (user datapath only)
 12/08/09 Kernel datapath support complete
 12/09/09 Moved controller and switch routines into classes
+12/12/09 Added subdivided network driver workflow
 """
 
 from subprocess import call, check_call, Popen, PIPE, STDOUT
@@ -289,7 +288,13 @@ def startKernelDatapath( self, controller):
    def stopKernelDatapath( self ):
       "Terminate a switch using OpenFlow reference kernel datapath."
       quietRun( 'dpctl deldp ' + self.dp )
-      for intf in self.intfs: quietRun( 'ip link del ' + intf )
+      # In theory the interfaces should go away after we shut down.
+      # However, this takes time, so we're better off to remove them
+      # explicitly so that we won't get errors if we run before they
+      # have been removed by the kernel. Unfortunately this is very slow.
+      for intf in self.intfs:
+         quietRun( 'ip link del ' + intf )
+         sys.stdout.write( '.' ) ; flush()
       self.terminate()
    def start( self, controller ): 
       if self.dp is None: self.startUserDatapath( controller )
@@ -435,14 +440,13 @@ class Network( object ):
    def __init__( self, kernel=True, startAddr=( 192, 168, 123, 1) ):
       self.kernel, self.startAddr = kernel, startAddr
       # Check for kernel modules
-      tun = quietRun( [ 'sh', '-c', 'lsmod | grep tun' ] )
-      ofdatapath = quietRun( [ 'sh', '-c', 'lsmod | grep ofdatapath' ] )
-      if tun == '' and not kernel: 
+      modules = quietRun( 'lsmod' )
+      if not kernel and 'tun' not in modules:
          print "*** Error: kernel module tun not loaded:",
          print " user datapath not supported"
          exit( 1 )
-      if ofdatapath == '' and kernel:
-         print "*** Error: ofdatapath not loaded:",
+      if kernel and 'ofdatapath' not in modules:
+         print "*** Error: kernel module ofdatapath not loaded:",
          print " kernel datapath not supported"
          exit( 1 )
       # Create network, but don't start things up yet!
@@ -551,7 +555,9 @@ def makeNet( self, controller ):
 # Grid network
 
 class GridNet( Network ):
-   "An N x M grid/mesh network of switches, with hosts at the edges."
+   """An N x M grid/mesh network of switches, with hosts at the edges.
+      This class also demonstrates creating a somewhat complicated
+      topology."""
    def __init__( self, n, m, kernel=True, linear=False ):
       self.n, self.m, self.linear = n, m, linear and m == 1
       Network.__init__( self, kernel )
@@ -711,7 +717,7 @@ def help( self, args ):
       print
       print "Interactive commands are not really supported yet,"
       print "so please limit commands to ones that do not"
-      print "require user interaction, and that will terminate"
+      print "require user interaction and will terminate"
       print "after a reasonable amount of time."
    def nodes( self, args ):
       "List available nodes"
@@ -725,7 +731,7 @@ def net( self, args ):
       for switch in self.switches:
          print switch.name, "<->",
          for intf in switch.intfs:
-            node, rintf = switch.connection[ intf ]
+            node, remoteIntf = switch.connection[ intf ]
             print node.name,
          print
    def iperf( self, args ):
-- 
GitLab