Revision bb941950 bin/mn

View differences:

bin/mn
21 21
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
22 22
from mininet.node import RemoteController, UserSwitch, OVSKernelSwitch
23 23
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
24
from mininet.util import makeNumeric
24 25

  
25 26
# built in topologies, created only when run
26 27
TOPODEF = 'minimal'
27
TOPOS = { 'minimal': ( lambda: SingleSwitchTopo( k=2 ) ),
28
         'reversed': ( lambda: SingleSwitchReversedTopo( k=2 ) ),
29
         'single4': ( lambda: SingleSwitchTopo( k=4 ) ),
30
         'single100': ( lambda: SingleSwitchTopo( k=100 ) ),
31
         'linear2': ( lambda: LinearTopo( k=2 ) ),
32
         'linear100': ( lambda: LinearTopo( k=100 ) ) }
28
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
29
         'linear': LinearTopo,
30
         'reversed': SingleSwitchReversedTopo,
31
         'single': SingleSwitchTopo }
33 32

  
34 33
SWITCHDEF = 'kernel'
35 34
SWITCHES = { 'kernel': KernelSwitch,
......
51 50
TESTS = [ 'cli', 'build', 'pingAll', 'pingPair', 'iperf', 'all', 'iperfUdp' ]
52 51

  
53 52

  
53
def buildTopo( topo ):
54
    "Create topology from string with format (object, arg1, arg2,...)."
55
    topo_split = topo.split( ',' )
56
    topo_name = topo_split[ 0 ]
57
    topo_params = topo_split[ 1: ]
58

  
59
    # Convert int and float args; removes the need for every topology to
60
    # be flexible with input arg formats.
61
    topo_seq_params = [ s for s in topo_params if '=' not in s ]
62
    topo_seq_params = [ makeNumeric( s ) for s in topo_seq_params ]
63
    topo_kw_params = {}
64
    for s in [ s for s in topo_params if '=' in s ]:
65
        key, val = s.split( '=' )
66
        topo_kw_params[ key ] = makeNumeric( val )
67

  
68
    if topo_name not in TOPOS.keys():
69
        raise Exception( 'Invalid topo_name %s' % topo_name )
70
    return TOPOS[ topo_name ]( *topo_seq_params, **topo_kw_params )
71

  
72

  
54 73
def addDictOption( opts, choicesDict, default, name, helpStr=None ):
55 74
    """Convenience function to add choices dicts to OptionParser.
56 75
       opts: OptionParser instance
......
118 137
                raise Exception( 'Custom file name not found' )
119 138

  
120 139
        opts = OptionParser()
121
        addDictOption( opts, TOPOS, TOPODEF, 'topo' )
122 140
        addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
123 141
        addDictOption( opts, HOSTS, HOSTDEF, 'host' )
124 142
        addDictOption( opts, CONTROLLERS, CONTROLLERDEF, 'controller' )
125 143

  
144
        opts.add_option( '--topo', type='string', default=TOPODEF,
145
                        help='[' + ' '.join( TOPOS.keys() ) + '],arg1,arg2,'
146
                        '...argN')
126 147
        opts.add_option( '--custom', type='string', default=None,
127 148
                        help='read custom topo and node params from .py file' )
128 149
        opts.add_option( '--test', type='choice', choices=TESTS,
......
165 186

  
166 187
        start = time.time()
167 188

  
168
        topo = TOPOS[ self.options.topo ]() # build topology object
189
        topo = buildTopo( self.options.topo )
169 190
        switch = SWITCHES[ self.options.switch ]
170 191
        host = HOSTS[ self.options.host ]
171 192
        controller = CONTROLLERS[ self.options.controller ]

Also available in: Unified diff