multicast-udp-transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_FACE_MULTICAST_UDP_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_MULTICAST_UDP_TRANSPORT_HPP
28 
29 #include "datagram-transport.hpp"
30 
31 #include <boost/asio/ip/udp.hpp>
32 #include <ndn-cxx/net/network-interface.hpp>
33 
34 namespace nfd::face {
35 
36 NFD_LOG_MEMBER_DECL_SPECIALIZED((DatagramTransport<boost::asio::ip::udp, Multicast>));
37 
41 class MulticastUdpTransport final : public DatagramTransport<boost::asio::ip::udp, Multicast>
42 {
43 public:
44  class Error : public std::runtime_error
45  {
46  public:
47  using std::runtime_error::runtime_error;
48  };
49 
57  MulticastUdpTransport(const boost::asio::ip::udp::endpoint& multicastGroup,
58  boost::asio::ip::udp::socket&& recvSocket,
59  boost::asio::ip::udp::socket&& sendSocket,
60  ndn::nfd::LinkType linkType);
61 
62  ssize_t
63  getSendQueueLength() final;
64 
68  static void
69  openRxSocket(boost::asio::ip::udp::socket& sock,
70  const boost::asio::ip::udp::endpoint& multicastGroup,
71  const boost::asio::ip::address& localAddress = {},
72  const ndn::net::NetworkInterface* netif = nullptr);
73 
77  static void
78  openTxSocket(boost::asio::ip::udp::socket& sock,
79  const boost::asio::ip::udp::endpoint& localEndpoint,
80  const ndn::net::NetworkInterface* netif = nullptr,
81  bool enableLoopback = false);
82 
83 private:
84  void
85  doSend(const Block& packet) final;
86 
87  void
88  doClose() final;
89 
90 private:
91  boost::asio::ip::udp::endpoint m_multicastGroup;
92  boost::asio::ip::udp::socket m_sendSocket;
93 };
94 
95 } // namespace nfd::face
96 
97 #endif // NFD_DAEMON_FACE_MULTICAST_UDP_TRANSPORT_HPP
Implements a Transport for datagram-based protocols.
A Transport that communicates on a UDP multicast group.
MulticastUdpTransport(const boost::asio::ip::udp::endpoint &multicastGroup, boost::asio::ip::udp::socket &&recvSocket, boost::asio::ip::udp::socket &&sendSocket, ndn::nfd::LinkType linkType)
Creates a UDP-based transport for multicast communication.
static void openRxSocket(boost::asio::ip::udp::socket &sock, const boost::asio::ip::udp::endpoint &multicastGroup, const boost::asio::ip::address &localAddress={}, const ndn::net::NetworkInterface *netif=nullptr)
Opens and configures the receive-side socket.
ssize_t getSendQueueLength() final
Returns the current send queue length of the transport (in octets).
static void openTxSocket(boost::asio::ip::udp::socket &sock, const boost::asio::ip::udp::endpoint &localEndpoint, const ndn::net::NetworkInterface *netif=nullptr, bool enableLoopback=false)
Opens and configures the transmit-side socket.
#define NFD_LOG_MEMBER_DECL_SPECIALIZED(cls)
Definition: logger.hpp:33