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-2022, 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 
40 {
41 public:
45 
49 
53 
57 
61 
65 
69 };
70 
75 class LinkService : protected virtual LinkServiceCounters, noncopyable
76 {
77 public:
82 
83 public:
84  virtual
86 
91  void
92  setFaceAndTransport(Face& face, Transport& transport) noexcept;
93 
97  const Face*
98  getFace() const noexcept
99  {
100  return m_face;
101  }
102 
106  const Transport*
107  getTransport() const noexcept
108  {
109  return m_transport;
110  }
111 
115  Transport*
116  getTransport() noexcept
117  {
118  return m_transport;
119  }
120 
121  virtual const Counters&
122  getCounters() const
123  {
124  return *this;
125  }
126 
127  virtual ssize_t
128  getEffectiveMtu() const;
129 
130 public: // upper interface to be used by forwarding
134  void
135  sendInterest(const Interest& interest);
136 
140  void
141  sendData(const Data& data);
142 
146  void
147  sendNack(const ndn::lp::Nack& nack);
148 
151  signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
152 
155  signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
156 
159  signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
160 
163  signal::Signal<LinkService, Interest> onDroppedInterest;
164 
165 public: // lower interface to be invoked by Transport
168  void
169  receivePacket(const Block& packet, const EndpointId& endpoint);
170 
171 protected: // upper interface to be invoked in subclass (receive path termination)
174  void
175  receiveInterest(const Interest& interest, const EndpointId& endpoint);
176 
179  void
180  receiveData(const Data& data, const EndpointId& endpoint);
181 
184  void
185  receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
186 
187 protected: // lower interface to be invoked in subclass (send path termination)
190  void
191  sendPacket(const Block& packet);
192 
193 protected:
194  void
195  notifyDroppedInterest(const Interest& packet);
196 
197 private: // upper interface to be overridden in subclass (send path entrypoint)
200  virtual void
201  doSendInterest(const Interest& interest) = 0;
202 
205  virtual void
206  doSendData(const Data& data) = 0;
207 
210  virtual void
211  doSendNack(const lp::Nack& nack) = 0;
212 
213 private: // lower interface to be overridden in subclass
214  virtual void
215  doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
216 
217 private:
218  Face* m_face = nullptr;
219  Transport* m_transport = nullptr;
220 };
221 
222 inline ssize_t
224 {
225  return m_transport->getMtu();
226 }
227 
228 inline void
229 LinkService::receivePacket(const Block& packet, const EndpointId& endpoint)
230 {
231  doReceivePacket(packet, endpoint);
232 }
233 
234 inline void
235 LinkService::sendPacket(const Block& packet)
236 {
237  m_transport->send(packet);
238 }
239 
240 std::ostream&
241 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
242 
243 template<typename T>
244 std::enable_if_t<std::is_base_of_v<LinkService, T> && !std::is_same_v<LinkService, T>,
245  std::ostream&>
246 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
247 {
248  return os << FaceLogHelper<LinkService>(flh.obj);
249 }
250 
251 } // namespace nfd::face
252 
253 #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
Represents a counter of number of packets.
Definition: counter.hpp:70
Generalization of a network interface.
Definition: face.hpp:56
For internal use by FaceLogging macros.
The lower half of a Face.
Definition: transport.hpp:114
ssize_t getMtu() const noexcept
Returns the maximum payload size.
Definition: transport.hpp:270
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:45
std::variant< std::monostate, ethernet::Address, udp::Endpoint > EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:77