link-service.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, 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_LINK_SERVICE_HPP
27 #define NFD_DAEMON_FACE_LINK_SERVICE_HPP
28 
29 #include "face-common.hpp"
30 #include "transport.hpp"
31 #include "common/counter.hpp"
32 
33 namespace nfd::face {
34 
41 {
42 public:
57 };
58 
63 class LinkService : protected virtual LinkServiceCounters, noncopyable
64 {
65 public:
70 
71 public:
72  virtual
74 
79  void
80  setFaceAndTransport(Face& face, Transport& transport) noexcept;
81 
85  const Face*
86  getFace() const noexcept
87  {
88  return m_face;
89  }
90 
94  const Transport*
95  getTransport() const noexcept
96  {
97  return m_transport;
98  }
99 
103  Transport*
104  getTransport() noexcept
105  {
106  return m_transport;
107  }
108 
109  virtual const Counters&
110  getCounters() const
111  {
112  return *this;
113  }
114 
115  virtual ssize_t
117  {
118  return m_transport->getMtu();
119  }
120 
121 public: // upper interface to be used by forwarding
126  void
127  sendInterest(const Interest& interest);
128 
133  void
134  sendData(const Data& data);
135 
140  void
141  sendNack(const ndn::lp::Nack& nack);
142 
146  signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
147 
151  signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
152 
156  signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
157 
162  signal::Signal<LinkService, Interest> onDroppedInterest;
163 
164 public: // lower interface to be invoked by Transport
168  void
169  receivePacket(const Block& packet, const EndpointId& endpoint)
170  {
171  doReceivePacket(packet, endpoint);
172  }
173 
174 protected: // upper interface to be invoked in subclass (receive path termination)
178  void
179  receiveInterest(const Interest& interest, const EndpointId& endpoint);
180 
184  void
185  receiveData(const Data& data, const EndpointId& endpoint);
186 
190  void
191  receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
192 
193 protected: // lower interface to be invoked in subclass (send path termination)
197  void
198  sendPacket(const Block& packet)
199  {
200  m_transport->send(packet);
201  }
202 
203 protected:
204  void
205  notifyDroppedInterest(const Interest& packet);
206 
207 private: // upper interface to be overridden in subclass (send path entrypoint)
211  virtual void
212  doSendInterest(const Interest& interest) = 0;
213 
217  virtual void
218  doSendData(const Data& data) = 0;
219 
223  virtual void
224  doSendNack(const lp::Nack& nack) = 0;
225 
226 private: // lower interface to be overridden in subclass
227  virtual void
228  doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
229 
230 private:
231  Face* m_face = nullptr;
232  Transport* m_transport = nullptr;
233 };
234 
235 std::ostream&
236 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
237 
238 template<typename T>
239 std::enable_if_t<std::is_base_of_v<LinkService, T> && !std::is_same_v<LinkService, T>,
240  std::ostream&>
241 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
242 {
243  return os << FaceLogHelper<LinkService>(flh.obj);
244 }
245 
246 } // namespace nfd::face
247 
248 #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
Represents a counter of number of packets.
Definition: counter.hpp:71
Generalization of a network interface.
Definition: face.hpp:118
For internal use by FaceLogging macros.
The lower half of a Face.
Definition: transport.hpp:123
ssize_t getMtu() const noexcept
Returns the maximum payload size.
Definition: transport.hpp:279
void send(const Block &packet)
Send a link-layer packet.
Definition: transport.cpp:80
std::ostream & operator<<(std::ostream &os, const FaceLogHelper< Face > &flh)
Definition: face.cpp:63
std::variant< std::monostate, ethernet::Address, udp::Endpoint > EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:78