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-2020, 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 {
34 namespace face {
35 
41 {
42 public:
46 
50 
54 
58 
62 
66 
70 };
71 
75 class LinkService : protected virtual LinkServiceCounters, noncopyable
76 {
77 public:
81 
82 public:
83  LinkService();
84 
85  virtual
86  ~LinkService();
87 
91  void
92  setFaceAndTransport(Face& face, Transport& transport);
93 
96  const Face*
97  getFace() const;
98 
101  const Transport*
102  getTransport() const;
103 
106  Transport*
107  getTransport();
108 
109  virtual const Counters&
110  getCounters() const;
111 
112  virtual ssize_t
113  getEffectiveMtu() const;
114 
115 public: // upper interface to be used by forwarding
119  void
120  sendInterest(const Interest& interest);
121 
125  void
126  sendData(const Data& data);
127 
131  void
132  sendNack(const ndn::lp::Nack& nack);
133 
136  signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
137 
140  signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
141 
144  signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
145 
148  signal::Signal<LinkService, Interest> onDroppedInterest;
149 
150 public: // lower interface to be invoked by Transport
153  void
154  receivePacket(const Block& packet, const EndpointId& endpoint);
155 
156 protected: // upper interface to be invoked in subclass (receive path termination)
159  void
160  receiveInterest(const Interest& interest, const EndpointId& endpoint);
161 
164  void
165  receiveData(const Data& data, const EndpointId& endpoint);
166 
169  void
170  receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
171 
172 protected: // lower interface to be invoked in subclass (send path termination)
175  void
176  sendPacket(const Block& packet);
177 
178 protected:
179  void
180  notifyDroppedInterest(const Interest& packet);
181 
182 private: // upper interface to be overridden in subclass (send path entrypoint)
185  virtual void
186  doSendInterest(const Interest& interest) = 0;
187 
190  virtual void
191  doSendData(const Data& data) = 0;
192 
195  virtual void
196  doSendNack(const lp::Nack& nack) = 0;
197 
198 private: // lower interface to be overridden in subclass
199  virtual void
200  doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
201 
202 private:
203  Face* m_face;
204  Transport* m_transport;
205 };
206 
207 inline const Face*
209 {
210  return m_face;
211 }
212 
213 inline const Transport*
215 {
216  return m_transport;
217 }
218 
219 inline Transport*
221 {
222  return m_transport;
223 }
224 
225 inline const LinkService::Counters&
227 {
228  return *this;
229 }
230 
231 inline ssize_t
233 {
234  return m_transport->getMtu();
235 }
236 
237 inline void
238 LinkService::receivePacket(const Block& packet, const EndpointId& endpoint)
239 {
240  doReceivePacket(packet, endpoint);
241 }
242 
243 inline void
244 LinkService::sendPacket(const Block& packet)
245 {
246  m_transport->send(packet);
247 }
248 
249 std::ostream&
250 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
251 
252 template<typename T>
253 typename std::enable_if<std::is_base_of<LinkService, T>::value &&
254  !std::is_same<LinkService, T>::value, std::ostream&>::type
255 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
256 {
257  return os << FaceLogHelper<LinkService>(flh.obj);
258 }
259 
260 } // namespace face
261 } // namespace nfd
262 
263 #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
The lower half of a Face.
Definition: transport.hpp:108
uint64_t EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:71
represents a counter of number of packets
Definition: counter.hpp:66
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
generalization of a network interface
Definition: face.hpp:54