diff options
author | Martin Braun <martin.braun@ettus.com> | 2022-07-04 14:33:51 +0200 |
---|---|---|
committer | skooNI <60897865+skooNI@users.noreply.github.com> | 2022-07-20 15:57:20 -0500 |
commit | 54990c55f8ca4568c3281325636f15d02bb31f3f (patch) | |
tree | e2b5d06fd327ba21ead9ebf5ae54094898c45b21 /mpm/python | |
parent | 807e19c107fcc316988b8f58a16a5b5613d3354f (diff) | |
download | uhd-54990c55f8ca4568c3281325636f15d02bb31f3f.tar.gz uhd-54990c55f8ca4568c3281325636f15d02bb31f3f.tar.bz2 uhd-54990c55f8ca4568c3281325636f15d02bb31f3f.zip |
mpm: Factor out transport API into PeriphManagerBase
All MPM devices use identical implementations of the transport API.
Minor differences between the actual lines of code in the various
transport adapters are due to minor optimizations, such as hard-coding
'udp' as the only valid transport type for the N3xx series.
This change moves the implementation of the transport API calls
(get_chdr_link_options() and get_chdr_link_types()) into
PeriphManagerBase. The class attributes _xport_adapter_mgrs is also
declared in that class, but defining them is left up to the individual
device implementations.
Diffstat (limited to 'mpm/python')
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 24 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/e31x.py | 29 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/e320.py | 48 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n3xx.py | 49 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/x4xx.py | 37 |
5 files changed, 19 insertions, 168 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index 729952c33..4bde831a0 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -8,14 +8,11 @@ Mboard implementation base class """ -from __future__ import print_function import os from enum import Enum from hashlib import md5 from time import sleep from concurrent import futures -from builtins import str -from builtins import object from six import iteritems, itervalues from usrp_mpm.mpmlog import get_logger from usrp_mpm.sys_utils.filesystem_status import get_fs_version @@ -51,7 +48,7 @@ def get_dboard_class_from_pid(pid): # pylint: disable=no-self-use # pylint: disable=too-many-public-methods # pylint: disable=too-many-instance-attributes -class PeriphManagerBase(object): +class PeriphManagerBase: """" Base class for all motherboards. Common function and API calls should be implemented here. Motherboard specific information can be stored in @@ -243,6 +240,9 @@ class PeriphManagerBase(object): assert self.mboard_eeprom_magic is not None self.dboards = [] self._default_args = "" + # CHDR transport managers. These need to be instantiated by the child + # classes. + self._xport_mgrs = {} # Set up logging self.log = get_logger('PeriphManager') self.claimed = False @@ -730,6 +730,8 @@ class PeriphManagerBase(object): self.log.error( "Cannot run init(), device was never fully initialized!") return False + for xport_mgr in self._xport_mgrs.values(): + xport_mgr.init(args) if not self.dboards: return True if args.get("serialize_init", False): @@ -761,6 +763,8 @@ class PeriphManagerBase(object): for slot, dboard in enumerate(self.dboards): self.log.trace("call deinit() on dBoard in slot {}".format(slot)) dboard.deinit() + for xport_mgr in self._xport_mgrs.values(): + xport_mgr.deinit() def tear_down(self): """ @@ -1090,7 +1094,7 @@ class PeriphManagerBase(object): the keys returned from this function can be used with get_chdr_link_options(). """ - raise NotImplementedError("get_chdr_link_types() not implemented.") + return list(self._xport_mgrs.keys()) def get_chdr_link_options(self, xport_type): """ @@ -1106,7 +1110,15 @@ class PeriphManagerBase(object): - link_rate (bps of the link, e.g. 10e9 for 10GigE) """ - raise NotImplementedError("get_chdr_link_options() not implemented.") + if xport_type not in self._xport_mgrs: + self.log.warning( + f"Can't get link options for unknown link type: `{xport_type}'.") + return [] + if xport_type == "udp": + return self._xport_mgrs[xport_type].get_chdr_link_options( + self.mboard_info['rpc_connection']) + # else: + return self._xport_mgrs[xport_type].get_chdr_link_options() ####################################################################### # Claimer API diff --git a/mpm/python/usrp_mpm/periph_manager/e31x.py b/mpm/python/usrp_mpm/periph_manager/e31x.py index 4d5e8f3cd..beda96822 100644 --- a/mpm/python/usrp_mpm/periph_manager/e31x.py +++ b/mpm/python/usrp_mpm/periph_manager/e31x.py @@ -393,8 +393,6 @@ class e31x(ZynqComponents, PeriphManagerBase): self._do_not_reload = \ str2bool(args.get("no_reload_fpga")) or args.get("no_reload_fpga") == "" result = super(e31x, self).init(args) - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.init(args) return result def apply_idle_overlay(self): @@ -434,8 +432,6 @@ class e31x(ZynqComponents, PeriphManagerBase): "Cannot run deinit(), device was never fully initialized!") return super(e31x, self).deinit() - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.deinit() if not self._do_not_reload: self.tear_down() # Reset back to value from _default_args (mpm.conf) @@ -473,31 +469,6 @@ class e31x(ZynqComponents, PeriphManagerBase): self.log.trace("Found idle overlay: %s", idle_overlay) return is_idle - - ########################################################################### - # Transport API - ########################################################################### - def get_chdr_link_types(self): - """ - See PeriphManagerBase.get_chdr_link_types() for docs. - """ - assert self.mboard_info['rpc_connection'] in ('remote', 'local') - return ["udp"] - - def get_chdr_link_options(self, xport_type): - """ - See PeriphManagerBase.get_chdr_link_options() for docs. - """ - if xport_type not in self._xport_mgrs: - self.log.warning("Can't get link options for unknown link type: `{}'." - .format(xport_type)) - return [] - if xport_type == "udp": - return self._xport_mgrs[xport_type].get_chdr_link_options( - self.mboard_info['rpc_connection']) - # else: - return self._xport_mgrs[xport_type].get_chdr_link_options() - ########################################################################### # Device info ########################################################################### diff --git a/mpm/python/usrp_mpm/periph_manager/e320.py b/mpm/python/usrp_mpm/periph_manager/e320.py index c06ba897a..15a8284a7 100644 --- a/mpm/python/usrp_mpm/periph_manager/e320.py +++ b/mpm/python/usrp_mpm/periph_manager/e320.py @@ -302,22 +302,8 @@ class e320(ZynqComponents, PeriphManagerBase): self.set_clock_source(args.get("clock_source", E320_DEFAULT_CLOCK_SOURCE)) self.set_time_source(args.get("time_source", E320_DEFAULT_TIME_SOURCE)) result = super(e320, self).init(args) - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.init(args) return result - def deinit(self): - """ - Clean up after a UHD session terminates. - """ - if not self._device_initialized: - self.log.warning( - "Cannot run deinit(), device was never fully initialized!") - return - super(e320, self).deinit() - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.deinit() - def tear_down(self): """ Tear down all members that need to be specially handled before @@ -334,40 +320,6 @@ class e320(ZynqComponents, PeriphManagerBase): dtoverlay.rm_overlay(overlay) ########################################################################### - # Transport API - ########################################################################### - def get_chdr_link_types(self): - """ - This will only ever return a single item (udp). - """ - assert self.mboard_info['rpc_connection'] in ('remote', 'local') - return ["udp"] - - def get_chdr_link_options(self, xport_type): - """ - Returns a list of dictionaries. Every dictionary contains information - about one way to connect to this device in order to initiate CHDR - traffic. - - The interpretation of the return value is very highly dependant on the - transport type (xport_type). - For UDP, the every entry of the list has the following keys: - - ipv4 (IP Address) - - port (UDP port) - - link_rate (bps of the link, e.g. 10e9 for 10GigE) - - """ - if xport_type not in self._xport_mgrs: - self.log.warning("Can't get link options for unknown link type: `{}'." - .format(xport_type)) - return [] - if xport_type == "udp": - return self._xport_mgrs[xport_type].get_chdr_link_options( - self.mboard_info['rpc_connection']) - # else: - return self._xport_mgrs[xport_type].get_chdr_link_options() - - ########################################################################### # Device info ########################################################################### def get_device_info_dyn(self): diff --git a/mpm/python/usrp_mpm/periph_manager/n3xx.py b/mpm/python/usrp_mpm/periph_manager/n3xx.py index 6800d356b..3e502be4e 100644 --- a/mpm/python/usrp_mpm/periph_manager/n3xx.py +++ b/mpm/python/usrp_mpm/periph_manager/n3xx.py @@ -7,12 +7,11 @@ N3xx implementation module """ -from __future__ import print_function import copy import re import threading import time -from six import iteritems, itervalues +from six import iteritems from usrp_mpm.cores import WhiteRabbitRegsControl from usrp_mpm.components import ZynqComponents from usrp_mpm.gpsd_iface import GPSDIfaceExtension @@ -451,22 +450,8 @@ class n3xx(ZynqComponents, PeriphManagerBase): 'pps_export', N3XX_DEFAULT_ENABLE_PPS_EXPORT )) - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.init(args) return result - def deinit(self): - """ - Clean up after a UHD session terminates. - """ - if not self._device_initialized: - self.log.warning( - "Cannot run deinit(), device was never fully initialized!") - return - super(n3xx, self).deinit() - for xport_mgr in itervalues(self._xport_mgrs): - xport_mgr.deinit() - def tear_down(self): """ Tear down all members that need to be specially handled before @@ -488,38 +473,6 @@ class n3xx(ZynqComponents, PeriphManagerBase): dtoverlay.rm_overlay(overlay) ########################################################################### - # Transport API - ########################################################################### - def get_chdr_link_types(self): - """ - This will only ever return a single item (udp). - """ - assert self.mboard_info['rpc_connection'] in ('remote', 'local') - return ["udp"] - - def get_chdr_link_options(self, xport_type): - """ - Returns a list of dictionaries. Every dictionary contains information - about one way to connect to this device in order to initiate CHDR - traffic. - - The interpretation of the return value is very highly dependant on the - transport type (xport_type). - For UDP, the every entry of the list has the following keys: - - ipv4 (IP Address) - - port (UDP port) - - link_rate (bps of the link, e.g. 10e9 for 10GigE) - """ - if xport_type not in self._xport_mgrs: - self.log.warning("Can't get link options for unknown link type: `{}'.".format(xport_type)) - return [] - if xport_type == "udp": - return self._xport_mgrs[xport_type].get_chdr_link_options( - self.mboard_info['rpc_connection']) - else: - return self._xport_mgrs[xport_type].get_chdr_link_options() - - ########################################################################### # Device info ########################################################################### def get_device_info_dyn(self): diff --git a/mpm/python/usrp_mpm/periph_manager/x4xx.py b/mpm/python/usrp_mpm/periph_manager/x4xx.py index fdebaeb3c..8f364b0ef 100644 --- a/mpm/python/usrp_mpm/periph_manager/x4xx.py +++ b/mpm/python/usrp_mpm/periph_manager/x4xx.py @@ -664,8 +664,6 @@ class x4xx(ZynqComponents, PeriphManagerBase): args.get('trig_direction', X400_DEFAULT_TRIG_DIRECTION) ) - for xport_mgr in self._xport_mgrs.values(): - xport_mgr.init(args) return result def deinit(self): @@ -685,8 +683,6 @@ class x4xx(ZynqComponents, PeriphManagerBase): self.set_sync_source(source) super(x4xx, self).deinit() self.ctrlport_regs.deinit() - for xport_mgr in self._xport_mgrs.values(): - xport_mgr.deinit() def tear_down(self): """ @@ -714,39 +710,6 @@ class x4xx(ZynqComponents, PeriphManagerBase): )) for overlay in active_overlays: dtoverlay.rm_overlay(overlay) - - ########################################################################### - # Transport API - ########################################################################### - def get_chdr_link_types(self): - """ - Return a list of ways how UHD can connect to the X4xx. See - PeriphManagerBase.get_chdr_link_types() for more docs. - """ - return list(self._xport_mgrs.keys()) - - def get_chdr_link_options(self, xport_type): - """ - Returns a list of dictionaries. Every dictionary contains information - about one way to connect to this device in order to initiate CHDR - traffic. - - The interpretation of the return value is very highly dependant on the - transport type (xport_type). - For UDP, the every entry of the list has the following keys: - - ipv4 (IP Address) - - port (UDP port) - - link_rate (bps of the link, e.g. 10e9 for 10GigE) - """ - if xport_type not in self._xport_mgrs: - self.log.warning("Can't get link options for unknown link type: `{}'.") - return [] - if xport_type == "udp": - return self._xport_mgrs[xport_type].get_chdr_link_options( - self.mboard_info['rpc_connection']) - # else: - return self._xport_mgrs[xport_type].get_chdr_link_options() - ########################################################################### # Device info ########################################################################### |