Munged mn and mnclean into mininet style.

This commit is contained in:
Bob Lantz
2010-02-08 15:42:31 -08:00
parent 7c371cf32a
commit 8895862acf
2 changed files with 130 additions and 133 deletions
Executable → Regular
+12 -14
View File
@@ -1,7 +1,8 @@
#!/usr/bin/env python
"""Mininet Cleanup
@author Bob Lantz (rlantz@cs.stanford.edu)
"""
Mininet Cleanup
author: Bob Lantz (rlantz@cs.stanford.edu)
Unfortunately, Mininet and OpenFlow don't always clean up
properly after themselves. Until they do (or until cleanup
@@ -15,42 +16,39 @@ from subprocess import Popen, PIPE
from mininet.xterm import cleanUpScreens
def sh(cmd):
def sh( cmd ):
"Print a command and send it to the shell"
print cmd
return Popen(['/bin/sh', '-c', cmd], stdout=PIPE).communicate()[0]
return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
def cleanup():
"""Clean up junk which might be left over from old runs;
do fast stuff before slow dp and link removal!"""
print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
zombies += 'udpbwtest'
# Note: real zombie processes can't actually be killed, since they
# are already (un)dead. Then again,
# are already ( un )dead. Then again,
# 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"
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"
cleanUpScreens()
print "*** Removing excess kernel datapaths"
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:
if dp != '':
sh('dpctl deldp ' + dp)
sh( 'dpctl deldp ' + dp )
print "*** Removing all links of the pattern foo-ethX"
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:
if link != '':
sh("ip link del " + link)
sh( "ip link del " + link )
print "*** Cleanup complete."