Revision 8f20b95d

View differences:

bin/mn_clean.py
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

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

  
25
def cleanUpScreens():
26
   "Remove moldy old screen sessions."      
27
   r = r'(\d+.[hsc]\d+)'
28
   output = sh( 'screen -ls' ).split( '\n' )
29
   for line in output:
30
      m = re.search( r, line )
31
      if m is not None:
32
         quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
33
 
34
def cleanup():
35
   """Clean up junk which might be left over from old runs;
36
      do fast stuff before slow dp and link removal!"""
37
      
38
   print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
39
   zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
40
   zombies += 'udpbwtest'
41
   # Note: real zombie processes can't actually be killed, since they 
42
   # are already (un)dead. Then again,
43
   # you can't connect to them either, so they're mostly harmless.
44
   sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
45

  
46
   print "*** Removing junk from /tmp"
47
   sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
48

  
49
   print "*** Removing old screen sessions"
50
   cleanUpScreens()
51

  
52
   print "*** Removing excess kernel datapaths"
53
   dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
54
   for dp in dps: 
55
      if dp != '': sh( 'dpctl deldp ' + dp )
56
      
57
   print "*** Removing all links of the pattern foo-ethX"
58
   links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
59
   for link in links: 
60
      if link != '': sh( "ip link del " + link )
61

  
62
   print "*** Cleanup complete."
63

  
64
if __name__ == "__main__":
65
   cleanup()
mininet/cleanup
1
#!/usr/bin/python
2

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

  
12
from subprocess import Popen, PIPE
13
import re
14

  
15
from mininet.util import quietRun
16

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

  
23
def cleanUpScreens():
24
   "Remove moldy old screen sessions."      
25
   r = r'(\d+.[hsc]\d+)'
26
   output = sh( 'screen -ls' ).split( '\n' )
27
   for line in output:
28
      m = re.search( r, line )
29
      if m is not None:
30
         quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
31
 
32
def cleanup():
33
   """Clean up junk which might be left over from old runs;
34
      do fast stuff before slow dp and link removal!"""
35
      
36
   print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
37
   zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
38
   zombies += 'udpbwtest'
39
   # Note: real zombie processes can't actually be killed, since they 
40
   # are already (un)dead. Then again,
41
   # you can't connect to them either, so they're mostly harmless.
42
   sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
43

  
44
   print "*** Removing junk from /tmp"
45
   sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
46

  
47
   print "*** Removing old screen sessions"
48
   cleanUpScreens()
49

  
50
   print "*** Removing excess kernel datapaths"
51
   dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
52
   for dp in dps: 
53
      if dp != '': sh( 'dpctl deldp ' + dp )
54
      
55
   print "*** Removing all links of the pattern foo-ethX"
56
   links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
57
   for link in links: 
58
      if link != '': sh( "ip link del " + link )
59

  
60
   print "*** Cleanup complete."
61

  
62
if __name__ == "__main__":
63
   cleanup()
mininet/net.py
1 1
#!/usr/bin/python
2
"""Mininet: A simple networking testbed for OpenFlow!
2 3

  
3
"""
4
Mininet: A simple networking testbed for OpenFlow!
4
@author Bob Lantz (rlantz@cs.stanford.edu)
5
@author Brandon Heller (brandonh@stanford.edu)
5 6

  
6 7
Mininet creates scalable OpenFlow test networks by using
7 8
process-based virtualization and network namespaces. 
......
16 17
   A parent shell (and possibly some child processes) in a namespace
17 18
   
18 19
Hosts have a network interface which is configured via ifconfig/ip
19
link/etc. with data network IP addresses (e.g. 192.168.123.2 )
20
link/etc.
20 21

  
21 22
This version supports both the kernel and user space datapaths
22 23
from the OpenFlow reference implementation.
......
43 44
   Switch nodes are named s0-sN
44 45
   Interfaces are named {nodename}-eth0 .. {nodename}-ethN,
45 46

  
46
Thoughts/TBD:
47

  
48
   It should be straightforward to add a function to read
