From 852bf3aa10613e80a8b9434b2d69f967b53a2d97 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 8 Jan 2018 19:23:28 -0800 Subject: mpm: n310: Return CHDR addresses as part of device_info Reviewed-by: Brent Stapleton --- mpm/python/usrp_mpm/periph_manager/base.py | 18 +++++++++++++++++- mpm/python/usrp_mpm/periph_manager/n310.py | 10 ++++++++++ mpm/python/usrp_mpm/xports/xportmgr_liberio.py | 12 ++++++++++++ mpm/python/usrp_mpm/xports/xportmgr_udp.py | 17 +++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index 303f7e805..69a20c369 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -407,12 +407,28 @@ class PeriphManagerBase(object): @no_rpc def get_device_info(self): """ - return the mboard_info dict and add a claimed field + Return the mboard_info dict and add a claimed field. + + Will also call into get_device_info_dyn() for additional information. + Don't override this function. """ result = {"claimed": str(self.claimed)} result.update(self.mboard_info) + result.update(self.get_device_info_dyn()) return result + @no_rpc + def get_device_info_dyn(self): + """ + "Dynamic" device info getter. When get_device_info() is called, it + will also call into this function to see if there is 'dynamic' info + that needs to be returned. The reason to split up these functions is + because we don't want anyone to override get_device_info(), but we do + want periph managers to be able to inject custom device info data. + """ + self.log.trace("Called get_device_info_dyn(), but not implemented.") + return {} + @no_rpc def set_connection_type(self, conn_type): """ diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 899710475..be18228a1 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -688,6 +688,16 @@ class n310(PeriphManagerBase): elif self.mboard_info['rpc_connection'] == 'local': return self._xport_mgrs['liberio'].commit_xport(sid, xport_info) + ########################################################################### + # Device info + ########################################################################### + def get_device_info_dyn(self): + """ + Append the device info with current IP addresses. + """ + return self._xport_mgrs['udp'].get_xport_info() \ + if self._device_initialized else {} + ########################################################################### # Clock/Time API ########################################################################### diff --git a/mpm/python/usrp_mpm/xports/xportmgr_liberio.py b/mpm/python/usrp_mpm/xports/xportmgr_liberio.py index 8ac2f06f3..f1e9fe2de 100644 --- a/mpm/python/usrp_mpm/xports/xportmgr_liberio.py +++ b/mpm/python/usrp_mpm/xports/xportmgr_liberio.py @@ -38,6 +38,18 @@ class XportMgrLiberio(object): " Clean up after a session terminates " self._data_chan_ctr = 0 + def get_xport_info(self): + """ + Returns a dictionary of useful information, e.g. for appending into the + device info. + + Note: This can be run by callers not owning a claim, even when the + device has been claimed by someone else. + + In this case, returns an empty dict. + """ + return {} + def request_xport( self, sid, diff --git a/mpm/python/usrp_mpm/xports/xportmgr_udp.py b/mpm/python/usrp_mpm/xports/xportmgr_udp.py index dd783e132..5e565ba86 100644 --- a/mpm/python/usrp_mpm/xports/xportmgr_udp.py +++ b/mpm/python/usrp_mpm/xports/xportmgr_udp.py @@ -112,6 +112,23 @@ class XportMgrUDP(object): " Clean up after a session terminates " self._allocations = {} + def get_xport_info(self): + """ + Returns a dictionary of useful information, e.g. for appending into the + device info. + + Note: This can be run by callers not owning a claim, even when the + device has been claimed by someone else. + + In this case, returns the available IP addresses. + """ + available_interfaces = \ + self._init_interfaces(self._possible_chdr_ifaces) + return dict(zip( + ("addr", "second_addr", "third_addr", "fourth_addr"), + (x['ip_addr'] for x in itervalues(available_interfaces)) + )) + def _preload_ethtables(self, eth_dispatchers, table_file): """ Populates the ethernet tables from a JSON file -- cgit v1.2.3