Bob Lantz
Committed by Brian O'Connor

Use ip route to determine default intf for port forwarding

We were using eth0 by default before, but this doesn't work if
your default interface isn't eth0.

Fixes port forwarding on Ubuntu 16.04.

Change-Id: I55baed7fd8952a9f6cab364e20e31a0632ddda6d
...@@ -55,6 +55,8 @@ from sys import argv ...@@ -55,6 +55,8 @@ from sys import argv
55 from glob import glob 55 from glob import glob
56 import time 56 import time
57 from functools import partial 57 from functools import partial
58 +from re import search
59 +
58 60
59 ### ONOS Environment 61 ### ONOS Environment
60 62
...@@ -418,9 +420,22 @@ class ONOSCluster( Controller ): ...@@ -418,9 +420,22 @@ class ONOSCluster( Controller ):
418 "Return list of ONOS nodes" 420 "Return list of ONOS nodes"
419 return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ] 421 return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]
420 422
421 - def configPortForwarding( self, ports=[], intf='eth0', action='A' ): 423 + def defaultIntf( self ):
422 - """Start or stop ports on intf to all nodes 424 + "Call ip route to determine default interface"
425 + result = quietRun( 'ip route | grep default', shell=True ).strip()
426 + match = search( r'dev\s+([^\s]+)', result )
427 + if match:
428 + intf = match.group( 1 )
429 + else:
430 + warn( "Can't find default network interface - using eth0\n" )
431 + intf = 'eth0'
432 + return intf
433 +
434 + def configPortForwarding( self, ports=[], intf='', action='A' ):
435 + """Start or stop forwarding on intf to all nodes
423 action: A=add/start, D=delete/stop (default: A)""" 436 action: A=add/start, D=delete/stop (default: A)"""
437 + if not intf:
438 + intf = self.defaultIntf()
424 for port in ports: 439 for port in ports:
425 for index, node in enumerate( self.nodes() ): 440 for index, node in enumerate( self.nodes() ):
426 ip, inport = node.IP(), port + index 441 ip, inport = node.IP(), port + index
......