mininet / bin / mn_clean.py @ 60d9ead6
History | View | Annotate | Download (1.82 KB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
"""Mininet Cleanup
|
3 |
|
4 |
@author Bob Lantz (rlantz@cs.stanford.edu)
|
5 |
|
6 |
Unfortunately, Mininet and OpenFlow don't always clean up
|
7 |
properly after themselves. Until they do (or until cleanup
|
8 |
functionality is integrated into the python code), this
|
9 |
script may be used to get rid of unwanted garbage. It may
|
10 |
also get rid of 'false positives', but hopefully nothing
|
11 |
irreplaceable!
|
12 |
"""
|
13 |
|
14 |
from subprocess import Popen, PIPE |
15 |
import re |
16 |
|
17 |
from mininet.util import quietRun |
18 |
from mininet.xterm import cleanUpScreens |
19 |
|
20 |
def sh( cmd ): |
21 |
"Print a command and send it to the shell"
|
22 |
print cmd
|
23 |
return Popen( [ '/bin/sh', '-c', cmd ], |
24 |
stdout=PIPE ).communicate()[ 0 ]
|
25 |
|
26 |
|
27 |
def cleanup(): |
28 |
"""Clean up junk which might be left over from old runs;
|
29 |
do fast stuff before slow dp and link removal!"""
|
30 |
|
31 |
print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes" |
32 |
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
33 |
zombies += 'udpbwtest'
|
34 |
# Note: real zombie processes can't actually be killed, since they
|
35 |
# are already (un)dead. Then again,
|
36 |
# you can't connect to them either, so they're mostly harmless.
|
37 |
sh( 'killall -9 ' + zombies + ' 2> /dev/null' ) |
38 |
|
39 |
print "*** Removing junk from /tmp" |
40 |
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
41 |
|
42 |
print "*** Removing old screen sessions" |
43 |
cleanUpScreens() |
44 |
|
45 |
print "*** Removing excess kernel datapaths" |
46 |
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n') |
47 |
for dp in dps: |
48 |
if dp != '': sh( 'dpctl deldp ' + dp ) |
49 |
|
50 |
print "*** Removing all links of the pattern foo-ethX" |
51 |
links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' ) |
52 |
for link in links: |
53 |
if link != '': sh( "ip link del " + link ) |
54 |
|
55 |
print "*** Cleanup complete." |
56 |
|
57 |
if __name__ == "__main__": |
58 |
cleanup() |