Revision 6cb68f26

View differences:

bin/mn
26 26
from mininet.net import Mininet, MininetWithControlNet, VERSION
27 27
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
28 28
                           Ryu, NOX, RemoteController, findController,
29
                           DefaultController,
29
                           DefaultController, NullController,
30 30
                           UserSwitch, OVSSwitch, OVSBridge,
31 31
                           IVSSwitch )
32 32
from mininet.nodelib import LinuxBridge
33 33
from mininet.link import Link, TCLink, OVSLink
34
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
34
from mininet.topo import ( SingleSwitchTopo, LinearTopo,
35
                           SingleSwitchReversedTopo, MinimalTopo )
35 36
from mininet.topolib import TreeTopo, TorusTopo
36 37
from mininet.util import customClass, specialClass, splitArgs
37 38
from mininet.util import buildTopo
......
49 50

  
50 51
# built in topologies, created only when run
51 52
TOPODEF = 'minimal'
52
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
53
TOPOS = { 'minimal': MinimalTopo,
53 54
          'linear': LinearTopo,
54 55
          'reversed': SingleSwitchReversedTopo,
55 56
          'single': SingleSwitchTopo,
......
65 66
             'ivs': IVSSwitch,
66 67
             'lxbr': LinuxBridge,
67 68
             'default': OVSSwitch }
68
SWITCHESHELP = { 'user': 'OpenFlow reference user-space switch.',
69
                 'ovs': 'Open vSwitch OpenFlow-compatible switch.',
70
                 'ovsbr': 'Open vSwitch as an L2 MAC learning switch.',
71
                 'ovsk': 'Same as the ovs type.',
72
                 'ivs': 'Indigo Virtual Switch.',
73
                 'lxbr': 'Linux Bridge.',
74
                 'default': 'Open vSwitch OpenFlow-compatible switch.'}
75 69

  
76 70
HOSTDEF = 'proc'
77 71
HOSTS = { 'proc': Host,
......
79 73
          'cfs': specialClass( CPULimitedHost, defaults=dict( sched='cfs' ) ) }
80 74

  
81 75
CONTROLLERDEF = 'default'
76

  
82 77
CONTROLLERS = { 'ref': Controller,
83 78
                'ovsc': OVSController,
84 79
                'nox': NOX,
85 80
                'remote': RemoteController,
86 81
                'ryu': Ryu,
87 82
                'default': DefaultController,  # Note: replaced below
88
                'none': lambda name: None }
83
                'none': NullController }
89 84

  
90 85
LINKDEF = 'default'
91 86
LINKS = { 'default': Link,
......
103 98
                'iperfUDP': 'iperfUdp' }
104 99

  
105 100

  
106
def addDictOption( opts, choicesDict, default, name, helpDict=None, **kwargs ):
107
    """Convenience function to add choices dicts to OptionParser.          
108
       opts: OptionParser instance                                         
109
       choicesDict: dictionary of valid choices, must include default      
110
       default: default choice key                                         
111
       name: long option name                                              
112
       helpDict: dictionary describing choices
113
       kwargs: additional arguments to add_option"""                       
101
def addDictOption( opts, choicesDict, default, name, **kwargs ):
102
    """Convenience function to add choices dicts to OptionParser.
103
       opts: OptionParser instance
104
       choicesDict: dictionary of valid choices, must include default
105
       default: default choice key
106
       name: long option name
107
       kwargs: additional arguments to add_option"""
114 108
    helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
115 109
                '[,param=value...]' )
116
    if helpDict:
117
        helpList = [ k + "=" + helpDict[k] 
118
                     for k in sorted( helpDict.keys() ) ]
119
        helpStr += " " + ( ' '.join( helpList ) )
110
    helpList = [ '%s=%s' % ( k, v.__name__ )
111
                 for k, v in choicesDict.items() ]
112
    helpStr += ' ' + ( ' '.join( helpList ) )
120 113
    params = dict( type='string', default=default, help=helpStr )
121 114
    params.update( **kwargs )
122 115
    opts.add_option( '--' + name, **params )
......
202 195
                  '(type %prog -h for details)' )
203 196

  
204 197
        opts = OptionParser( description=desc, usage=usage )
205
        addDictOption( opts, SWITCHES, SWITCHDEF, 'switch', SWITCHESHELP )
198
        addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
206 199
        addDictOption( opts, HOSTS, HOSTDEF, 'host' )
207 200
        addDictOption( opts, CONTROLLERS, [], 'controller', action='append' )
208 201
        addDictOption( opts, LINKS, LINKDEF, 'link' )
mininet/node.py
906 906
           deleteIntfs: delete interfaces? (True)"""
907 907
        if deleteIntfs:
908 908
            self.deleteIntfs()
909
    
909

  
910 910
    def __repr__( self ):
911 911
        "More informative string representation"
912 912
        intfs = ( ','.join( [ '%s:%s' % ( i.name, i.IP() )
......
1517 1517
    if not controller:
1518 1518
        raise Exception( 'Could not find a default OpenFlow controller' )
1519 1519
    return controller( name, **kwargs )
1520

  
1521
def NullController( *_args, **_kwargs ):
1522
    "Nonexistent controller - simply returns None"
1523
    return None
mininet/topo.py
318 318
                          port1=0, port2=( k - h + 1 ) )
319 319

  
320 320

  
321
class MinimalTopo( SingleSwitchTopo ):
322
    "Minimal topology with two hosts and one switch"
323
    def build( self ):
324
        return SingleSwitchTopo.build( self, k=2 )
325

  
326

  
321 327
class LinearTopo( Topo ):
322 328
    "Linear topology of k switches, with n hosts per switch."
323 329

  

Also available in: Unified diff