From ccca871ae65fee89b150fdff3ebad66677e93469 Mon Sep 17 00:00:00 2001 From: Brandon Heller Date: Wed, 18 Aug 2010 00:18:09 -0700 Subject: [PATCH] Add passive listening port --- bin/mn | 6 +++++- mininet/net.py | 19 +++++++++++++------ mininet/node.py | 5 ++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/mn b/bin/mn index 9e50cbf..510af1a 100755 --- a/bin/mn +++ b/bin/mn @@ -176,6 +176,9 @@ class MininetRunner( object ): ' controller]' ) opts.add_option( '--innamespace', action='store_true', default=False, help='sw and ctrl in namespace?' ) + opts.add_option( '--listenport', type='int', default=6634, + help='[base port for passive switch listening' + ' controller]' ) opts.add_option( '--pre', type='string', default=None, help='[CLI script to run before tests]' ) opts.add_option( '--post', type='string', default=None, @@ -222,10 +225,11 @@ class MininetRunner( object ): xterms = self.options.xterms mac = self.options.mac arp = self.options.arp + listenPort = self.options.listenport mn = Mininet( topo, switch, host, controller, controllerParams, inNamespace=inNamespace, xterms=xterms, autoSetMacs=mac, - autoStaticArp=arp ) + autoStaticArp=arp, listenPort=listenPort ) if self.options.pre: CLI( mn, script=self.options.pre ) diff --git a/mininet/net.py b/mininet/net.py index 5f1bb44..d343207 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -108,7 +108,7 @@ class Mininet( object ): cparams=ControllerParams( '10.0.0.0', 8 ), build=True, xterms=False, cleanup=False, inNamespace=False, - autoSetMacs=False, autoStaticArp=False ): + autoSetMacs=False, autoStaticArp=False, listenPort=None ): """Create Mininet object. topo: Topo (topology) object or None switch: Switch class @@ -120,7 +120,9 @@ class Mininet( object ): cleanup: if build now, cleanup before creating? inNamespace: spawn switches and controller in net namespaces? autoSetMacs: set MAC addrs from topo? - autoStaticArp: set all-pairs static MAC addrs?""" + autoStaticArp: set all-pairs static MAC addrs? + listenPort: base listening port to open; will be incremented for + each additional switch in the net if inNamespace=False""" self.switch = switch self.host = host self.controller = controller @@ -131,6 +133,7 @@ class Mininet( object ): self.cleanup = cleanup self.autoSetMacs = autoSetMacs self.autoStaticArp = autoStaticArp + self.listenPort = listenPort self.hosts = [] self.switches = [] @@ -162,13 +165,17 @@ class Mininet( object ): """Add switch. name: name of switch to add mac: default MAC address for kernel/OVS switch intf 0 - returns: added switch""" + returns: added switch + side effect: increments the listenPort member variable.""" if self.switch == UserSwitch: - sw = self.switch( name, defaultMAC=mac, defaultIP=ip, - inNamespace=self.inNamespace ) + sw = self.switch( name, listenPort=self.listenPort, + defaultMAC=mac, defaultIP=ip, inNamespace=self.inNamespace ) else: - sw = self.switch( name, defaultMAC=mac, defaultIP=ip, dp=self.dps, + sw = self.switch( name, listenPort=self.listenPort, + defaultMAC=mac, defaultIP=ip, dp=self.dps, inNamespace=self.inNamespace ) + if not self.inNamespace: + self.listenPort += 1 self.dps += 1 self.switches.append( sw ) self.nameToNode[ name ] = sw diff --git a/mininet/node.py b/mininet/node.py index 6380fee..6da4d70 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -434,9 +434,12 @@ class Switch( Node ): portBase = SWITCH_PORT_BASE # 0 for OF < 1.0, 1 for OF >= 1.0 - def __init__( self, name, opts='', **kwargs): + def __init__( self, name, opts='', listenPort=None, **kwargs): Node.__init__( self, name, **kwargs ) self.opts = opts + self.listenPort = listenPort + if self.listenPort: + self.opts += ' --listen=ptcp:%i ' % self.listenPort def sendCmd( self, *cmd, **kwargs ): """Send command to Node.