diff options
| author | Trung Tran <trung.tran@ettus.com> | 2018-08-24 11:57:20 -0700 | 
|---|---|---|
| committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-09-13 14:47:54 -0700 | 
| commit | b357278c1ba0c85a22dcf95f298fc567f8001ba3 (patch) | |
| tree | 70fe28eaa92519f11dcd4101396b6a221bdd03bb /mpm/python/usrp_mpm | |
| parent | 36218e220e88728379d6b25465f4ebd62dc75a6e (diff) | |
| download | uhd-b357278c1ba0c85a22dcf95f298fc567f8001ba3.tar.gz uhd-b357278c1ba0c85a22dcf95f298fc567f8001ba3.tar.bz2 uhd-b357278c1ba0c85a22dcf95f298fc567f8001ba3.zip | |
mpm: add link_speed xport_info
Diffstat (limited to 'mpm/python/usrp_mpm')
| -rw-r--r-- | mpm/python/usrp_mpm/sys_utils/net.py | 21 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/xports/xportmgr_udp.py | 1 | 
2 files changed, 22 insertions, 0 deletions
| diff --git a/mpm/python/usrp_mpm/sys_utils/net.py b/mpm/python/usrp_mpm/sys_utils/net.py index 95dc14ed8..e28c8bda1 100644 --- a/mpm/python/usrp_mpm/sys_utils/net.py +++ b/mpm/python/usrp_mpm/sys_utils/net.py @@ -8,6 +8,7 @@ Network utilities for MPM  """  import itertools  import socket +import pyudev  from six import iteritems  from pyroute2 import IPRoute, IPDB  from usrp_mpm.mpmlog import get_logger @@ -54,6 +55,7 @@ def get_iface_info(ifname):                  raise LookupError("No interfaces known with name `{}'!"                                    .format(ifname))              link_info = ipr.get_links(links)[0] +            link_speed = get_link_speed(ifname)      except IndexError:          raise LookupError("Could not get links for interface `{}'"                            .format(ifname)) @@ -63,8 +65,27 @@ def get_iface_info(ifname):          'mac_addr': mac_addr,          'ip_addr': ip_addrs[0] if ip_addrs else '',          'ip_addrs': ip_addrs, +        'link_speed': link_speed      } + +def get_link_speed(ifname): +    """ +    Given an interface name (e.g 'eth0'), return link speed +    of that interface as unsigned interger. +    If interface is not found, IndexError will be thrown. +    The speed is Megabits/sec +    (from kernel at https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net) +    """ +    net_sysfs = [device for device in pyudev.Context().list_devices(subsystem='net') +                 if device.sys_name == ifname][0] + +    speed = net_sysfs.attributes.asint('speed') +    # TODO: 1Gige driver returns a bad value (less than 1000). Remove the conditional once the +    #       driver is fixed +    return speed if speed >= 10000 else 1000 + +  def ip_addr_to_iface(ip_addr, iface_list):      """      Return an Ethernet interface (e.g. 'eth1') given an IP address. diff --git a/mpm/python/usrp_mpm/xports/xportmgr_udp.py b/mpm/python/usrp_mpm/xports/xportmgr_udp.py index 6e355115e..40ba22414 100644 --- a/mpm/python/usrp_mpm/xports/xportmgr_udp.py +++ b/mpm/python/usrp_mpm/xports/xportmgr_udp.py @@ -255,6 +255,7 @@ class XportMgrUDP(object):                  'send_sid': str(fixup_sid(sid, iface_name)),                  'allocation': str(allocation_getter(iface_name)),                  'xport_type': xport_type, +                'link_speed': str(iface_info['link_speed'])              }              for iface_name, iface_info in iteritems(self._chdr_ifaces)          ] | 
