Revision 49654212

View differences:

bin/mn
25 25
from mininet.log import lg, LEVELS, info, debug, warn, error
26 26
from mininet.net import Mininet, MininetWithControlNet, VERSION
27 27
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
28
                           RYU, NOX, RemoteController, findController, DefaultController,
28
                           RYU, NOX, RemoteController, findController,
29
                           DefaultController,
29 30
                           UserSwitch, OVSSwitch, OVSBridge,
30 31
                           OVSLegacyKernelSwitch, IVSSwitch )
31 32
from mininet.nodelib import LinuxBridge
......
132 133
        self.setup()
133 134
        self.begin()
134 135

  
135
    def custom( self, option, opt_str, value, parser ):
136
    def custom( self, _option, _opt_str, value, _parser ):
136 137
        """Parse custom file and add params.
137 138
           option: option e.g. --custom
138 139
           opt_str: option string e.g. --custom
......
168 169
            # Add or modify global variable or class
169 170
            globals()[ name ] = value
170 171

  
171
    def setNat( self, option, opt_str, value, parser ):
172
    def setNat( self, _option, opt_str, value, parser ):
173
        "Set NAT option(s)"
174
        assert self  # satisfy pylint
172 175
        parser.values.nat = True
173
        if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-': #first arg, first char != '-'
176
        # first arg, first char != '-'
177
        if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-':
174 178
            value = parser.rargs.pop( 0 )
175 179
            _, args, kwargs = splitArgs( opt_str + ',' + value )
176 180
            parser.values.nat_args = args
......
201 205
                         default=False, help='clean and exit' )
202 206
        opts.add_option( '--custom', action='callback',
203 207
                         callback=self.custom,
204
                         type='string', help='read custom classes or params from .py file(s)' )
208
                         type='string',
209
                         help='read custom classes or params from .py file(s)' )
205 210
        opts.add_option( '--test', type='choice', choices=TESTS,
206 211
                         default=TESTS[ 0 ],
207 212
                         help='|'.join( TESTS ) )
......
231 236
                         default=False, help="pin hosts to CPU cores "
232 237
                         "(requires --host cfs or --host rt)" )
233 238
        opts.add_option( '--nat', action='callback', callback=self.setNat,
234
                         help="adds a NAT to the topology that connects Mininet hosts"
235
                         " to the physical network."
236
                         " Warning: This may route any traffic on the machine that uses Mininet's"
237
                         " IP subnet into the Mininet network. If you need to change"
239
                         help="adds a NAT to the topology that"
240
                         " connects Mininet hosts to the physical network."
241
                         " Warning: This may route any traffic on the machine"
242
                         " that uses Mininet's"
243
                         " IP subnet into the Mininet network."
244
                         " If you need to change"
238 245
                         " Mininet's IP subnet, see the --ipbase option." )
239 246
        opts.add_option( '--version', action='callback', callback=version,
240 247
                         help='prints the version and exits' )
......
265 272
                    % self.options.verbosity )
266 273
        lg.setLogLevel( self.options.verbosity )
267 274

  
275
    # Maybe we'll reorganize this someday...
276
    # pylint: disable=too-many-branches,too-many-statements
277

  
268 278
    def begin( self ):
269 279
        "Create and run mininet."
270 280

  
......
279 289
            CONTROLLERS[ 'default' ] = findController()
280 290
            if CONTROLLERS[ 'default' ] is None:
281 291
                if self.options.switch == 'default':
282
                    # Fall back to OVS Bridge, which does not use an OF controller
283
                    info( '*** No default OpenFlow controller found for default switch!\n' )
292
                    info( '*** No default OpenFlow controller found '
293
                          'for default switch!\n' )
284 294
                    info( '*** Falling back to OVS Bridge\n' )
285 295
                    self.options.switch = 'ovsbr'
286 296
                    self.options.controller = 'none'
287 297
                elif self.options.switch in ( 'ovsbr', 'lxbr' ):
288 298
                    self.options.controller = 'none'
289 299
                else:
290
                    raise Exception( "Could not find a default controller for switch %s" %
300
                    raise Exception( "Could not find a default controller "
301
                                     "for switch %s" %
291 302
                                     self.options.switch )
292 303

  
293 304
        topo = buildTopo( TOPOS, self.options.topo )
examples/linuxrouter.py
44 44
class NetworkTopo( Topo ):
45 45
    "A simple topology of a router with three subnets (one host in each)."
46 46

  
47
    def build( self, **opts ):
47
    def build( self, **_opts ):
48 48
        router = self.addNode( 'r0', cls=LinuxRouter, ip='192.168.1.1/24' )
49 49
        h1 = self.addHost( 'h1', ip='192.168.1.100/24',
50 50
                           defaultRoute='via 192.168.1.1' )
examples/miniedit.py
13 13
OpenFlow icon from https://www.opennetworking.org/
14 14
"""
15 15

  
16
# For now, tolerate long lines and long module
17
# pylint: disable=line-too-long,too-many-lines
16
# Miniedit needs some work in order to pass pylint...
17
# pylint: disable=line-too-long,too-many-lines,too-many-branches
18
# pylint: disable=too-many-statements,attribute-defined-outside-init
19
# pylint: disable=missing-docstring
18 20

  
19 21
MINIEDIT_VERSION = '2.2.0.1'
20 22

  
......
1573 1575
            self.createDataLinkBindings()
