diff --git a/mininet/cli.py b/mininet/cli.py index 94489862f967090f73ab89889d693c28aae6ac2b..c3537eb436f5f31d4cb0fcd3866790f65bcf863c 100644 --- a/mininet/cli.py +++ b/mininet/cli.py @@ -351,6 +351,26 @@ def do_links( self, line ): for link in self.mn.links: print link, link.status() + def do_switch( self, line ): + "Starts or stops a switch" + args = line.split() + if len(args) != 2: + error( 'invalid number of args: switch <switch name> {start, stop}\n' ) + return + sw = args[ 0 ] + command = args[ 1 ] + if sw not in self.mn or self.mn.get( sw ) not in self.mn.switches : + error( 'invalid switch: %s\n' % args[ 1 ] ) + else: + sw = args[ 0 ] + command = args[ 1 ] + if command == 'start': + self.mn.get( sw ).start( self.mn.controllers ) + elif command == 'stop': + self.mn.get( sw ).stop( deleteIntfs=False ) + else: + error( 'invalid command: switch <switch name> {start, stop}\n' ) + def default( self, line ): """Called on an input line when the command prefix is not recognized. Overridden to run shell commands when a node is the first CLI argument. diff --git a/mininet/node.py b/mininet/node.py index 330097f60a527f550b53b3bc359b5215a838d47e..474b7e7d817335671f155f0a4b162c3474170940 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -981,11 +981,12 @@ def start( self, controllers ): if not intf.IP(): self.TCReapply( intf ) - def stop( self ): + def stop( self, deleteIntfs=True ): "Stop OpenFlow reference user datapath." self.cmd( 'kill %ofdatapath' ) self.cmd( 'kill %ofprotocol' ) - self.deleteIntfs() + if deleteIntfs: + self.deleteIntfs() class OVSLegacyKernelSwitch( Switch ): @@ -1031,11 +1032,12 @@ def start( self, controllers ): ' 1>' + ofplog + ' 2>' + ofplog + '&' ) self.execed = False - def stop( self ): + def stop( self, deleteIntfs=True ): "Terminate kernel datapath." quietRun( 'ovs-dpctl del-dp ' + self.dp ) self.cmd( 'kill %ovs-openflowd' ) - self.deleteIntfs() + if deleteIntfs: + self.deleteIntfs() class OVSSwitch( Switch ): @@ -1183,12 +1185,13 @@ def start( self, controllers ): self.TCReapply( intf ) - def stop( self ): + def stop( self, deleteIntfs=True ): "Terminate OVS switch." self.cmd( 'ovs-vsctl del-br', self ) if self.datapath == 'user': self.cmd( 'ip link del', self ) - self.deleteIntfs() + if deleteIntfs: + self.deleteIntfs() OVSKernelSwitch = OVSSwitch @@ -1205,7 +1208,7 @@ def start( self, controllers ): OVSSwitch.start( self, controllers=[] ) -class IVSSwitch(Switch): +class IVSSwitch( Switch ): """IVS virtual switch""" def __init__( self, name, verbose=False, **kwargs ): @@ -1251,11 +1254,12 @@ def start( self, controllers ): self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' ) - def stop( self ): + def stop( self, deleteIntfs=True ): "Terminate IVS switch." self.cmd( 'kill %ivs' ) self.cmd( 'wait' ) - self.deleteIntfs() + if deleteIntfs: + self.deleteIntfs() def attach( self, intf ): "Connect a data port"