diff options
Diffstat (limited to 'host/lib/include/uhdlib/transport')
5 files changed, 94 insertions, 17 deletions
diff --git a/host/lib/include/uhdlib/transport/inline_io_service.hpp b/host/lib/include/uhdlib/transport/inline_io_service.hpp index f207d15a0..fe41b96b6 100644 --- a/host/lib/include/uhdlib/transport/inline_io_service.hpp +++ b/host/lib/include/uhdlib/transport/inline_io_service.hpp @@ -37,6 +37,9 @@ public: void attach_recv_link(recv_link_if::sptr link); void attach_send_link(send_link_if::sptr link); + void detach_recv_link(recv_link_if::sptr link); + void detach_send_link(send_link_if::sptr link); + recv_io_if::sptr make_recv_client(recv_link_if::sptr data_link, size_t num_recv_frames, recv_callback_t cb, @@ -102,8 +105,7 @@ private: inline_recv_cb* recv_io_cb, recv_link_if* recv_link, int32_t timeout_ms); /* Track whether link is muxed and the callback */ - std::unordered_map<recv_link_if*, - std::tuple<inline_recv_mux*, inline_recv_cb*>> + std::unordered_map<recv_link_if*, std::tuple<inline_recv_mux*, inline_recv_cb*>> _recv_tbl; /* Shared ptr kept to avoid untimely release */ diff --git a/host/lib/include/uhdlib/transport/io_service.hpp b/host/lib/include/uhdlib/transport/io_service.hpp index 69a3a523e..399b693dc 100644 --- a/host/lib/include/uhdlib/transport/io_service.hpp +++ b/host/lib/include/uhdlib/transport/io_service.hpp @@ -282,10 +282,19 @@ public: */ virtual void attach_send_link(send_link_if::sptr link) = 0; - /* TODO: Cleanup functions + /*! + * Detach a recv_link_if previously attached to this I/O service. + * + * \param link the recv_link_if to detach + */ virtual void detach_recv_link(recv_link_if::sptr link) = 0; + + /*! + * Detach a send_link_if previously attached to this I/O service. + * + * \param link the send_link_if to detach + */ virtual void detach_send_link(send_link_if::sptr link) = 0; - */ /*! * Create a send_io_if so a transport may send packets through the link. diff --git a/host/lib/include/uhdlib/transport/links.hpp b/host/lib/include/uhdlib/transport/links.hpp index 64673f02f..09872b145 100644 --- a/host/lib/include/uhdlib/transport/links.hpp +++ b/host/lib/include/uhdlib/transport/links.hpp @@ -16,8 +16,7 @@ namespace uhd { namespace transport { enum class link_type_t { CTRL = 0, ASYNC_MSG, TX_DATA, RX_DATA }; //! Contains all information regarding a link interface -using both_links_t = std::tuple<uhd::transport::io_service::sptr, - uhd::transport::send_link_if::sptr, +using both_links_t = std::tuple<uhd::transport::send_link_if::sptr, size_t, // num_send_frames uhd::transport::recv_link_if::sptr, size_t, // num_recv_frames diff --git a/host/lib/include/uhdlib/transport/offload_io_service.hpp b/host/lib/include/uhdlib/transport/offload_io_service.hpp index a7d9d211d..02231c502 100644 --- a/host/lib/include/uhdlib/transport/offload_io_service.hpp +++ b/host/lib/include/uhdlib/transport/offload_io_service.hpp @@ -8,6 +8,7 @@ #define INCLUDED_UHDLIB_TRANSPORT_OFFLOAD_IO_SERVICE_HPP #include <uhdlib/transport/io_service.hpp> +#include <vector> namespace uhd { namespace transport { @@ -21,18 +22,9 @@ namespace uhd { namespace transport { class offload_io_service : public io_service { public: - enum client_type_t - { - RECV_ONLY, - SEND_ONLY, - BOTH_SEND_AND_RECV - }; + enum client_type_t { RECV_ONLY, SEND_ONLY, BOTH_SEND_AND_RECV }; - enum wait_mode_t - { - POLL, - BLOCK - }; + enum wait_mode_t { POLL, BLOCK }; /*! * Options for configuring offload I/O service diff --git a/host/lib/include/uhdlib/transport/udp_common.hpp b/host/lib/include/uhdlib/transport/udp_common.hpp index 5f5a18c27..6c87ef498 100644 --- a/host/lib/include/uhdlib/transport/udp_common.hpp +++ b/host/lib/include/uhdlib/transport/udp_common.hpp @@ -10,7 +10,10 @@ #include <uhd/config.hpp> #include <uhd/exception.hpp> +#include <uhd/rfnoc/constants.hpp> +#include <uhd/types/device_addr.hpp> #include <uhd/utils/log.hpp> +#include <uhdlib/transport/links.hpp> #include <boost/asio.hpp> #include <boost/format.hpp> #include <thread> @@ -194,6 +197,78 @@ UHD_INLINE size_t resize_udp_socket_buffer_with_warning( return actual_size; } +/*! + * Determines a set of values to use for a UDP CHDR link based on defaults and + * any overrides that the user may have provided. In cases where both device + * and stream arguments can be used to override a value, note that the stream + * argument will always take precedence. + * + * \param link_type the link type (CTRL, RX, TX) to calculate parameters for + * \param send_mtu the MTU of link for Tx cases + * \param recv_mtu the MTU of link for Rx cases + * \param default_link_params default values to use for the link parameters + * \param device_args device-level argument dictionary for overrides + * \param link_args argument dictionary with stream-level overrides (come from + * stream params) + * \return Parameters to apply + */ +inline link_params_t calculate_udp_link_params( + const uhd::transport::link_type_t link_type, + const size_t send_mtu, + const size_t recv_mtu, + const link_params_t& default_link_params, + const uhd::device_addr_t& device_args, + const uhd::device_addr_t& link_args) +{ + // Apply any device-level overrides to the default values first. + // If the MTU is overridden, it will be capped to the value provided by + // the caller. + const size_t constrained_send_mtu = + std::min(send_mtu, device_args.cast<size_t>("mtu", send_mtu)); + const size_t constrained_recv_mtu = + std::min(recv_mtu, device_args.cast<size_t>("mtu", recv_mtu)); + + link_params_t link_params; + link_params.num_send_frames = + device_args.cast<size_t>("num_send_frames", default_link_params.num_send_frames); + link_params.num_recv_frames = + device_args.cast<size_t>("num_recv_frames", default_link_params.num_recv_frames); + link_params.send_frame_size = + device_args.cast<size_t>("send_frame_size", default_link_params.send_frame_size); + link_params.recv_frame_size = + device_args.cast<size_t>("recv_frame_size", default_link_params.recv_frame_size); + link_params.send_buff_size = + device_args.cast<size_t>("send_buff_size", default_link_params.send_buff_size); + link_params.recv_buff_size = + device_args.cast<size_t>("recv_buff_size", default_link_params.recv_buff_size); + + // Now apply stream-level overrides based on the link type. + if (link_type == link_type_t::CTRL) { + // Control links typically do not allow the number of frames to be + // configured. + link_params.num_recv_frames = + uhd::rfnoc::CMD_FIFO_SIZE / uhd::rfnoc::MAX_CMD_PKT_SIZE; + } else if (link_type == link_type_t::TX_DATA) { + // Note that the send frame size will be capped to the Tx MTU. + link_params.send_frame_size = link_args.cast<size_t>("send_frame_size", + std::min(link_params.send_frame_size, constrained_send_mtu)); + link_params.num_send_frames = + link_args.cast<size_t>("num_send_frames", link_params.num_send_frames); + link_params.send_buff_size = + link_args.cast<size_t>("send_buff_size", link_params.send_buff_size); + } else if (link_type == link_type_t::RX_DATA) { + // Note that the receive frame size will be capped to the Rx MTU. + link_params.recv_frame_size = link_args.cast<size_t>("recv_frame_size", + std::min(link_params.recv_frame_size, constrained_recv_mtu)); + link_params.num_recv_frames = + link_args.cast<size_t>("num_recv_frames", link_params.num_recv_frames); + link_params.recv_buff_size = + link_args.cast<size_t>("recv_buff_size", link_params.recv_buff_size); + } + + return link_params; +} + }} // namespace uhd::transport |