From 93cd5583eb9618ca38ba450bfa999975b1a3c77a Mon Sep 17 00:00:00 2001 From: Rich Lane Date: Thu, 22 May 2014 12:18:08 -0700 Subject: [PATCH 1/2] IVSSwitch: support batch shutdown Not a single command like the OVS one, but it still greatly decreases the shutdown time. This does assume that stop() is called after batchShutdown(), which is true in the current mininet code. --- mininet/node.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mininet/node.py b/mininet/node.py index 27d1e16..fdc855e 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -1106,6 +1106,13 @@ class IVSSwitch(Switch): 'not be loaded. Try modprobe openvswitch.\n' ) exit( 1 ) + @classmethod + def batchShutdown( cls, switches ): + "Kill each IVS switch, to be waited on later in stop()" + for switch in switches: + if type(switch) == cls: + switch.cmd( 'kill %ivs' ) + def start( self, controllers ): "Start up a new IVS switch" args = ['ivs'] From 876e66e5553fe1c93ef4ad4d3c9cbff5bb3735ee Mon Sep 17 00:00:00 2001 From: Rich Lane Date: Thu, 22 May 2014 12:36:07 -0700 Subject: [PATCH 2/2] net: allow batch shutdown of multiple types of switches Each switch class will be called to shutdown its own instances. --- mininet/net.py | 7 +++---- mininet/node.py | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index 1c932f9..8edaee3 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -91,7 +91,7 @@ import re import select import signal from time import sleep -from itertools import chain +from itertools import chain, groupby from mininet.cli import CLI from mininet.log import info, error, debug, output @@ -408,10 +408,9 @@ class Mininet( object ): info( '*** Stopping %i terms\n' % len( self.terms ) ) self.stopXterms() info( '*** Stopping %i switches\n' % len( self.switches ) ) - if self.switches: - swclass = type( self.switches[ 0 ] ) + for swclass, switches in groupby( sorted( self.switches, key=type ), type ): if hasattr( swclass, 'batchShutdown' ): - swclass.batchShutdown( self.switches ) + swclass.batchShutdown( switches ) for switch in self.switches: info( switch.name + ' ' ) switch.stop() diff --git a/mininet/node.py b/mininet/node.py index fdc855e..54bfd23 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -993,7 +993,7 @@ class OVSSwitch( Switch ): "Call ovs-vsctl del-br on all OVSSwitches in a list" quietRun( 'ovs-vsctl ' + ' -- '.join( '--if-exists del-br %s' % s - for s in switches if type(s) == cls ) ) + for s in switches ) ) def dpctl( self, *args ): "Run ovs-ofctl command" @@ -1110,8 +1110,7 @@ class IVSSwitch(Switch): def batchShutdown( cls, switches ): "Kill each IVS switch, to be waited on later in stop()" for switch in switches: - if type(switch) == cls: - switch.cmd( 'kill %ivs' ) + switch.cmd( 'kill %ivs' ) def start( self, controllers ): "Start up a new IVS switch"