diff --git a/bin/mn_run.py b/bin/mn_run.py index f5e8530..a1fdfe4 100755 --- a/bin/mn_run.py +++ b/bin/mn_run.py @@ -16,7 +16,7 @@ except ImportError: from mininet.logging_mod import lg, set_loglevel, LEVELS from mininet.net import Mininet, init from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX -from mininet.node import RemoteController +from mininet.node import RemoteController, UserSwitch from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo # built in topologies, created only when run @@ -38,7 +38,8 @@ if USE_RIPCORD: TOPOS.update(TOPOS_RIPCORD) SWITCH_DEF = 'kernel' -SWITCHES = {'kernel' : KernelSwitch} +SWITCHES = {'kernel' : KernelSwitch, + 'user' : UserSwitch} HOST_DEF = 'process' HOSTS = {'process' : Host} @@ -115,6 +116,8 @@ class MininetRunner(object): opts.add_option('--port', type = 'string', default = 6633, help = '[port integer for a listening remote' ' controller]') + opts.add_option('--in_namespace', action = 'store_true', + default = False, help = 'sw and ctrl in namespace?') self.options = opts.parse_args()[0] def setup(self): @@ -147,10 +150,12 @@ class MininetRunner(object): port = self.options.port) controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8 + in_namespace = self.options.in_namespace xterms = self.options.xterms mac = self.options.mac arp = self.options.arp mn = Mininet(topo, switch, host, controller, controller_params, + in_namespace = in_namespace, xterms = xterms, auto_set_macs = mac, auto_static_arp = arp) diff --git a/mininet/net.py b/mininet/net.py index 0305e02..0bb2dd2 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -92,7 +92,7 @@ class Mininet(object): @param now build now? @param xterms if build now, spawn xterms? @param cleanup if build now, cleanup before creating? - @param in_namespace spawn switches and hosts in their own namespace? + @param in_namespace spawn switches and controller in net namespaces? @param auto_set_macs set MAC addrs to DPIDs? @param auto_static_arp set all-pairs static MAC addrs? ''' @@ -112,8 +112,6 @@ class Mininet(object): self.terms = [] # list of spawned xterm processes - self.kernel = True #temporary! - if build: self.build() @@ -178,7 +176,7 @@ class Mininet(object): @param controller Controller class ''' - controller = self.controller('c0', not self.kernel) + controller = self.controller('c0', self.in_namespace) if controller: # allow controller-less setups self.controllers['c0'] = controller @@ -271,11 +269,6 @@ class Mininet(object): if self.cleanup: pass # cleanup # validate topo? - kernel = self.kernel - if kernel: - lg.info('*** Using kernel datapath\n') - else: - lg.info('*** Using user datapath\n') lg.info('*** Adding controller\n') self._add_controller(self.controller) lg.info('*** Creating network\n') @@ -287,13 +280,13 @@ class Mininet(object): for switch in sorted(self.topo.switches()): self._add_switch(switch) lg.info('0x%x ' % switch) - lg.info('\n*** Adding edges: ') + lg.info('\n*** Adding edges:\n') for src, dst in sorted(self.topo.edges()): self._add_link(src, dst) lg.info('(0x%x, 0x%x) ' % (src, dst)) lg.info('\n') - if not kernel: + if self.in_namespace: lg.info('*** Configuring control network\n') self._configureControlNetwork() diff --git a/mininet/node.py b/mininet/node.py index ca1f4f9..82c44c8 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -259,13 +259,17 @@ class Switch(Node): return True, '' class UserSwitch(Switch): + '''User-space switch. + + Currently only works in the root namespace. + ''' def __init__(self, name): '''Init. @param name ''' - Node.__init__(self, name, inNamespace = True) + Node.__init__(self, name, inNamespace = False) def start(self, controllers): '''Start OpenFlow reference user datapath. @@ -274,17 +278,17 @@ class UserSwitch(Switch): @param controllers dict of controller names to objects ''' - if 'c0' not in controller: + if 'c0' not in controllers: raise Exception('User datapath start() requires controller c0') controller = controllers['c0'] ofdlog = '/tmp/' + self.name + '-ofd.log' ofplog = '/tmp/' + self.name + '-ofp.log' self.cmd('ifconfig lo up') - intfs = self.intfs[1:] # 0 is mgmt interface - self.cmdPrint('ofdatapath -i ' + ','.join(intfs) + - ' ptcp: 1> ' + ofdlog + ' 2> ' + ofdlog + ' &') - self.cmdPrint('ofprotocol tcp:' + controller.IP() + - ' tcp:localhost --fail=closed 1> ' + ofplog + ' 2>' + + intfs = self.intfs + self.cmdPrint('ofdatapath -i ' + ','.join(intfs) + ' punix:/tmp/' + + self.name + ' 1> ' + ofdlog + ' 2> ' + ofdlog + ' &') + self.cmdPrint('ofprotocol unix:/tmp/' + self.name + ' tcp:' + + controller.IP() + ' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &') def stop(self):