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