Support multiple --controller arguments
This commit is contained in:
@@ -96,24 +96,20 @@ ALTSPELLING = { 'pingall': 'pingAll',
|
|||||||
'iperfUDP': 'iperfUdp' }
|
'iperfUDP': 'iperfUdp' }
|
||||||
|
|
||||||
|
|
||||||
def addDictOption( opts, choicesDict, default, name, helpStr=None ):
|
def addDictOption( opts, choicesDict, default, name, helpStr=None, **kwargs ):
|
||||||
"""Convenience function to add choices dicts to OptionParser.
|
"""Convenience function to add choices dicts to OptionParser.
|
||||||
opts: OptionParser instance
|
opts: OptionParser instance
|
||||||
choicesDict: dictionary of valid choices, must include default
|
choicesDict: dictionary of valid choices, must include default
|
||||||
default: default choice key
|
default: default choice key
|
||||||
name: long option name
|
name: long option name
|
||||||
help: string"""
|
helpStr: help string
|
||||||
if default not in choicesDict:
|
kwargs: additional arguments to add_option"""
|
||||||
raise Exception( 'Invalid default %s for choices dict: %s' %
|
|
||||||
( default, name ) )
|
|
||||||
if not helpStr:
|
if not helpStr:
|
||||||
helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
|
helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
|
||||||
'[,param=value...]' )
|
'[,param=value...]' )
|
||||||
opts.add_option( '--' + name,
|
params = dict( type='string', default=default, help=helpStr )
|
||||||
type='string',
|
params.update( **kwargs )
|
||||||
default = default,
|
opts.add_option( '--' + name, **params )
|
||||||
help = helpStr )
|
|
||||||
|
|
||||||
|
|
||||||
def version( *_args ):
|
def version( *_args ):
|
||||||
"Print Mininet version and exit"
|
"Print Mininet version and exit"
|
||||||
@@ -198,7 +194,7 @@ class MininetRunner( object ):
|
|||||||
opts = OptionParser( description=desc, usage=usage )
|
opts = OptionParser( description=desc, usage=usage )
|
||||||
addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
|
addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
|
||||||
addDictOption( opts, HOSTS, HOSTDEF, 'host' )
|
addDictOption( opts, HOSTS, HOSTDEF, 'host' )
|
||||||
addDictOption( opts, CONTROLLERS, CONTROLLERDEF, 'controller' )
|
addDictOption( opts, CONTROLLERS, [], 'controller', action='append' )
|
||||||
addDictOption( opts, LINKS, LINKDEF, 'link' )
|
addDictOption( opts, LINKS, LINKDEF, 'link' )
|
||||||
addDictOption( opts, TOPOS, TOPODEF, 'topo' )
|
addDictOption( opts, TOPOS, TOPODEF, 'topo' )
|
||||||
|
|
||||||
@@ -292,19 +288,18 @@ class MininetRunner( object ):
|
|||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
if self.options.controller == 'default':
|
if not self.options.controller:
|
||||||
# Update default based on available controllers
|
# Update default based on available controllers
|
||||||
CONTROLLERS[ 'default' ] = findController()
|
CONTROLLERS[ 'default' ] = findController()
|
||||||
if CONTROLLERS[ 'default' ] is None:
|
self.options.controller = [ 'default' ]
|
||||||
|
if not CONTROLLERS[ 'default' ]:
|
||||||
|
self.options.controller = [ 'none' ]
|
||||||
if self.options.switch == 'default':
|
if self.options.switch == 'default':
|
||||||
info( '*** No default OpenFlow controller found '
|
info( '*** No default OpenFlow controller found '
|
||||||
'for default switch!\n' )
|
'for default switch!\n' )
|
||||||
info( '*** Falling back to OVS Bridge\n' )
|
info( '*** Falling back to OVS Bridge\n' )
|
||||||
self.options.switch = 'ovsbr'
|
self.options.switch = 'ovsbr'
|
||||||
self.options.controller = 'none'
|
elif self.options.switch not in ( 'ovsbr', 'lxbr' ):
|
||||||
elif self.options.switch in ( 'ovsbr', 'lxbr' ):
|
|
||||||
self.options.controller = 'none'
|
|
||||||
else:
|
|
||||||
raise Exception( "Could not find a default controller "
|
raise Exception( "Could not find a default controller "
|
||||||
"for switch %s" %
|
"for switch %s" %
|
||||||
self.options.switch )
|
self.options.switch )
|
||||||
@@ -312,7 +307,8 @@ class MininetRunner( object ):
|
|||||||
topo = buildTopo( TOPOS, self.options.topo )
|
topo = buildTopo( TOPOS, self.options.topo )
|
||||||
switch = customClass( SWITCHES, self.options.switch )
|
switch = customClass( SWITCHES, self.options.switch )
|
||||||
host = customClass( HOSTS, self.options.host )
|
host = customClass( HOSTS, self.options.host )
|
||||||
controller = customClass( CONTROLLERS, self.options.controller )
|
controller = [ customClass( CONTROLLERS, c )
|
||||||
|
for c in self.options.controller ]
|
||||||
link = customClass( LINKS, self.options.link )
|
link = customClass( LINKS, self.options.link )
|
||||||
|
|
||||||
if self.validate:
|
if self.validate:
|
||||||
|
|||||||
+1
-1
@@ -402,7 +402,7 @@ class Mininet( object ):
|
|||||||
if not isinstance( classes, list ):
|
if not isinstance( classes, list ):
|
||||||
classes = [ classes ]
|
classes = [ classes ]
|
||||||
for i, cls in enumerate( classes ):
|
for i, cls in enumerate( classes ):
|
||||||
# Allow Controller objects because nobody understands currying
|
# Allow Controller objects because nobody understands partial()
|
||||||
if isinstance( cls, Controller ):
|
if isinstance( cls, Controller ):
|
||||||
self.addController( cls )
|
self.addController( cls )
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user