Statistics
| Branch: | Tag: | Revision:

mininet / bin / mnclean @ 80be5642

History | View | Annotate | Download (1.83 KB)

1
#!/usr/bin/env python
2

    
3
"""
4
Mininet Cleanup
5
author: Bob Lantz (rlantz@cs.stanford.edu)
6

    
7
Unfortunately, Mininet and OpenFlow (and the Linux kernel)
8
don't always clean up properly after themselves. Until they do
9
(or until cleanup functionality is integrated into the Python
10
code), this script may be used to get rid of unwanted garbage.
11
It may also get rid of 'false positives', but hopefully
12
nothing irreplaceable!
13
"""
14

    
15
from subprocess import Popen, PIPE
16

    
17
from mininet.xterm import cleanUpScreens
18

    
19
def sh( cmd ):
20
    "Print a command and send it to the shell"
21
    print cmd
22
    return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
23

    
24
def cleanup():
25
    """Clean up junk which might be left over from old runs;
26
       do fast stuff before slow dp and link removal!"""
27
    print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
28
    zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
29
    zombies += 'udpbwtest'
30
    # Note: real zombie processes can't actually be killed, since they
31
    # are already (un)dead. Then again,
32
    # you can't connect to them either, so they're mostly harmless.
33
    sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
34

    
35
    print "*** Removing junk from /tmp"
36
    sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
37

    
38
    print "*** Removing old screen sessions"
39
    cleanUpScreens()
40

    
41
    print "*** Removing excess kernel datapaths"
42
    dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n' )
43
    for dp in dps:
44
        if dp != '':
45
            sh( 'dpctl deldp ' + dp )
46

    
47
    print "*** Removing all links of the pattern foo-ethX"
48
    links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
49
    for link in links:
50
        if link != '':
51
            sh( "ip link del " + link )
52

    
53
    print "*** Cleanup complete."
54

    
55
if __name__ == "__main__":
56
    cleanup()