Revision 125e6697

View differences:

bin/mn
96 96
                'iperfUDP': 'iperfUdp' }
97 97

  
98 98

  
99
def addDictOption( opts, choicesDict, default, name, helpStr=None ):
99
def addDictOption( opts, choicesDict, default, name, helpStr=None, **kwargs ):
100 100
    """Convenience function to add choices dicts to OptionParser.
101 101
       opts: OptionParser instance
102 102
       choicesDict: dictionary of valid choices, must include default
103 103
       default: default choice key
104 104
       name: long option name
105
       help: string"""
106
    if default not in choicesDict:
107
        raise Exception( 'Invalid  default %s for choices dict: %s' %
108
                         ( default, name ) )
105
       helpStr: help string
106
       kwargs: additional arguments to add_option"""
109 107
    if not helpStr:
110 108
        helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
111 109
                    '[,param=value...]' )
112
    opts.add_option( '--' + name,
113
                     type='string',
114
                     default = default,
115
                     help = helpStr )
116

  
110
    params = dict( type='string', default=default, help=helpStr )
111
    params.update( **kwargs )
112
    opts.add_option( '--' + name, **params )
117 113

  
118 114
def version( *_args ):
119 115
    "Print Mininet version and exit"
......
198 194
        opts = OptionParser( description=desc, usage=usage )
199 195
        addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
200 196
        addDictOption( opts, HOSTS, HOSTDEF, 'host' )
201
        addDictOption( opts, CONTROLLERS, CONTROLLERDEF, 'controller' )
197
        addDictOption( opts, CONTROLLERS, [], 'controller', action='append' )
202 198
        addDictOption( opts, LINKS, LINKDEF, 'link' )
203 199
        addDictOption( opts, TOPOS, TOPODEF, 'topo' )
204 200

  
......
292 288

  
293 289
        start = time.time()
294 290

  
295
        if self.options.controller == 'default':
291
        if not self.options.controller:
296 292
            # Update default based on available controllers
297 293
            CONTROLLERS[ 'default' ] = findController()
298
            if CONTROLLERS[ 'default' ] is None:
294
            self.options.controller = [ 'default' ]
295
            if not CONTROLLERS[ 'default' ]:
296
                self.options.controller = [ 'none' ]
299 297
                if self.options.switch == 'default':
300 298
                    info( '*** No default OpenFlow controller found '
301 299
                          'for default switch!\n' )
302 300
                    info( '*** Falling back to OVS Bridge\n' )
303 301
                    self.options.switch = 'ovsbr'
304
                    self.options.controller = 'none'
305
                elif self.options.switch in ( 'ovsbr', 'lxbr' ):
306
                    self.options.controller = 'none'
307
                else:
302
                elif self.options.switch not in ( 'ovsbr', 'lxbr' ):
308 303
                    raise Exception( "Could not find a default controller "
309 304
                                     "for switch %s" %
310 305
                                     self.options.switch )
......
312 307
        topo = buildTopo( TOPOS, self.options.topo )
313 308
        switch = customClass( SWITCHES, self.options.switch )
314 309
        host = customClass( HOSTS, self.options.host )
315
        controller = customClass( CONTROLLERS, self.options.controller )
310
        controller = [ customClass( CONTROLLERS, c )
311
                       for c in self.options.controller ]
316 312
        link = customClass( LINKS, self.options.link )
317 313

  
318 314
        if self.validate:
mininet/net.py
402 402
            if not isinstance( classes, list ):
403 403
                classes = [ classes ]
404 404
            for i, cls in enumerate( classes ):
405
                # Allow Controller objects because nobody understands currying
405
                # Allow Controller objects because nobody understands partial()
406 406
                if isinstance( cls, Controller ):
407 407
                    self.addController( cls )
408 408
                else:

Also available in: Unified diff