@@ -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
0 commit comments