49
   OpenFlowVMS spec files, but I haven't done so yet.
50
   For the moment, specifying configurations and tests in Python
51
   is straightforward and relatively concise.
52
   Soon, we may want to split the various subsystems (core,
53
   topology/network, cli, tests, etc.) into multiple modules.
54
   Currently nox support is in nox.py.
55
   We'd like to support OpenVSwitch as well as the reference
56
   implementation.
57
   
58
Bob Lantz
59
rlantz@cs.stanford.edu
60

  
61
History:
62
11/19/09 Initial revision (user datapath only)
63
11/19/09 Mininet demo at OpenFlow SWAI meeting
64
12/08/09 Kernel datapath support complete
65
12/09/09 Moved controller and switch routines into classes
66
12/12/09 Added subdivided network driver workflow
67
12/13/09 Added support for custom controller and switch classes
68 47
"""
69 48
import os
70 49
import re
71 50
from subprocess import call
72 51
import sys
73 52
from time import sleep
74
#flush = sys.stdout.flush
75
#import os, re, signal, sys, select
76 53

  
77
from mininet.logging_mod import lg, set_loglevel
78
from mininet.node import Host, Controller, Switch, ControllerParams
79
from mininet.topo import TreeTopo
54
from mininet.logging_mod import lg
80 55
from mininet.util import quietRun, fixLimits
81 56
from mininet.util import make_veth_pair, move_intf, retry, MOVEINTF_DELAY
82 57

  
......
517 492
            else:
518 493
                lg.error('CLI: unknown node or command: < %s >\n' % first)
519 494
            #lg.info('*** CLI: command complete\n')
520
        return 'exited by user command'
521

  
522

  
523
if __name__ == '__main__':
524
    if len(sys.argv) > 1:
525
        set_loglevel(sys.argv[1])
526
    else:
527
        set_loglevel('info')
528

  
529
    init()
530
    results = {}
531
    lg.info("*** Welcome to Mininet!\n")
532
    lg.info("*** Look in examples/ for more examples\n\n")
533
    lg.info("*** Testing Mininet with kernel and user datapath\n")
534
    for datapath in DATAPATHS:
535
        k = datapath == 'kernel'
536
        controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
537
        mn = Mininet(TreeTopo(), Switch, Host, Controller,
538
                         controller_params)
539
        mn.start()
540
        dropped = mn.ping_test()
541
        results[datapath] = "%i%% dropped" % dropped
542
        mn.stop()
543

  
544
    lg.info("*** Test results: %s\n", results)
495
        return 'exited by user command'
setup.py
2 2
'''Setuptools params'''
3 3

  
4 4
from setuptools import setup, find_packages
5
from os.path import join
6

  
7
scripts = [join('bin', filename) for filename in
8
            ['mn_run.py', 'mn_clean.py']]
9

  
10
modname = distname = 'mininet'
5 11

  
6 12
setup(
7
    name='mininet',
13
    name=distname,
8 14
    version='0.0.0',
9
    description='The OpenFlow-based data center network',
15
    description='Process-based OpenFlow emulator',
10 16
    author='Bob Lantz',
11 17
    author_email='rlantz@cs.stanford.edu',
12 18
    packages=find_packages(exclude='test'),
13 19
    long_description="""\
14 20
Insert longer description here.
15 21
      """,
16
      classifiers=[
22
    classifiers=[
17 23
          "License :: OSI Approved :: GNU General Public License (GPL)",
18 24
          "Programming Language :: Python",
19 25
          "Development Status :: 4 - Beta",
20 26
          "Intended Audience :: Developers",
21 27
          "Topic :: Internet",
22
      ],
23
      keywords='networking protocol Internet OpenFlow',
24
      license='GPL',
25
      install_requires=[
28
    ],
29
    keywords='networking protocol Internet OpenFlow',
30
    license='GPL',
31
    install_requires=[
26 32
        'setuptools'
27
      ])
33
    ],
34
    scripts=scripts,
35
    package_dir={modname:''})

Also available in: Unified diff