Fix codecheck and MininetWithControlNet.

This commit is contained in:
Bob Lantz
2012-03-10 20:44:34 -08:00
parent 1d814c606d
commit 14ff3ad3d0
11 changed files with 292 additions and 239 deletions
+26 -23
View File
@@ -19,7 +19,7 @@ import time
from mininet.clean import cleanup
from mininet.cli import CLI
from mininet.log import lg, LEVELS, info, warn
from mininet.net import Mininet
from mininet.net import Mininet, MininetWithControlNet
from mininet.node import Host, CPULimitedHost, Controller, OVSController, NOX
from mininet.node import RemoteController, UserSwitch, OVSKernelSwitch
from mininet.link import Intf, TCIntf
@@ -32,12 +32,13 @@ def customNode( constructors, argStr ):
"Return custom Node constructor based on argStr"
cname, newargs, kwargs = splitArgs( argStr )
constructor = constructors.get( cname, None )
#if args:
# raise Exception( "please specify keyword arguments for " + cname )
if not constructor:
raise Exception( "error: %s is unknown - please specify one of %s" %
( cname, constructors.keys() ) )
def custom( name, *args, **params ):
def customized( name, *args, **params ):
"Customized Node constructor"
params.update( kwargs )
if not newargs:
return constructor( name, *args, **params )
@@ -45,7 +46,8 @@ def customNode( constructors, argStr ):
warn( 'warning: %s replacing %s with %s\n',
constructor, args, newargs )
return constructor( name, *newargs, **params )
return custom
return customized
# built in topologies, created only when run
@@ -68,7 +70,7 @@ HOSTS = { 'proc': Host,
CONTROLLERDEF = 'ref'
CONTROLLERS = { 'ref': Controller,
'ovsc': OVSController,
'nox': NOX,
'nox': NOX,
'remote': RemoteController,
'none': lambda name: None }
@@ -94,8 +96,7 @@ def splitArgs( argstr ):
params = split[ 1: ]
# Convert int and float args; removes the need for function
# to be flexible with input arg formats.
args = [ s for s in params if '=' not in s ]
args = map( makeNumeric, args )
args = [ makeNumeric( s ) for s in params if '=' not in s ]
kwargs = {}
for s in [ p for p in params if '=' in p ]:
key, val = s.split( '=' )
@@ -122,7 +123,8 @@ def addDictOption( opts, choicesDict, default, name, helpStr=None ):
raise Exception( 'Invalid default %s for choices dict: %s' %
( default, name ) )
if not helpStr:
helpStr = '|'.join( sorted( choicesDict.keys() ) ) + '[,param=value...]'
helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
'[,param=value...]' )
opts.add_option( '--' + name,
type='string',
default = default,
@@ -157,11 +159,11 @@ class MininetRunner( object ):
def parseCustomFile( self, fileName ):
"Parse custom file and add params before parsing cmd-line options."
custom = {}
customs = {}
if os.path.isfile( fileName ):
execfile( fileName, custom, custom )
for name in custom:
self.setCustom( name, custom[ name ] )
execfile( fileName, customs, customs )
for name, val in customs.iteritems():
self.setCustom( name, val )
else:
raise Exception( 'could not find custom file: %s' % fileName )
@@ -171,8 +173,8 @@ class MininetRunner( object ):
if '--custom' in sys.argv:
index = sys.argv.index( '--custom' )
if len( sys.argv ) > index + 1:
custom = sys.argv[ index + 1 ]
self.parseCustomFile( custom )
filename = sys.argv[ index + 1 ]
self.parseCustomFile( filename )
else:
raise Exception( 'Custom file name not found' )
@@ -241,7 +243,7 @@ class MininetRunner( object ):
start = time.time()
topo = buildTopo( self.options.topo )
switch = customNode( SWITCHES, self.options.switch )
switch = customNode( SWITCHES, self.options.switch )
host = customNode( HOSTS, self.options.host )
controller = customNode( CONTROLLERS, self.options.controller )
intf = customNode( INTFS, self.options.intf )
@@ -250,6 +252,7 @@ class MininetRunner( object ):
self.validate( self.options )
inNamespace = self.options.innamespace
Net = MininetWithControlNet if inNamespace else Mininet
ipBase = self.options.ipbase
xterms = self.options.xterms
mac = self.options.mac
@@ -257,13 +260,13 @@ class MininetRunner( object ):
listenPort = None
if not self.options.nolistenport:
listenPort = self.options.listenport
mn = Mininet( topo=topo,
switch=switch, host=host, controller=controller,
intf=intf,
ipBase=ipBase,
inNamespace=inNamespace,
xterms=xterms, autoSetMacs=mac,
autoStaticArp=arp, listenPort=listenPort )
mn = Net( topo=topo,
switch=switch, host=host, controller=controller,
intf=intf,
ipBase=ipBase,
inNamespace=inNamespace,
xterms=xterms, autoSetMacs=mac,
autoStaticArp=arp, listenPort=listenPort )
if self.options.pre:
CLI( mn, script=self.options.pre )