From 01284980b1d7227f1c11496d2be939bb4b23adb1 Mon Sep 17 00:00:00 2001 From: Alex Williams Date: Fri, 9 Aug 2019 11:18:35 -0700 Subject: transport: Add modeling of physical adapters Now link instances must have the ability to report the corresponding physical adapter that is used for the local side of the link. This information can be used to help identify when multiple links share the same adapter. --- host/lib/include/uhdlib/transport/adapter.hpp | 33 +++++++++++++++++ host/lib/include/uhdlib/transport/adapter_info.hpp | 30 ++++++++++++++++ host/lib/include/uhdlib/transport/link_if.hpp | 11 ++++++ .../uhdlib/transport/udp_boost_asio_link.hpp | 42 ++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 host/lib/include/uhdlib/transport/adapter.hpp create mode 100644 host/lib/include/uhdlib/transport/adapter_info.hpp (limited to 'host/lib/include/uhdlib/transport') diff --git a/host/lib/include/uhdlib/transport/adapter.hpp b/host/lib/include/uhdlib/transport/adapter.hpp new file mode 100644 index 000000000..3d6d49575 --- /dev/null +++ b/host/lib/include/uhdlib/transport/adapter.hpp @@ -0,0 +1,33 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHDLIB_TRANSPORT_ADAPTER_HPP +#define INCLUDED_UHDLIB_TRANSPORT_ADAPTER_HPP + +#include +#include + +namespace uhd { namespace transport { + +class adapter_ctx : uhd::noncopyable +{ +public: + UHD_SINGLETON_FCN(adapter_ctx, get); + + ~adapter_ctx() = default; + + adapter_id_t register_adapter(adapter_info& info); + +private: + adapter_ctx() = default; + + std::mutex _mutex; + std::unordered_map _id_map; +}; + +}} // namespace uhd::transport + +#endif /* INCLUDED_UHDLIB_TRANSPORT_ADAPTER_HPP */ diff --git a/host/lib/include/uhdlib/transport/adapter_info.hpp b/host/lib/include/uhdlib/transport/adapter_info.hpp new file mode 100644 index 000000000..a21551e96 --- /dev/null +++ b/host/lib/include/uhdlib/transport/adapter_info.hpp @@ -0,0 +1,30 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHDLIB_TRANSPORT_ADAPTER_INFO_HPP +#define INCLUDED_UHDLIB_TRANSPORT_ADAPTER_INFO_HPP + +#include +#include +#include +#include +#include +#include + +namespace uhd { namespace transport { + +class adapter_info +{ +public: + /*! Returns a unique string identifying the adapter + * String contents are not API. Only uniqueness is guaranteed. + */ + virtual std::string to_string() = 0; +}; + +}} // namespace uhd::transport + +#endif /* INCLUDED_UHDLIB_TRANSPORT_ADAPTER_INFO_HPP */ diff --git a/host/lib/include/uhdlib/transport/link_if.hpp b/host/lib/include/uhdlib/transport/link_if.hpp index 60376e571..6f533603e 100644 --- a/host/lib/include/uhdlib/transport/link_if.hpp +++ b/host/lib/include/uhdlib/transport/link_if.hpp @@ -4,6 +4,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later // +#include #include #include @@ -51,6 +52,11 @@ public: */ virtual void release_send_buff(frame_buff::uptr buff) = 0; + /*! + * Get the physical adapter id used for this link + */ + virtual adapter_id_t get_send_adapter_id() const = 0; + send_link_if() = default; send_link_if(const send_link_if&) = delete; send_link_if& operator=(const send_link_if&) = delete; @@ -91,6 +97,11 @@ public: */ virtual void release_recv_buff(frame_buff::uptr buff) = 0; + /*! + * Get the physical adapter ID used for this link + */ + virtual adapter_id_t get_recv_adapter_id() const = 0; + recv_link_if() = default; recv_link_if(const recv_link_if&) = delete; recv_link_if& operator=(const recv_link_if&) = delete; diff --git a/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp b/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp index 2e6f731c9..88ad6e518 100644 --- a/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp +++ b/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,29 @@ public: } }; +class udp_boost_asio_adapter_info : public adapter_info +{ +public: + udp_boost_asio_adapter_info(boost::asio::ip::udp::socket& s) + : _src_ip(s.local_endpoint().address()) {} + + ~udp_boost_asio_adapter_info() {} + + std::string to_string() + { + return std::string("Ethernet(kernel):") + _src_ip.to_string(); + } + + bool operator==(const udp_boost_asio_adapter_info& rhs) const + { + return (_src_ip == rhs._src_ip); + } + +private: + // Use source IP addr + boost::asio::ip::address _src_ip; +}; + class udp_boost_asio_link : public recv_link_base, public send_link_base { @@ -62,6 +86,22 @@ public: */ std::string get_local_addr() const; + /*! + * Get the physical adapter ID used for this link + */ + adapter_id_t get_send_adapter_id() const + { + return _adapter_id; + } + + /*! + * Get the physical adapter ID used for this link + */ + adapter_id_t get_recv_adapter_id() const + { + return _adapter_id; + } + private: using recv_link_base_t = recv_link_base; using send_link_base_t = send_link_base; @@ -108,8 +148,10 @@ private: boost::asio::io_service _io_service; std::shared_ptr _socket; int _sock_fd; + adapter_id_t _adapter_id; }; }} // namespace uhd::transport + #endif /* INCLUDED_UHD_TRANSPORT_UDP_BOOST_ASIO_LINK_HPP */ -- cgit v1.2.3