Skip to content

Commit 14ff3ad

Browse files
committed
Fix codecheck and MininetWithControlNet.
1 parent 1d814c6 commit 14ff3ad

11 files changed

Lines changed: 290 additions & 237 deletions

File tree

bin/mn

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import time
1919
from mininet.clean import cleanup
2020
from mininet.cli import CLI
2121
from mininet.log import lg, LEVELS, info, warn
22-
from mininet.net import Mininet
22+
from mininet.net import Mininet, MininetWithControlNet
2323
from mininet.node import Host, CPULimitedHost, Controller, OVSController, NOX
2424
from mininet.node import RemoteController, UserSwitch, OVSKernelSwitch
2525
from 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,
6870
CONTROLLERDEF = 'ref'
6971
CONTROLLERS = { '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 )

examples/consoles.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def append( self, text ):
107107
self.text.insert( 'end', text )
108108
self.text.mark_set( 'insert', 'end' )
109109
self.text.see( 'insert' )
110-
outputHook = lambda x,y: True # make pylint happy
110+
outputHook = lambda x, y: True # make pylint happier
111111
if self.outputHook:
112112
outputHook = self.outputHook
113113
outputHook( self, text )
@@ -132,27 +132,22 @@ def handleReturn( self, event ):
132132
self.sendCmd( cmd )
133133

134134
# Callback ignores event
135-
# pylint: disable-msg=W0613
136-
def handleInt( self, event=None ):
135+
def handleInt( self, _event=None ):
137136
"Handle control-c."
138137
self.node.sendInt()
139-
# pylint: enable-msg=W0613
140138

141139
def sendCmd( self, cmd ):
142140
"Send a command to our node."
143141
if not self.node.waiting:
144142
self.node.sendCmd( cmd )
145143

146-
# Callback ignores fds
147-
# pylint: disable-msg=W0613
148-
def handleReadable( self, fds, timeoutms=None ):
144+
def handleReadable( self, _fds, timeoutms=None ):
149145
"Handle file readable event."
150146
data = self.node.monitor( timeoutms )
151147
self.append( data )
152148
if not self.node.waiting:
153149
# Print prompt
154150
self.append( self.prompt )
155-
# pylint: enable-msg=W0613
156151

157152
def waiting( self ):
158153
"Are we waiting for output?"
@@ -321,9 +316,7 @@ def __init__( self, net, parent=None, width=4 ):
321316

322317
self.pack( expand=True, fill='both' )
323318

324-
# Update callback doesn't use console arg
325-
# pylint: disable-msg=W0613
326-
def updateGraph( self, console, output ):
319+
def updateGraph( self, _console, output ):
327320
"Update our graph."
328321
m = re.search( r'(\d+) Mbits/sec', output )
329322
if not m:
@@ -334,7 +327,6 @@ def updateGraph( self, console, output ):
334327
self.graph.addBar( self.bw )
335328
self.bw = 0
336329
self.updates = 0
337-
# pylint: enable-msg=W0613
338330

339331
def setOutputHook( self, fn=None, consoles=None ):
340332
"Register fn as output hook [on specific consoles.]"

examples/limit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
from time import sleep
1414

1515
def testLinkLimit( net, bw ):
16+
"Run bandwidth limit test"
1617
print '*** Testing network %.2f Mbps bandwidth limit' % bw
1718
net.iperf( )
1819

1920
def testCpuLimit( net, cpu ):
21+
"run CPU limit test"
2022
pct = cpu * 100
2123
print '*** Testing CPU %.0f%% bandwidth limit' % pct
2224
h1, h2 = net.hosts
@@ -25,8 +27,9 @@ def testCpuLimit( net, cpu ):
2527
pid1 = h1.cmd( 'echo $!' ).strip()
2628
pid2 = h2.cmd( 'echo $!' ).strip()
2729
cmd = 'ps -p %s,%s -o pid,%%cpu,args' % ( pid1, pid2 )
28-
for i in range( 0, 5):
29-
sleep( 1 )
30+
# It's a shame that this is what pylint prefers
31+
for _ in range( 5 ):
32+
sleep( 1 )
3033
print quietRun( cmd ).strip()
3134
h1.cmd( 'kill %1')
3235
h2.cmd( 'kill %1')

examples/miniedit.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,11 @@ def deleteItem( self, item ):
299299
# Delete from view
300300
self.canvas.delete( item )
301301

302-
# Callback ignores event
303-
# pylint: disable-msg=W0613
304-
def deleteSelection( self, event ):
302+
def deleteSelection( self, _event ):
305303
"Delete the selected item."
306304
if self.selection is not None:
307305
self.deleteItem( self.selection )
308306
self.selectItem( None )
309-
# pylint: enable-msg=W0613
310307

311308
def nodeIcon( self, node, name ):
312309
"Create a new node icon."
@@ -350,14 +347,11 @@ def dragLink( self, event ):
350347
c = self.canvas
351348
c.coords( self.link, self.linkx, self.linky, x, y )
352349

353-
# Callback ignores event
354-
# pylint: disable-msg=W0613
355-
def releaseLink( self, event ):
350+
def releaseLink( self, _event ):
356351
"Give up on the current link."
357352
if self.link is not None:
358353
self.canvas.delete( self.link )
359354
self.linkWidget = self.linkItem = self.link = None
360-
# pylint: enable-msg=W0613
361355

362356
# Generic node handlers
363357

@@ -385,12 +379,9 @@ def enterNode( self, event ):
385379
"Select node on entry."
386380
self.selectNode( event )
387381

388-
# Callback ignores event
389-
# pylint: disable-msg=W0613
390-
def leaveNode( self, event ):
382+
def leaveNode( self, _event ):
391383
"Restore old selection on exit."
392384
self.selectItem( self.lastSelection )
393-
# pylint: enable-msg=W0613
394385

395386
def clickNode( self, event ):
396387
"Node click handler."
@@ -454,23 +445,21 @@ def startLink( self, event ):
454445
# Link bindings
455446
# Selection still needs a bit of work overall
456447
# Callbacks ignore event
457-
# pylint: disable-msg=W0613
458448

459-
def select( event, link=self.link ):
449+
def select( _event, link=self.link ):
460450
"Select item on mouse entry."
461451
self.selectItem( link )
462452

463-
def highlight( event, link=self.link ):
453+
def highlight( _event, link=self.link ):
464454
"Highlight item on mouse entry."
465455
# self.selectItem( link )
466456
self.canvas.itemconfig( link, fill='green' )
467457

468-
def unhighlight( event, link=self.link ):
458+
def unhighlight( _event, link=self.link ):
469459
"Unhighlight item on mouse exit."
470460
self.canvas.itemconfig( link, fill='blue' )
471461
# self.selectItem( None )
472462

473-
# pylint: disable-msg=W0613
474463
self.canvas.tag_bind( self.link, '<Enter>', highlight )
475464
self.canvas.tag_bind( self.link, '<Leave>', unhighlight )
476465
self.canvas.tag_bind( self.link, '<ButtonPress-1>', select )
@@ -602,7 +591,7 @@ def stop( self ):
602591
cleanUpScreens()
603592
self.net = None
604593

605-
def xterm( self, ignore=None ):
594+
def xterm( self, _=None ):
606595
"Make an xterm when a button is pressed."
607596
if ( self.selection is None or
608597
self.net is None or

examples/scratchnetuser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
5252
info( '*** Starting controller and user datapath\n' )
5353
controller.cmd( cname + ' ' + cargs + '&' )
5454
switch.cmd( 'ifconfig lo 127.0.0.1' )
55-
intfs = map( str, [ sintf1, sintf2 ] )
55+
intfs = [ str( i ) for i in sintf1, sintf2 ]
5656
switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
5757
switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
5858

mininet/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def emptyline( self ):
7777
# Disable pylint "Unused argument: 'arg's'" messages, as well as
7878
# "method could be a function" warning, since each CLI function
7979
# must have the same interface
80-
# pylint: disable-msg=W0613,R0201
80+
# pylint: disable-msg=R0201
8181

8282
helpStr = (
8383
'You may also send a command to a node using:\n'
@@ -104,12 +104,12 @@ def do_help( self, line ):
104104
if line is '':
105105
output( self.helpStr )
106106

107-
def do_nodes( self, line ):
107+
def do_nodes( self, _line ):
108108
"List all nodes."
109109
nodes = ' '.join( [ node.name for node in sorted( self.nodelist ) ] )
110110
output( 'available nodes are: \n%s\n' % nodes )
111111

112-
def do_net( self, line ):
112+
def do_net( self, _line ):
113113
"List network connections."
114114
for switch in self.mn.switches:
115115
output( switch.name, '<->' )
@@ -143,11 +143,11 @@ def do_py( self, line ):
143143

144144
# pylint: enable-msg=W0703
145145

146-
def do_pingall( self, line ):
146+
def do_pingall( self, _line ):
147147
"Ping between all hosts."
148148
self.mn.pingAll()
149149

150-
def do_pingpair( self, line ):
150+
def do_pingpair( self, _line ):
151151
"Ping between first two hosts, useful for testing."
152152
self.mn.pingPair()
153153

@@ -191,13 +191,13 @@ def do_iperfudp( self, line ):
191191
error( 'invalid number of args: iperfudp bw src dst\n' +
192192
'bw examples: 10M\n' )
193193

194-
def do_intfs( self, line ):
194+
def do_intfs( self, _line ):
195195
"List interfaces."
196196
for node in self.nodelist:
197197
output( '%s: %s\n' %
198198
( node.name, ' '.join( sorted( node.intfs.values() ) ) ) )
199199

200-
def do_dump( self, line ):
200+
def do_dump( self, _line ):
201201
"Dump node info."
202202
for node in self.nodelist:
203203
output( '%s\n' % node )
@@ -229,7 +229,7 @@ def do_gterm( self, line ):
229229
"Spawn gnome-terminal(s) for the given node(s)."
230230
self.do_xterm( line, term='gterm' )
231231

232-
def do_exit( self, line ):
232+
def do_exit( self, _line ):
233233
"Exit"
234234
return 'exited by user command'
235235

@@ -311,7 +311,7 @@ def default( self, line ):
311311
else:
312312
error( '*** Unknown command: %s\n' % first )
313313

314-
# pylint: enable-msg=W0613,R0201
314+
# pylint: enable-msg=R0201
315315

316316
def waitForNode( self, node ):
317317
"Wait for a node to finish, and print its output."

0 commit comments

Comments
 (0)