diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-12-01 16:14:11 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:05:58 -0800 |
commit | 87dbcd9f1a5b2b464c27af56c3a91ab00f66c441 (patch) | |
tree | 62ccd5be210d94862071aecda5ec3e667b036148 /host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp | |
parent | a927a364c5b07387be3a849b74546b98ba84db84 (diff) | |
download | uhd-87dbcd9f1a5b2b464c27af56c3a91ab00f66c441.tar.gz uhd-87dbcd9f1a5b2b464c27af56c3a91ab00f66c441.tar.bz2 uhd-87dbcd9f1a5b2b464c27af56c3a91ab00f66c441.zip |
mpmd: Refactor MPM transport architecture, use managers
This splits up the transport code in mpmd_impl across multiple classes
to properly leverage the request_xport/commit_xport API in MPM.
Different types of transport (UDP, liberio) use their own distinct
classes, which are generated dynamically on request.
This is a true refactoring despite the large amount of changes; there
are no functional differences.
Reviewed-By: Brent Stapleton <brent.stapleton@ettus.com>
Reviewed-By: Trung Tran <trung.tran@ettus.com>
Reviewed-By: Ashish Chaudhari <ashish.chaudhari@ettus.com>
Diffstat (limited to 'host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp')
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp b/host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp new file mode 100644 index 000000000..de4b3bbba --- /dev/null +++ b/host/lib/usrp/mpmd/mpmd_xport_ctrl_udp.cpp @@ -0,0 +1,103 @@ +// +// Copyright 2017 Ettus Research, National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "mpmd_xport_mgr.hpp" +#include "mpmd_xport_ctrl_udp.hpp" +#include <uhd/transport/udp_zero_copy.hpp> + +using namespace uhd; +using namespace uhd::mpmd::xport; + +namespace { + + #if defined(UHD_PLATFORM_MACOS) || defined(UHD_PLATFORM_BSD) + const size_t MPMD_RX_SW_BUFF_SIZE_ETH = 0x100000; // 1Mib + #elif defined(UHD_PLATFORM_LINUX) || defined(UHD_PLATFORM_WIN32) + //For an ~8k frame size any size >32MiB is just wasted buffer space: + const size_t MPMD_RX_SW_BUFF_SIZE_ETH = 0x2000000; // 32 MiB + #endif + + const size_t MPMD_10GE_DATA_FRAME_MAX_SIZE = 8000; // CHDR packet size in bytes + + std::vector<std::string> get_addrs_from_mb_args( + const uhd::device_addr_t& mb_args + ) { + // mb_args must always include addr + std::vector<std::string> addrs{mb_args["addr"]}; + if (mb_args.has_key("second_addr")){ + addrs.push_back(mb_args["second_addr"]); + } + return addrs; + } +} + + +mpmd_xport_ctrl_udp::mpmd_xport_ctrl_udp( + const uhd::device_addr_t& mb_args +) : _mb_args(mb_args) + , _recv_args(filter_args(mb_args, "recv")) + , _send_args(filter_args(mb_args, "send")) + , _available_addrs(get_addrs_from_mb_args(mb_args)) +{ +} + +uhd::both_xports_t +mpmd_xport_ctrl_udp::make_transport( + mpmd_xport_mgr::xport_info_t &xport_info, + const usrp::device3_impl::xport_type_t xport_type, + const uhd::device_addr_t& xport_args_ +) { + auto xport_args = xport_args_; + + if (xport_type == usrp::device3_impl::RX_DATA + and not xport_args.has_key("recv_buff_size")) { + xport_args["recv_buff_size"] = + std::to_string(MPMD_RX_SW_BUFF_SIZE_ETH); + } + + transport::zero_copy_xport_params default_buff_args; + // Create actual UDP transport + // TODO don't hardcode these + default_buff_args.send_frame_size = 8000; + default_buff_args.recv_frame_size = 8000; + default_buff_args.num_recv_frames = 32; + default_buff_args.num_send_frames = 32; + + transport::udp_zero_copy::buff_params buff_params; + auto recv = transport::udp_zero_copy::make( + xport_info["ipv4"], + xport_info["port"], + default_buff_args, + buff_params, + xport_args + ); + const uint16_t port = recv->get_local_port(); + const std::string src_ip_addr = recv->get_local_addr(); + xport_info["src_port"] = std::to_string(port); + xport_info["src_ipv4"] = src_ip_addr; + + // Create both_xports_t object and finish: + both_xports_t xports; + xports.endianness = uhd::ENDIANNESS_BIG; + xports.send_sid = sid_t(xport_info["send_sid"]); + xports.recv_sid = xports.send_sid.reversed(); + xports.recv_buff_size = buff_params.recv_buff_size; + xports.send_buff_size = buff_params.send_buff_size; + xports.recv = recv; // Note: This is a type cast! + xports.send = recv; // This too + return xports; +} + +bool mpmd_xport_ctrl_udp::is_valid( + const mpmd_xport_mgr::xport_info_t& xport_info +) const { + return std::find( + _available_addrs.cbegin(), + _available_addrs.cend(), + xport_info.at("ipv4") + ) != _available_addrs.cend(); +} + |