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-2019, 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 public: // upper interface to be used by forwarding
116  void
117  sendInterest(const Interest& interest, const EndpointId& endpoint);
118 
122  void
123  sendData(const Data& data, const EndpointId& endpoint);
124 
128  void
129  sendNack(const ndn::lp::Nack& nack, const EndpointId& endpoint);
130 
133  signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
134 
137  signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
138 
141  signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
142 
145  signal::Signal<LinkService, Interest> onDroppedInterest;
146 
147 public: // lower interface to be invoked by Transport
150  void
151  receivePacket(const Block& packet, const EndpointId& endpoint);
152 
153 protected: // upper interface to be invoked in subclass (receive path termination)
156  void
157  receiveInterest(const Interest& interest, const EndpointId& endpoint);
158 
161  void
162  receiveData(const Data& data, const EndpointId& endpoint);
163 
166  void
167  receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
168 
169 protected: // lower interface to be invoked in subclass (send path termination)
172  void
173  sendPacket(const Block& packet, const EndpointId& endpoint);
174 
175 protected:
176  void
177  notifyDroppedInterest(const Interest& packet);
178 
179 private: // upper interface to be overridden in subclass (send path entrypoint)
182  virtual void
183  doSendInterest(const Interest& interest, const EndpointId& endpoint) = 0;
184 
187  virtual void
188  doSendData(const Data& data, const EndpointId& endpoint) = 0;
189 
192  virtual void
193  doSendNack(const lp::Nack& nack, const EndpointId& endpoint) = 0;
194 
195 private: // lower interface to be overridden in subclass
196  virtual void
197  doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
198 
199 private:
200  Face* m_face;
201  Transport* m_transport;
202 };
203 
204 inline const Face*
206 {
207  return m_face;
208 }
209 
210 inline const Transport*
212 {
213  return m_transport;
214 }
215 
216 inline Transport*
218 {
219  return m_transport;
220 }
221 
222 inline const LinkService::Counters&
224 {
225  return *this;
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, const EndpointId& endpoint)
236 {
237  m_transport->send(packet, endpoint);
238 }
239 
240 std::ostream&
241 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
242 
243 template<typename T>
244 typename std::enable_if<std::is_base_of<LinkService, T>::value &&
245  !std::is_same<LinkService, T>::value, std::ostream&>::type
246 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
247 {
248  return os << FaceLogHelper<LinkService>(flh.obj);
249 }
250 
251 } // namespace face
252 } // namespace nfd
253 
254 #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:65
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:52