@@ -19,7 +19,7 @@ import time
1919from mininet .clean import cleanup
2020from mininet .cli import CLI
2121from mininet .log import lg , LEVELS , info , warn
22- from mininet .net import Mininet
22+ from mininet .net import Mininet , MininetWithControlNet
2323from mininet .node import Host , CPULimitedHost , Controller , OVSController , NOX
2424from mininet .node import RemoteController , UserSwitch , OVSKernelSwitch
2525from mininet .link import Intf , TCIntf
@@ -32,20 +32,22 @@ def customNode( constructors, argStr ):
3232 "Return custom Node constructor based on argStr"
3333 cname , newargs , kwargs = splitArgs ( argStr )
3434 constructor = constructors .get ( cname , None )
35- #if args:
36- # raise Exception( "please specify keyword arguments for " + cname )
35+
3736 if not constructor :
3837 raise Exception ( "error: %s is unknown - please specify one of %s" %
3938 ( cname , constructors .keys () ) )
40- def custom ( name , * args , ** params ):
39+
40+ def customized ( name , * args , ** params ):
41+ "Customized Node constructor"
4142 params .update ( kwargs )
4243 if not newargs :
4344 return constructor ( name , * args , ** params )
4445 if args :
4546 warn ( 'warning: %s replacing %s with %s\n ' ,
4647 constructor , args , newargs )
4748 return constructor ( name , * newargs , ** params )
48- return custom
49+
50+ return customized
4951
5052
5153# built in topologies, created only when run
@@ -68,7 +70,7 @@ HOSTS = { 'proc': Host,
6870CONTROLLERDEF = 'ref'
6971CONTROLLERS = { 'ref' : Controller ,
7072 'ovsc' : OVSController ,
71- 'nox' : NOX ,
73+ 'nox' : NOX ,
7274 'remote' : RemoteController ,
7375 'none' : lambda name : None }
7476
@@ -94,8 +96,7 @@ def splitArgs( argstr ):
9496 params = split [ 1 : ]
9597 # Convert int and float args; removes the need for function
9698 # to be flexible with input arg formats.
97- args = [ s for s in params if '=' not in s ]
98- args = map ( makeNumeric , args )
99+ args = [ makeNumeric ( s ) for s in params if '=' not in s ]
99100 kwargs = {}
100101 for s in [ p for p in params if '=' in p ]:
101102 key , val = s .split ( '=' )
@@ -122,7 +123,8 @@ def addDictOption( opts, choicesDict, default, name, helpStr=None ):
122123 raise Exception ( 'Invalid default %s for choices dict: %s' %
123124 ( default , name ) )
124125 if not helpStr :
125- helpStr = '|' .join ( sorted ( choicesDict .keys () ) ) + '[,param=value...]'
126+ helpStr = ( '|' .join ( sorted ( choicesDict .keys () ) ) +
127+ '[,param=value...]' )
126128 opts .add_option ( '--' + name ,
127129 type = 'string' ,
128130 default = default ,
@@ -157,11 +159,11 @@ class MininetRunner( object ):
157159
158160 def parseCustomFile ( self , fileName ):
159161 "Parse custom file and add params before parsing cmd-line options."
160- custom = {}
162+ customs = {}
161163 if os .path .isfile ( fileName ):
162- execfile ( fileName , custom , custom )
163- for name in custom :
164- self .setCustom ( name , custom [ name ] )
164+ execfile ( fileName , customs , customs )
165+ for name , val in customs . iteritems () :
166+ self .setCustom ( name , val )
165167 else :
166168 raise Exception ( 'could not find custom file: %s' % fileName )
167169
@@ -171,8 +173,8 @@ class MininetRunner( object ):
171173 if '--custom' in sys .argv :
172174 index = sys .argv .index ( '--custom' )
173175 if len ( sys .argv ) > index + 1 :
174- custom = sys .argv [ index + 1 ]
175- self .parseCustomFile ( custom )
176+ filename = sys .argv [ index + 1 ]
177+ self .parseCustomFile ( filename )
176178 else :
177179 raise Exception ( 'Custom file name not found' )
178180
@@ -241,7 +243,7 @@ class MininetRunner( object ):
241243 start = time .time ()
242244
243245 topo = buildTopo ( self .options .topo )
244- switch = customNode ( SWITCHES , self .options .switch )
246+ switch = customNode ( SWITCHES , self .options .switch )
245247 host = customNode ( HOSTS , self .options .host )
246248 controller = customNode ( CONTROLLERS , self .options .controller )
247249 intf = customNode ( INTFS , self .options .intf )
@@ -250,20 +252,21 @@ class MininetRunner( object ):
250252 self .validate ( self .options )
251253
252254 inNamespace = self .options .innamespace
255+ Net = MininetWithControlNet if inNamespace else Mininet
253256 ipBase = self .options .ipbase
254257 xterms = self .options .xterms
255258 mac = self .options .mac
256259 arp = self .options .arp
257260 listenPort = None
258261 if not self .options .nolistenport :
259262 listenPort = self .options .listenport
260- mn = Mininet ( topo = topo ,
261- switch = switch , host = host , controller = controller ,
262- intf = intf ,
263- ipBase = ipBase ,
264- inNamespace = inNamespace ,
265- xterms = xterms , autoSetMacs = mac ,
266- autoStaticArp = arp , listenPort = listenPort )
263+ mn = Net ( topo = topo ,
264+ switch = switch , host = host , controller = controller ,
265+ intf = intf ,
266+ ipBase = ipBase ,
267+ inNamespace = inNamespace ,
268+ xterms = xterms , autoSetMacs = mac ,
269+ autoStaticArp = arp , listenPort = listenPort )
267270
268271 if self .options .pre :
269272 CLI ( mn , script = self .options .pre )
0 commit comments