diff options
| -rw-r--r-- | host/include/uhd/transport/adapter_id.hpp | 21 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/transport/adapter.hpp | 33 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/transport/adapter_info.hpp | 30 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/transport/link_if.hpp | 11 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp | 42 | ||||
| -rw-r--r-- | host/lib/transport/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | host/lib/transport/adapter.cpp | 24 | ||||
| -rw-r--r-- | host/lib/transport/udp_boost_asio_link.cpp | 13 | ||||
| -rw-r--r-- | host/tests/common/mock_link.hpp | 10 | 
9 files changed, 180 insertions, 5 deletions
| diff --git a/host/include/uhd/transport/adapter_id.hpp b/host/include/uhd/transport/adapter_id.hpp new file mode 100644 index 000000000..02041bc4c --- /dev/null +++ b/host/include/uhd/transport/adapter_id.hpp @@ -0,0 +1,21 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHD_TRANSPORT_ADAPTER_ID_HPP +#define INCLUDED_UHD_TRANSPORT_ADAPTER_ID_HPP + +#include <cstddef> + +namespace uhd { namespace transport { + +//! Host transport adapter ID +using adapter_id_t = size_t; +//! NULL/unassigned host transport adapter ID +static const adapter_id_t NULL_ADAPTER_ID = 0; + +}} // namespace uhd::transport + +#endif /* INCLUDED_UHD_TRANSPORT_ADAPTER_ID_HPP */ 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 <uhdlib/transport/adapter_info.hpp> +#include <uhdlib/transport/udp_boost_asio_link.hpp> + +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<std::string, adapter_id_t> _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 <uhd/transport/adapter_id.hpp> +#include <uhd/utils/noncopyable.hpp> +#include <uhd/utils/static.hpp> +#include <unordered_map> +#include <memory> +#include <mutex> + +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 <uhd/transport/adapter_id.hpp>  #include <uhd/transport/frame_buff.hpp>  #include <memory> @@ -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 <uhd/config.hpp>  #include <uhd/transport/buffer_pool.hpp>  #include <uhd/types/device_addr.hpp> +#include <uhdlib/transport/adapter_info.hpp>  #include <uhdlib/transport/link_base.hpp>  #include <uhdlib/transport/links.hpp>  #include <uhdlib/transport/udp_common.hpp> @@ -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<udp_boost_asio_link>,                              public send_link_base<udp_boost_asio_link>  { @@ -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<udp_boost_asio_link>;      using send_link_base_t = send_link_base<udp_boost_asio_link>; @@ -108,8 +148,10 @@ private:      boost::asio::io_service _io_service;      std::shared_ptr<boost::asio::ip::udp::socket> _socket;      int _sock_fd; +    adapter_id_t _adapter_id;  };  }} // namespace uhd::transport +  #endif /* INCLUDED_UHD_TRANSPORT_UDP_BOOST_ASIO_LINK_HPP */ diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 003beeee4..dd83164bf 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -124,6 +124,7 @@ LIBUHD_APPEND_SOURCES(      ${CMAKE_CURRENT_SOURCE_DIR}/muxed_zero_copy_if.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/zero_copy_flow_ctrl.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/inline_io_service.cpp +    ${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp  )  if(ENABLE_X300) diff --git a/host/lib/transport/adapter.cpp b/host/lib/transport/adapter.cpp new file mode 100644 index 000000000..247b33868 --- /dev/null +++ b/host/lib/transport/adapter.cpp @@ -0,0 +1,24 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include <uhd/exception.hpp> +#include <uhdlib/transport/adapter.hpp> + +using namespace uhd::transport; + +adapter_id_t adapter_ctx::register_adapter(adapter_info& info) +{ +    std::lock_guard<std::mutex> lock(_mutex); +    auto key = info.to_string(); +    if (_id_map.count(key) > 0) { +        return _id_map.at(key); +    } else { +        adapter_id_t id = _id_map.size() + 1; +        _id_map.emplace(std::make_pair(key, id)); +        return id; +    } +} + diff --git a/host/lib/transport/udp_boost_asio_link.cpp b/host/lib/transport/udp_boost_asio_link.cpp index 95d68ba91..2d4a4f640 100644 --- a/host/lib/transport/udp_boost_asio_link.cpp +++ b/host/lib/transport/udp_boost_asio_link.cpp @@ -5,6 +5,7 @@  //  #include <uhd/utils/log.hpp> +#include <uhdlib/transport/adapter.hpp>  #include <uhdlib/transport/udp_boost_asio_link.hpp>  #include <boost/format.hpp> @@ -39,10 +40,13 @@ udp_boost_asio_link::udp_boost_asio_link(      _socket  = open_udp_socket(addr, port, _io_service);      _sock_fd = _socket->native_handle(); -    UHD_LOGGER_TRACE("UDP") -        << boost::format("Created UDP link to %s:%s") % addr % port; +    auto info   = udp_boost_asio_adapter_info(*_socket); +    auto& ctx   = adapter_ctx::get(); +    _adapter_id = ctx.register_adapter(info); + +    UHD_LOGGER_TRACE("UDP") << boost::format("Created UDP link to %s:%s") % addr % port;      UHD_LOGGER_TRACE("UDP") << boost::format("Local UDP socket endpoint: %s:%s") -        % get_local_addr() % get_local_port(); +                                   % get_local_addr() % get_local_port();  }  uint16_t udp_boost_asio_link::get_local_port() const @@ -91,8 +95,7 @@ udp_boost_asio_link::sptr udp_boost_asio_link::make(const std::string& addr,      }  #endif -    udp_boost_asio_link::sptr link( -        new udp_boost_asio_link(addr, port, params)); +    udp_boost_asio_link::sptr link(new udp_boost_asio_link(addr, port, params));      // call the helper to resize send and recv buffers diff --git a/host/tests/common/mock_link.hpp b/host/tests/common/mock_link.hpp index 73a65916c..a62aa49c7 100644 --- a/host/tests/common/mock_link.hpp +++ b/host/tests/common/mock_link.hpp @@ -128,6 +128,11 @@ public:          _simulate_io_timeout = simulate_io_timeout;      } +    adapter_id_t get_send_adapter_id() const +    { +        return NULL_ADAPTER_ID; +    } +  private:      // Friend declaration to allow base class to call private methods      friend base_t; @@ -223,6 +228,11 @@ public:          _rx_lens.push_back(len);      } +    adapter_id_t get_recv_adapter_id() const +    { +        return NULL_ADAPTER_ID; +    } +  private:      // Friend declaration to allow base class to call private methods      friend base_t; | 