1574 1576
            self.link = self.linkWidget = None
1575 1577

  
1576
        f.close
1578
        f.close()
1577 1579

  
1578 1580
    def findWidgetByName( self, name ):
1579 1581
        for widget in self.widgetToItem:
......
2624 2626
    # Ultimately we will either want to use a topo or
2625 2627
    # mininet object here, probably.
2626 2628

  
2627
    def addLink( self, source, dest, linktype='data', linkopts={} ):
2629
    def addLink( self, source, dest, linktype='data', linkopts=None ):
2628 2630
        "Add link to model."
2631
        if linkopts is None:
2632
            linkopts = {}
2629 2633
        source.links[ dest ] = self.link
2630 2634
        dest.links[ source ] = self.link
2631 2635
        self.links[ self.link ] = {'type' :linktype,
......
3142 3146
            return
3143 3147
        self.net.nameToNode[ name ].cmd( 'iperf -s -p 5001 &' )
3144 3148

  
3145
    """ BELOW HERE IS THE TOPOLOGY IMPORT CODE """
3149
    ### BELOW HERE IS THE TOPOLOGY IMPORT CODE ###
3146 3150

  
3147 3151
    def parseArgs( self ):
3148 3152
        """Parse command-line args and return options object.
......
3562 3566
if __name__ == '__main__':
3563 3567
    setLogLevel( 'info' )
3564 3568
    app = MiniEdit()
3565
    """ import topology if specified """
3569
    ### import topology if specified ###
3566 3570
    app.parseArgs()
3567 3571
    app.importTopo()
3568 3572

  
examples/vlanhost.py
30 30
from mininet.log import error
31 31

  
32 32
class VLANHost( Host ):
33
    "Host connected to VLAN interface"
33 34

  
34
   def config( self, vlan=100, **params ):
35
    def config( self, vlan=100, **params ):
35 36
        """Configure VLANHost according to (optional) parameters:
36 37
           vlan: VLAN ID for default interface"""
37 38

  
......
90 91
            self.addLink( h, s1 )
91 92

  
92 93

  
93
def exampleCustomTags( vlan ):
94
def exampleCustomTags():
94 95
    """Simple example that exercises VLANStarTopo"""
95 96

  
96 97
    net = Mininet( topo=VLANStarTopo() )
......
110 111
    setLogLevel( 'info' )
111 112

  
112 113
    if not quietRun( 'which vconfig' ):
113
        error( "Cannot find command 'vconfig'\nThe packge",
114
        error( "Cannot find command 'vconfig'\nThe package",
114 115
               "'vlan' is required in Ubuntu or Debian,",
115 116
               "or 'vconfig' in Fedora\n" )
116 117
        exit()
117
    try:
118
        vlan = int( sys.argv[ 1 ] )
119
    except Exception:
120
        vlan = None
121 118

  
122
    if vlan:
123
        exampleAllHosts( vlan )
119
    if len( sys.argv ) >= 2:
120
        exampleAllHosts( vlan=int( sys.argv[ 1 ] ) )
124 121
    else:
125
        exampleCustomTags( vlan )
122
        exampleCustomTags()

Also available in: Unified diff