Add ability to read custom Mininets
This commit is contained in:
+21
-4
@@ -5,6 +5,7 @@
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import os.path
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -100,6 +101,8 @@ class MininetRunner(object):
|
|||||||
add_dict_option(opts, HOSTS, HOST_DEF, 'host')
|
add_dict_option(opts, HOSTS, HOST_DEF, 'host')
|
||||||
add_dict_option(opts, CONTROLLERS, CONTROLLER_DEF, 'controller')
|
add_dict_option(opts, CONTROLLERS, CONTROLLER_DEF, 'controller')
|
||||||
|
|
||||||
|
opts.add_option('--custom', type = 'string', default = None,
|
||||||
|
help = 'read custom mininet from current dir')
|
||||||
opts.add_option('--test', type = 'choice', choices = TESTS,
|
opts.add_option('--test', type = 'choice', choices = TESTS,
|
||||||
default = TESTS[0],
|
default = TESTS[0],
|
||||||
help = '[' + ' '.join(TESTS) + ']')
|
help = '[' + ' '.join(TESTS) + ']')
|
||||||
@@ -137,6 +140,10 @@ class MininetRunner(object):
|
|||||||
raise Exception('multipath topos require multipath-capable '
|
raise Exception('multipath topos require multipath-capable '
|
||||||
'controller.')
|
'controller.')
|
||||||
|
|
||||||
|
if self.options.custom:
|
||||||
|
if not os.path.isfile(self.options.custom):
|
||||||
|
raise Exception('could not find custom file: %s' % custom)
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
'''Create and run mininet.'''
|
'''Create and run mininet.'''
|
||||||
|
|
||||||
@@ -156,10 +163,20 @@ class MininetRunner(object):
|
|||||||
xterms = self.options.xterms
|
xterms = self.options.xterms
|
||||||
mac = self.options.mac
|
mac = self.options.mac
|
||||||
arp = self.options.arp
|
arp = self.options.arp
|
||||||
mn = Mininet(topo, switch, host, controller, controller_params,
|
mn = None
|
||||||
in_namespace = in_namespace,
|
if not self.options.custom:
|
||||||
xterms = xterms, auto_set_macs = mac,
|
mn = Mininet(topo, switch, host, controller, controller_params,
|
||||||
auto_static_arp = arp)
|
in_namespace = in_namespace,
|
||||||
|
xterms = xterms, auto_set_macs = mac,
|
||||||
|
auto_static_arp = arp)
|
||||||
|
else:
|
||||||
|
globals_ = {}
|
||||||
|
locals_ = {}
|
||||||
|
execfile(self.options.custom, globals_, locals_)
|
||||||
|
if 'mn' not in locals_:
|
||||||
|
raise Exception('could not find mn var in custom file')
|
||||||
|
else:
|
||||||
|
mn = locals_['mn']
|
||||||
|
|
||||||
test = self.options.test
|
test = self.options.test
|
||||||
if test != 'build':
|
if test != 'build':
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
This directory should hold configuration files for custom mininets.
|
||||||
|
|
||||||
|
See custom_example.py, which loads the default minimal topology. The advantage of defining a mininet in a separate file is that you then use the --custom option in mn_run.py to run the CLI or specific tests with it.
|
||||||
|
|
||||||
|
Each custom file must define a Mininet object for an 'mn' variable.
|
||||||
|
|
||||||
|
To start up a mininet with this custom topology, do:
|
||||||
|
sudo mn_run.py --custom custom_example.py
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
'''Example of custom topo
|
||||||
|
|
||||||
|
@author Brandon Heller (brandonh@stanford.edu)
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from mininet.topo import SingleSwitchTopo
|
||||||
|
from mininet.net import Mininet
|
||||||
|
from mininet.node import KernelSwitch, Host, Controller, ControllerParams
|
||||||
|
|
||||||
|
topo = SingleSwitchTopo(k = 2) # build topology object
|
||||||
|
switch = KernelSwitch
|
||||||
|
host = Host
|
||||||
|
controller = Controller
|
||||||
|
controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
|
||||||
|
in_namespace = False
|
||||||
|
xterms = False
|
||||||
|
mac = True
|
||||||
|
arp = True
|
||||||
|
|
||||||
|
mn = Mininet(topo, switch, host, controller, controller_params,
|
||||||
|
in_namespace = in_namespace,
|
||||||
|
xterms = xterms, auto_set_macs = mac,
|
||||||
|
auto_static_arp = arp)
|
||||||
|
|
||||||
Reference in New Issue
Block a user