From d66b96260a34a8b236821efc947a32d5a074088a Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Thu, 15 Jan 2015 02:05:20 -0800
Subject: [PATCH] Don't stop switches that we've already stopped.

Note that this also changes the way that links are deleted;
the reason is that the batch shutdown doesn't currently delete
the links, but OVSSwitch.stop() does. We may wish to revisit
this in the future.
---
 mininet/net.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/mininet/net.py b/mininet/net.py
index 01e19360..d59a0897 100755
--- a/mininet/net.py
+++ b/mininet/net.py
@@ -495,20 +495,25 @@ def stop( self ):
         if self.terms:
             info( '*** Stopping %i terms\n' % len( self.terms ) )
             self.stopXterms()
+        info( '*** Stopping %i links\n' % len( self.links ) )
+        for link in self.links:
+            info( '.' )
+            link.stop()
+        info( '\n' )
         info( '*** Stopping %i switches\n' % len( self.switches ) )
+        stopped = {}
         for swclass, switches in groupby(
                 sorted( self.switches, key=type ), type ):
+            switches = tuple( switches )
             if hasattr( swclass, 'batchShutdown' ):
                 swclass.batchShutdown( switches )
+            stopped.update( { s: s for s in switches } )
         for switch in self.switches:
             info( switch.name + ' ' )
-            switch.stop()
+            if switch not in stopped:
+                switch.stop()
             switch.terminate()
         info( '\n' )
-        info( '*** Stopping %i links\n' % len( self.links ) )
-        for link in self.links:
-            link.stop()
-        info( '\n' )
         info( '*** Stopping %i hosts\n' % len( self.hosts ) )
         for host in self.hosts:
             info( host.name + ' ' )
-- 
GitLab