Skip to content

Commit ccca871

Browse files
author
Brandon Heller
committed
Add passive listening port
1 parent 2d48b46 commit ccca871

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

bin/mn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class MininetRunner( object ):
176176
' controller]' )
177177
opts.add_option( '--innamespace', action='store_true',
178178
default=False, help='sw and ctrl in namespace?' )
179+
opts.add_option( '--listenport', type='int', default=6634,
180+
help='[base port for passive switch listening'
181+
' controller]' )
179182
opts.add_option( '--pre', type='string', default=None,
180183
help='[CLI script to run before tests]' )
181184
opts.add_option( '--post', type='string', default=None,
@@ -222,10 +225,11 @@ class MininetRunner( object ):
222225
xterms = self.options.xterms
223226
mac = self.options.mac
224227
arp = self.options.arp
228+
listenPort = self.options.listenport
225229
mn = Mininet( topo, switch, host, controller, controllerParams,
226230
inNamespace=inNamespace,
227231
xterms=xterms, autoSetMacs=mac,
228-
autoStaticArp=arp )
232+
autoStaticArp=arp, listenPort=listenPort )
229233
if self.options.pre:
230234
CLI( mn, script=self.options.pre )
231235

mininet/net.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__( self, topo=None, switch=KernelSwitch, host=Host,
108108
cparams=ControllerParams( '10.0.0.0', 8 ),
109109
build=True, xterms=False, cleanup=False,
110110
inNamespace=False,
111-
autoSetMacs=False, autoStaticArp=False ):
111+
autoSetMacs=False, autoStaticArp=False, listenPort=None ):
112112
"""Create Mininet object.
113113
topo: Topo (topology) object or None
114114
switch: Switch class
@@ -120,7 +120,9 @@ def __init__( self, topo=None, switch=KernelSwitch, host=Host,
120120
cleanup: if build now, cleanup before creating?
121121
inNamespace: spawn switches and controller in net namespaces?
122122
autoSetMacs: set MAC addrs from topo?
123-
autoStaticArp: set all-pairs static MAC addrs?"""
123+
autoStaticArp: set all-pairs static MAC addrs?
124+
listenPort: base listening port to open; will be incremented for
125+
each additional switch in the net if inNamespace=False"""
124126
self.switch = switch
125127
self.host = host
126128
self.controller = controller
@@ -131,6 +133,7 @@ def __init__( self, topo=None, switch=KernelSwitch, host=Host,
131133
self.cleanup = cleanup
132134
self.autoSetMacs = autoSetMacs
133135
self.autoStaticArp = autoStaticArp
136+
self.listenPort = listenPort
134137

135138
self.hosts = []
136139
self.switches = []
@@ -162,13 +165,17 @@ def addSwitch( self, name, mac=None, ip=None ):
162165
"""Add switch.
163166
name: name of switch to add
164167
mac: default MAC address for kernel/OVS switch intf 0
165-
returns: added switch"""
168+
returns: added switch
169+
side effect: increments the listenPort member variable."""
166170
if self.switch == UserSwitch:
167-
sw = self.switch( name, defaultMAC=mac, defaultIP=ip,
168-
inNamespace=self.inNamespace )
171+
sw = self.switch( name, listenPort=self.listenPort,
172+
defaultMAC=mac, defaultIP=ip, inNamespace=self.inNamespace )
169173
else:
170-
sw = self.switch( name, defaultMAC=mac, defaultIP=ip, dp=self.dps,
174+
sw = self.switch( name, listenPort=self.listenPort,
175+
defaultMAC=mac, defaultIP=ip, dp=self.dps,
171176
inNamespace=self.inNamespace )
177+
if not self.inNamespace:
178+
self.listenPort += 1
172179
self.dps += 1
173180
self.switches.append( sw )
174181
self.nameToNode[ name ] = sw

mininet/node.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,12 @@ class Switch( Node ):
434434

435435
portBase = SWITCH_PORT_BASE # 0 for OF < 1.0, 1 for OF >= 1.0
436436

437-
def __init__( self, name, opts='', **kwargs):
437+
def __init__( self, name, opts='', listenPort=None, **kwargs):
438438
Node.__init__( self, name, **kwargs )
439439
self.opts = opts
440+
self.listenPort = listenPort
441+
if self.listenPort:
442+
self.opts += ' --listen=ptcp:%i ' % self.listenPort
440443

441444
def sendCmd( self, *cmd, **kwargs ):
442445
"""Send command to Node.

0 commit comments

Comments
 (0)