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
diff --git a/tools/dev/mininet/onos.py b/tools/dev/mininet/onos.py
index cf448bb..bbc67d3 100755
--- a/tools/dev/mininet/onos.py
+++ b/tools/dev/mininet/onos.py
@@ -55,6 +55,8 @@
from glob import glob
import time
from functools import partial
+from re import search
+
### ONOS Environment
@@ -418,9 +420,22 @@
"Return list of ONOS nodes"
return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]
- def configPortForwarding( self, ports=[], intf='eth0', action='A' ):
- """Start or stop ports on intf to all nodes
+ def defaultIntf( self ):
+ "Call ip route to determine default interface"
+ result = quietRun( 'ip route | grep default', shell=True ).strip()
+ match = search( r'dev\s+([^\s]+)', result )
+ if match:
+ intf = match.group( 1 )
+ else:
+ warn( "Can't find default network interface - using eth0\n" )
+ intf = 'eth0'
+ return intf
+
+ def configPortForwarding( self, ports=[], intf='', action='A' ):
+ """Start or stop forwarding on intf to all nodes
action: A=add/start, D=delete/stop (default: A)"""
+ if not intf:
+ intf = self.defaultIntf()
for port in ports:
for index, node in enumerate( self.nodes() ):
ip, inport = node.IP(), port + index