Revision af1ccf93 bin/mn

View differences:

bin/mn
32 32
from mininet.link import Link, TCLink
33 33
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
34 34
from mininet.topolib import TreeTopo, TorusTopo
35
from mininet.util import customConstructor
35
from mininet.util import customConstructor, splitArgs
36 36
from mininet.util import buildTopo
37 37

  
38 38
from functools import partial
......
168 168
            # Add or modify global variable or class
169 169
            globals()[ name ] = value
170 170

  
171
    def setNat( self, option, opt_str, value, parser ):
172
        parser.values.nat = True
173
        if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-': #first arg, first char != '-'
174
            value = parser.rargs.pop( 0 )
175
            _, args, kwargs = splitArgs( opt_str + ',' + value )
176
            parser.values.nat_args = args
177
            parser.values.nat_kwargs = kwargs
178
        else:
179
            parser.values.nat_args = []
180
            parser.values.nat_kwargs = {}
181

  
171 182
    def parseArgs( self ):
172 183
        """Parse command-line args and return options object.
173 184
           returns: opts parse options dict"""
......
219 230
        opts.add_option( '--pin', action='store_true',
220 231
                         default=False, help="pin hosts to CPU cores "
221 232
                         "(requires --host cfs or --host rt)" )
222
        opts.add_option( '--nat', action='store_true',
223
                         default=False, help="adds a NAT to the topology "
224
                         "that connects Mininet to the physical network" )
233
        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"
238
                         " Mininet's IP subnet, see the --ipbase option." )
225 239
        opts.add_option( '--version', action='callback', callback=version,
226 240
                         help='prints the version and exits' )
227 241
        opts.add_option( '--cluster', type='string', default=None,
......
319 333
                  listenPort=listenPort )
320 334

  
321 335
        if self.options.nat:
322
            nat = mn.addNAT()
336
            nat = mn.addNAT( *self.options.nat_args, **self.options.nat_kwargs )
323 337
            nat.configDefault()
324 338

  
325 339
        if self.options.pre:

Also available in: Unified diff