Committed by
Gerrit Code Review
Add portOffset for multiple ONOSCluster port forwarding
With multiple ONOS clusters, we want to make sure that the forwarded port numbers don't collide. We add a portOffset which is automatically incremented appropriately as more ONOSClusters are created. It can also be specified explicitly. Change-Id: I62977c3d4141668d9f541067db1a20ec0035489b
Showing
1 changed file
with
14 additions
and
4 deletions
| ... | @@ -369,19 +369,27 @@ class ONOSNode( Controller ): | ... | @@ -369,19 +369,27 @@ class ONOSNode( Controller ): |
| 369 | 369 | ||
| 370 | class ONOSCluster( Controller ): | 370 | class ONOSCluster( Controller ): |
| 371 | "ONOS Cluster" | 371 | "ONOS Cluster" |
| 372 | + # Offset for port forwarding | ||
| 373 | + portOffset = 0 | ||
| 372 | def __init__( self, *args, **kwargs ): | 374 | def __init__( self, *args, **kwargs ): |
| 373 | """name: (first parameter) | 375 | """name: (first parameter) |
| 374 | *args: topology class parameters | 376 | *args: topology class parameters |
| 375 | ipBase: IP range for ONOS nodes | 377 | ipBase: IP range for ONOS nodes |
| 376 | - forward: default port forwarding list, | 378 | + forward: default port forwarding list |
| 379 | + portOffset: offset to port base (optional) | ||
| 377 | topo: topology class or instance | 380 | topo: topology class or instance |
| 378 | nodeOpts: ONOSNode options | 381 | nodeOpts: ONOSNode options |
| 379 | - **kwargs: additional topology parameters""" | 382 | + **kwargs: additional topology parameters |
| 383 | + By default, multiple ONOSClusters will increment | ||
| 384 | + the portOffset automatically; alternately, it can | ||
| 385 | + be specified explicitly. | ||
| 386 | + """ | ||
| 380 | args = list( args ) | 387 | args = list( args ) |
| 381 | name = args.pop( 0 ) | 388 | name = args.pop( 0 ) |
| 382 | topo = kwargs.pop( 'topo', None ) | 389 | topo = kwargs.pop( 'topo', None ) |
| 383 | self.nat = kwargs.pop( 'nat', 'nat0' ) | 390 | self.nat = kwargs.pop( 'nat', 'nat0' ) |
| 384 | nodeOpts = kwargs.pop( 'nodeOpts', {} ) | 391 | nodeOpts = kwargs.pop( 'nodeOpts', {} ) |
| 392 | + self.portOffset = kwargs.pop( 'portOffset', ONOSCluster.portOffset ) | ||
| 385 | # Pass in kwargs to the ONOSNodes instead of the cluster | 393 | # Pass in kwargs to the ONOSNodes instead of the cluster |
| 386 | "alertAction: exception|ignore|warn|exit (exception)" | 394 | "alertAction: exception|ignore|warn|exit (exception)" |
| 387 | alertAction = kwargs.pop( 'alertAction', None ) | 395 | alertAction = kwargs.pop( 'alertAction', None ) |
| ... | @@ -408,6 +416,8 @@ class ONOSCluster( Controller ): | ... | @@ -408,6 +416,8 @@ class ONOSCluster( Controller ): |
| 408 | self.net.addNAT( self.nat ).configDefault() | 416 | self.net.addNAT( self.nat ).configDefault() |
| 409 | updateNodeIPs( self.env, self.nodes() ) | 417 | updateNodeIPs( self.env, self.nodes() ) |
| 410 | self._remoteControllers = [] | 418 | self._remoteControllers = [] |
| 419 | + # Update port offset for more ONOS clusters | ||
| 420 | + ONOSCluster.portOffset += len( self.nodes() ) | ||
| 411 | 421 | ||
| 412 | def start( self ): | 422 | def start( self ): |
| 413 | "Start up ONOS cluster" | 423 | "Start up ONOS cluster" |
| ... | @@ -448,13 +458,13 @@ class ONOSCluster( Controller ): | ... | @@ -448,13 +458,13 @@ class ONOSCluster( Controller ): |
| 448 | '-j ACCEPT' ) | 458 | '-j ACCEPT' ) |
| 449 | for port in ports: | 459 | for port in ports: |
| 450 | for index, node in enumerate( self.nodes() ): | 460 | for index, node in enumerate( self.nodes() ): |
| 451 | - ip, inport = node.IP(), port + index | 461 | + ip, inport = node.IP(), port + self.portOffset + index |
| 452 | # Configure a destination NAT rule | 462 | # Configure a destination NAT rule |
| 453 | self.cmd( 'iptables -t nat -' + action, | 463 | self.cmd( 'iptables -t nat -' + action, |
| 454 | 'PREROUTING -t nat -p tcp --dport', inport, | 464 | 'PREROUTING -t nat -p tcp --dport', inport, |
| 455 | '-j DNAT --to-destination %s:%s' % ( ip, port ) ) | 465 | '-j DNAT --to-destination %s:%s' % ( ip, port ) ) |
| 456 | 466 | ||
| 457 | - | 467 | + |
| 458 | class ONOSSwitchMixin( object ): | 468 | class ONOSSwitchMixin( object ): |
| 459 | "Mixin for switches that connect to an ONOSCluster" | 469 | "Mixin for switches that connect to an ONOSCluster" |
| 460 | def start( self, controllers ): | 470 | def start( self, controllers ): | ... | ... |
-
Please register or login to post a comment