aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/include
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/include')
-rw-r--r--host/lib/include/uhdlib/transport/adapter.hpp33
-rw-r--r--host/lib/include/uhdlib/transport/adapter_info.hpp30
-rw-r--r--host/lib/include/uhdlib/transport/link_if.hpp11
-rw-r--r--host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp42
4 files changed, 116 insertions, 0 deletions
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 */