mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
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.
This commit is contained in:
parent
807e19c107
commit
54990c55f8
@ -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
|
||||
|
||||
@ -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
|
||||
###########################################################################
|
||||
|
||||
@ -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
|
||||
@ -333,40 +319,6 @@ class e320(ZynqComponents, PeriphManagerBase):
|
||||
for overlay in active_overlays:
|
||||
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
|
||||
###########################################################################
|
||||
|
||||
@ -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
|
||||
@ -487,38 +472,6 @@ class n3xx(ZynqComponents, PeriphManagerBase):
|
||||
for overlay in active_overlays:
|
||||
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
|
||||
###########################################################################
|
||||
|
||||
@ -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
|
||||
###########################################################################
|
||||
|
||||
Loading…
Reference in New Issue
Block a user