Make cleanup a param of mn, not a separate script
Also switch from print to info statements, to enable a non-verbose clean. Instead of 'mnclean', now run 'mn -c'.
This commit is contained in:
@@ -16,6 +16,7 @@ import os.path
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from mininet.clean import cleanup
|
||||||
from mininet.log import lg, LEVELS, info
|
from mininet.log import lg, LEVELS, info
|
||||||
from mininet.net import Mininet, init
|
from mininet.net import Mininet, init
|
||||||
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
||||||
@@ -144,6 +145,8 @@ class MininetRunner( object ):
|
|||||||
opts.add_option( '--topo', type='string', default=TOPODEF,
|
opts.add_option( '--topo', type='string', default=TOPODEF,
|
||||||
help='[' + ' '.join( TOPOS.keys() ) + '],arg1,arg2,'
|
help='[' + ' '.join( TOPOS.keys() ) + '],arg1,arg2,'
|
||||||
'...argN')
|
'...argN')
|
||||||
|
opts.add_option( '--clean', '-c', action='store_true',
|
||||||
|
default=False, help='clean and exit' )
|
||||||
opts.add_option( '--custom', type='string', default=None,
|
opts.add_option( '--custom', type='string', default=None,
|
||||||
help='read custom topo and node params from .py file' )
|
help='read custom topo and node params from .py file' )
|
||||||
opts.add_option( '--test', type='choice', choices=TESTS,
|
opts.add_option( '--test', type='choice', choices=TESTS,
|
||||||
@@ -184,6 +187,10 @@ class MininetRunner( object ):
|
|||||||
def begin( self ):
|
def begin( self ):
|
||||||
"Create and run mininet."
|
"Create and run mininet."
|
||||||
|
|
||||||
|
if self.options.clean:
|
||||||
|
cleanup()
|
||||||
|
exit()
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
topo = buildTopo( self.options.topo )
|
topo = buildTopo( self.options.topo )
|
||||||
|
|||||||
Executable → Regular
+9
-10
@@ -14,17 +14,19 @@ nothing irreplaceable!
|
|||||||
|
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
from mininet.log import info
|
||||||
from mininet.xterm import cleanUpScreens
|
from mininet.xterm import cleanUpScreens
|
||||||
|
|
||||||
def sh( cmd ):
|
def sh( cmd ):
|
||||||
"Print a command and send it to the shell"
|
"Print a command and send it to the shell"
|
||||||
print cmd
|
info( cmd + '\n' )
|
||||||
return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
|
return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
|
||||||
|
|
||||||
def cleanup():
|
def cleanup():
|
||||||
"""Clean up junk which might be left over from old runs;
|
"""Clean up junk which might be left over from old runs;
|
||||||
do fast stuff before slow dp and link removal!"""
|
do fast stuff before slow dp and link removal!"""
|
||||||
print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
|
info("*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
|
||||||
|
"\n")
|
||||||
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
||||||
zombies += 'udpbwtest'
|
zombies += 'udpbwtest'
|
||||||
# Note: real zombie processes can't actually be killed, since they
|
# Note: real zombie processes can't actually be killed, since they
|
||||||
@@ -32,25 +34,22 @@ def cleanup():
|
|||||||
# you can't connect to them either, so they're mostly harmless.
|
# you can't connect to them either, so they're mostly harmless.
|
||||||
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
||||||
|
|
||||||
print "*** Removing junk from /tmp"
|
info("*** Removing junk from /tmp\n")
|
||||||
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
||||||
|
|
||||||
print "*** Removing old screen sessions"
|
info("*** Removing old screen sessions")
|
||||||
cleanUpScreens()
|
cleanUpScreens()
|
||||||
|
|
||||||
print "*** Removing excess kernel datapaths"
|
info("*** Removing excess kernel datapaths\n")
|
||||||
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n' )
|
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n' )
|
||||||
for dp in dps:
|
for dp in dps:
|
||||||
if dp != '':
|
if dp != '':
|
||||||
sh( 'dpctl deldp ' + dp )
|
sh( 'dpctl deldp ' + dp )
|
||||||
|
|
||||||
print "*** Removing all links of the pattern foo-ethX"
|
info("*** Removing all links of the pattern foo-ethX\n")
|
||||||
links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
|
links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
|
||||||
for link in links:
|
for link in links:
|
||||||
if link != '':
|
if link != '':
|
||||||
sh( "ip link del " + link )
|
sh( "ip link del " + link )
|
||||||
|
|
||||||
print "*** Cleanup complete."
|
info("*** Cleanup complete.\n")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
cleanup()
|
|
||||||
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
|||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
scripts = [join('bin', filename) for filename in
|
scripts = [join('bin', filename) for filename in
|
||||||
['mn', 'mnclean']]
|
['mn']]
|
||||||
|
|
||||||
modname = distname = 'mininet'
|
modname = distname = 'mininet'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user