Revision b739cd11
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 custom, customConstructor
|
|
35 |
from mininet.util import customConstructor |
|
36 | 36 |
from mininet.util import buildTopo |
37 | 37 |
|
38 | 38 |
from functools import partial |
... | ... | |
67 | 67 |
|
68 | 68 |
HOSTDEF = 'proc' |
69 | 69 |
HOSTS = { 'proc': Host, |
70 |
'rt': custom( CPULimitedHost, sched='rt' ),
|
|
71 |
'cfs': custom( CPULimitedHost, sched='cfs' ) }
|
|
70 |
'rt': partial( CPULimitedHost, sched='rt' ),
|
|
71 |
'cfs': partial( CPULimitedHost, sched='cfs' ) }
|
|
72 | 72 |
|
73 | 73 |
CONTROLLERDEF = 'default' |
74 | 74 |
CONTROLLERS = { 'ref': Controller, |
... | ... | |
118 | 118 |
print "%s" % VERSION |
119 | 119 |
exit() |
120 | 120 |
|
121 |
def custom( option, opt_str, value, parser, *args, **kwargs ): |
|
122 |
"""Parse custom file and add params. |
|
123 |
option: option e.g. --custom |
|
124 |
opt_str: option string e.g. --custom |
|
125 |
value: the value the follows the option |
|
126 |
parser: option parser instance |
|
127 |
args: empty tuple |
|
128 |
kwargs: dict that contains { self : MininetRunner reference }""" |
|
129 |
|
|
130 |
self = kwargs['self'] |
|
131 |
files = [] |
|
132 |
if os.path.isfile( value ): |
|
133 |
# accept any single file (including those with commas) |
|
134 |
files.append( value ) |
|
135 |
else: |
|
136 |
# accept a comma-separated list of filenames |
|
137 |
files += value.split(',') |
|
138 |
|
|
139 |
for fileName in files: |
|
140 |
customs = {} |
|
141 |
if os.path.isfile( fileName ): |
|
142 |
execfile( fileName, customs, customs ) |
|
143 |
for name, val in customs.iteritems(): |
|
144 |
self.setCustom( name, val ) |
|
145 |
else: |
|
146 |
raise Exception( 'could not find custom file: %s' % fileName ) |
|
147 | 121 |
|
148 | 122 |
class MininetRunner( object ): |
149 | 123 |
"Build, setup, and run Mininet." |
... | ... | |
158 | 132 |
self.setup() |
159 | 133 |
self.begin() |
160 | 134 |
|
135 |
def custom( self, option, opt_str, value, parser ): |
|
136 |
"""Parse custom file and add params. |
|
137 |
option: option e.g. --custom |
|
138 |
opt_str: option string e.g. --custom |
|
139 |
value: the value the follows the option |
|
140 |
parser: option parser instance""" |
|
141 |
files = [] |
|
142 |
if os.path.isfile( value ): |
|
143 |
# Accept any single file (including those with commas) |
|
144 |
files.append( value ) |
|
145 |
else: |
|
146 |
# Accept a comma-separated list of filenames |
|
147 |
files += value.split(',') |
|
148 |
|
|
149 |
for fileName in files: |
|
150 |
customs = {} |
|
151 |
if os.path.isfile( fileName ): |
|
152 |
execfile( fileName, customs, customs ) |
|
153 |
for name, val in customs.iteritems(): |
|
154 |
self.setCustom( name, val ) |
|
155 |
else: |
|
156 |
raise Exception( 'could not find custom file: %s' % fileName ) |
|
157 |
|
|
161 | 158 |
def setCustom( self, name, value ): |
162 | 159 |
"Set custom parameters for MininetRunner." |
163 | 160 |
if name in ( 'topos', 'switches', 'hosts', 'controllers' ): |
... | ... | |
191 | 188 |
|
192 | 189 |
opts.add_option( '--clean', '-c', action='store_true', |
193 | 190 |
default=False, help='clean and exit' ) |
194 |
opts.add_option( '--custom', action='callback', callback=custom,
|
|
195 |
type='string', callback_kwargs={ 'self' : self },
|
|
196 |
help='read custom classes or params from .py file' )
|
|
191 |
opts.add_option( '--custom', action='callback', |
|
192 |
callback=partial( self.custom, self=self ),
|
|
193 |
type='string', help='read custom classes or params from .py file(s)' )
|
|
197 | 194 |
opts.add_option( '--test', type='choice', choices=TESTS, |
198 | 195 |
default=TESTS[ 0 ], |
199 | 196 |
help='|'.join( TESTS ) ) |
Also available in: Unified diff