aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-11-17 08:19:29 -0800
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:05:06 -0800
commite75497921e8edf48512c8bb6d2659e67c6738fbc (patch)
treea3972e194208198b783cdfeb0e6ccb4c7dfc94da
parentecaa81beafe1b995da2a4ecb003a480911478c17 (diff)
downloaduhd-e75497921e8edf48512c8bb6d2659e67c6738fbc.tar.gz
uhd-e75497921e8edf48512c8bb6d2659e67c6738fbc.tar.bz2
uhd-e75497921e8edf48512c8bb6d2659e67c6738fbc.zip
mpm: net: Add ip_addr_to_iface() function
Reviewed-By: Trung Tran <trung.tran@ettus.com>
-rw-r--r--mpm/python/usrp_mpm/net.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/net.py b/mpm/python/usrp_mpm/net.py
index 78895a0bb..b91e6d278 100644
--- a/mpm/python/usrp_mpm/net.py
+++ b/mpm/python/usrp_mpm/net.py
@@ -19,6 +19,7 @@ N310 implementation module
"""
import itertools
import socket
+from six import iteritems
from pyroute2 import IPRoute
from .mpmlog import get_logger
@@ -68,6 +69,22 @@ def get_iface_info(ifname):
'ip_addrs': ip_addrs,
}
+def ip_addr_to_iface(ip_addr, iface_list):
+ """
+ Return an Ethernet interface (e.g. 'eth1') given an IP address.
+
+ Arguments:
+ ip_addr -- The IP address as a string
+ iface_list -- A map "interface name" -> iface_info, where iface_info
+ is another map as returned by net.get_iface_info().
+ """
+ # Flip around the iface_info map and then use it to look up by IP addr
+ return {
+ iface_info['ip_addr']: iface_name
+ for iface_name, iface_info in iteritems(iface_list)
+ }[ip_addr]
+
+
def get_iface_addrs(mac_addr):
"""
return ipv4 addresses for a given macaddress