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-2017, 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 "core/counter.hpp"
30 #include "face-log.hpp"
31 #include "transport.hpp"
32 
33 namespace nfd {
34 namespace face {
35 
36 class Face;
37 
43 {
44 public:
48 
52 
56 
60 
64 
68 
72 };
73 
77 class LinkService : protected virtual LinkServiceCounters, noncopyable
78 {
79 public:
83 
84 public:
85  LinkService();
86 
87  virtual
88  ~LinkService();
89 
93  void
94  setFaceAndTransport(Face& face, Transport& transport);
95 
98  const Face*
99  getFace() const;
100 
103  const Transport*
104  getTransport() const;
105 
108  Transport*
109  getTransport();
110 
111  virtual const Counters&
112  getCounters() const;
113 
114 public: // upper interface to be used by forwarding
118  void
119  sendInterest(const Interest& interest);
120 
124  void
125  sendData(const Data& data);
126 
130  void
131  sendNack(const ndn::lp::Nack& nack);
132 
135  signal::Signal<LinkService, Interest> afterReceiveInterest;
136 
139  signal::Signal<LinkService, Data> afterReceiveData;
140 
143  signal::Signal<LinkService, lp::Nack> afterReceiveNack;
144 
147  signal::Signal<LinkService, Interest> onDroppedInterest;
148 
149 public: // lower interface to be invoked by Transport
152  void
153  receivePacket(Transport::Packet&& packet);
154 
155 protected: // upper interface to be invoked in subclass (receive path termination)
158  void
159  receiveInterest(const Interest& interest);
160 
163  void
164  receiveData(const Data& data);
165 
168  void
169  receiveNack(const lp::Nack& nack);
170 
171 protected: // lower interface to be invoked in subclass (send path termination)
174  void
175  sendPacket(Transport::Packet&& packet);
176 
177 protected:
178  void
179  notifyDroppedInterest(const Interest& packet);
180 
181 private: // upper interface to be overridden in subclass (send path entrypoint)
184  virtual void
185  doSendInterest(const Interest& interest) = 0;
186 
189  virtual void
190  doSendData(const Data& data) = 0;
191 
194  virtual void
195  doSendNack(const lp::Nack& nack) = 0;
196 
197 private: // lower interface to be overridden in subclass
198  virtual void
199  doReceivePacket(Transport::Packet&& packet) = 0;
200 
201 private:
202  Face* m_face;
203  Transport* m_transport;
204 };
205 
206 inline const Face*
208 {
209  return m_face;
210 }
211 
212 inline const Transport*
214 {
215  return m_transport;
216 }
217 
218 inline Transport*
220 {
221  return m_transport;
222 }
223 
224 inline const LinkService::Counters&
226 {
227  return *this;
228 }
229 
230 inline void
232 {
233  doReceivePacket(std::move(packet));
234 }
235 
236 inline void
238 {
239  m_transport->send(std::move(packet));
240 }
241 
242 std::ostream&
243 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
244 
245 template<typename T>
246 typename std::enable_if<std::is_base_of<LinkService, T>::value &&
247  !std::is_same<LinkService, T>::value, std::ostream&>::type
248 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
249 {
250  return os << FaceLogHelper<LinkService>(flh.obj);
251 }
252 
253 } // namespace face
254 } // namespace nfd
255 
256 #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
the lower part of a Face
Definition: transport.hpp:113
stores a packet along with the remote endpoint
Definition: transport.hpp:122
represents a counter of number of packets
Definition: counter.hpp:77
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:67