blob: 315d6551c178496e460435d1889f8bf0def7bc9f [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry41aba102017-11-01 16:42:13 -07002/*
3 * Copyright (c) 2014-2017, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * 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
Junxiao Shida93f1f2015-11-11 06:13:16 -070029#include "core/counter.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070030#include "face-log.hpp"
Eric Newberry41aba102017-11-01 16:42:13 -070031#include "transport.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070032
33namespace nfd {
34namespace face {
35
Junxiao Shicde37ad2015-12-24 01:02:05 -070036class Face;
Eric Newberrya98bf932015-09-21 00:58:47 -070037
Junxiao Shi57df2882015-11-11 06:12:35 -070038/** \brief counters provided by LinkService
39 * \note The type name 'LinkServiceCounters' is implementation detail.
40 * Use 'LinkService::Counters' in public API.
41 */
42class LinkServiceCounters
43{
44public:
45 /** \brief count of incoming Interests
46 */
47 PacketCounter nInInterests;
48
49 /** \brief count of outgoing Interests
50 */
51 PacketCounter nOutInterests;
52
Eric Newberry41aba102017-11-01 16:42:13 -070053 /** \brief count of Interests dropped by reliability system for exceeding allowed number of retx
54 */
55 PacketCounter nDroppedInterests;
56
57 /** \brief count of incoming Data packets
Junxiao Shi57df2882015-11-11 06:12:35 -070058 */
59 PacketCounter nInData;
60
Eric Newberry41aba102017-11-01 16:42:13 -070061 /** \brief count of outgoing Data packets
Junxiao Shi57df2882015-11-11 06:12:35 -070062 */
63 PacketCounter nOutData;
64
65 /** \brief count of incoming Nacks
66 */
67 PacketCounter nInNacks;
68
69 /** \brief count of outgoing Nacks
70 */
71 PacketCounter nOutNacks;
72};
73
Junxiao Shicde37ad2015-12-24 01:02:05 -070074/** \brief the upper part of a Face
75 * \sa Face
Eric Newberrya98bf932015-09-21 00:58:47 -070076 */
Junxiao Shi57df2882015-11-11 06:12:35 -070077class LinkService : protected virtual LinkServiceCounters, noncopyable
Eric Newberrya98bf932015-09-21 00:58:47 -070078{
79public:
Junxiao Shi57df2882015-11-11 06:12:35 -070080 /** \brief counters provided by LinkService
81 */
82 typedef LinkServiceCounters Counters;
83
84public:
Eric Newberrya98bf932015-09-21 00:58:47 -070085 LinkService();
86
87 virtual
88 ~LinkService();
89
90 /** \brief set Face and Transport for LinkService
91 * \pre setFaceAndTransport has not been called
92 */
93 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070094 setFaceAndTransport(Face& face, Transport& transport);
Eric Newberrya98bf932015-09-21 00:58:47 -070095
96 /** \return Face to which this LinkService is attached
97 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070098 const Face*
Eric Newberrya98bf932015-09-21 00:58:47 -070099 getFace() const;
100
101 /** \return Transport to which this LinkService is attached
102 */
103 const Transport*
104 getTransport() const;
105
106 /** \return Transport to which this LinkService is attached
107 */
108 Transport*
109 getTransport();
110
Junxiao Shi57df2882015-11-11 06:12:35 -0700111 virtual const Counters&
112 getCounters() const;
113
Eric Newberrya98bf932015-09-21 00:58:47 -0700114public: // upper interface to be used by forwarding
115 /** \brief send Interest
116 * \pre setTransport has been called
117 */
118 void
119 sendInterest(const Interest& interest);
120
121 /** \brief send Data
122 * \pre setTransport has been called
123 */
124 void
125 sendData(const Data& data);
126
127 /** \brief send Nack
128 * \pre setTransport has been called
129 */
130 void
131 sendNack(const ndn::lp::Nack& nack);
132
133 /** \brief signals on Interest received
134 */
135 signal::Signal<LinkService, Interest> afterReceiveInterest;
136
137 /** \brief signals on Data received
138 */
139 signal::Signal<LinkService, Data> afterReceiveData;
140
141 /** \brief signals on Nack received
142 */
143 signal::Signal<LinkService, lp::Nack> afterReceiveNack;
144
Eric Newberry41aba102017-11-01 16:42:13 -0700145 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
146 */
147 signal::Signal<LinkService, Interest> onDroppedInterest;
148
Spyridon Mastorakis24d8d712016-09-20 19:49:21 -0700149 /** \brief signals on Interest sent
150 */
151 signal::Signal<LinkService, Interest> afterSendInterest;
152
153 /** \brief signals on Data sent
154 */
155 signal::Signal<LinkService, Data> afterSendData;
156
157 /** \brief signals on Nack sent
158 */
159 signal::Signal<LinkService, lp::Nack> afterSendNack;
160
Junxiao Shi57df2882015-11-11 06:12:35 -0700161public: // lower interface to be invoked by Transport
162 /** \brief performs LinkService specific operations to receive a lower-layer packet
Eric Newberrya98bf932015-09-21 00:58:47 -0700163 */
Junxiao Shi57df2882015-11-11 06:12:35 -0700164 void
165 receivePacket(Transport::Packet&& packet);
Eric Newberrya98bf932015-09-21 00:58:47 -0700166
167protected: // upper interface to be invoked in subclass (receive path termination)
168 /** \brief delivers received Interest to forwarding
169 */
170 void
171 receiveInterest(const Interest& interest);
172
173 /** \brief delivers received Data to forwarding
174 */
175 void
176 receiveData(const Data& data);
177
178 /** \brief delivers received Nack to forwarding
179 */
180 void
181 receiveNack(const lp::Nack& nack);
182
Eric Newberrya98bf932015-09-21 00:58:47 -0700183protected: // lower interface to be invoked in subclass (send path termination)
184 /** \brief sends a lower-layer packet via Transport
185 */
186 void
187 sendPacket(Transport::Packet&& packet);
188
Eric Newberry41aba102017-11-01 16:42:13 -0700189protected:
190 void
191 notifyDroppedInterest(const Interest& packet);
192
Junxiao Shi57df2882015-11-11 06:12:35 -0700193private: // upper interface to be overridden in subclass (send path entrypoint)
194 /** \brief performs LinkService specific operations to send an Interest
195 */
196 virtual void
197 doSendInterest(const Interest& interest) = 0;
198
199 /** \brief performs LinkService specific operations to send a Data
200 */
201 virtual void
202 doSendData(const Data& data) = 0;
203
204 /** \brief performs LinkService specific operations to send a Nack
205 */
206 virtual void
207 doSendNack(const lp::Nack& nack) = 0;
208
Eric Newberrya98bf932015-09-21 00:58:47 -0700209private: // lower interface to be overridden in subclass
210 virtual void
211 doReceivePacket(Transport::Packet&& packet) = 0;
212
213private:
Junxiao Shicde37ad2015-12-24 01:02:05 -0700214 Face* m_face;
Eric Newberrya98bf932015-09-21 00:58:47 -0700215 Transport* m_transport;
Eric Newberrya98bf932015-09-21 00:58:47 -0700216};
217
Junxiao Shicde37ad2015-12-24 01:02:05 -0700218inline const Face*
Eric Newberrya98bf932015-09-21 00:58:47 -0700219LinkService::getFace() const
220{
221 return m_face;
222}
223
224inline const Transport*
225LinkService::getTransport() const
226{
227 return m_transport;
228}
229
230inline Transport*
231LinkService::getTransport()
232{
233 return m_transport;
234}
235
Junxiao Shi57df2882015-11-11 06:12:35 -0700236inline const LinkService::Counters&
237LinkService::getCounters() const
238{
239 return *this;
240}
241
Eric Newberrya98bf932015-09-21 00:58:47 -0700242inline void
243LinkService::receivePacket(Transport::Packet&& packet)
244{
245 doReceivePacket(std::move(packet));
246}
247
248inline void
249LinkService::sendPacket(Transport::Packet&& packet)
250{
251 m_transport->send(std::move(packet));
252}
253
254std::ostream&
255operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
256
257template<typename T>
258typename std::enable_if<std::is_base_of<LinkService, T>::value &&
259 !std::is_same<LinkService, T>::value, std::ostream&>::type
260operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
261{
262 return os << FaceLogHelper<LinkService>(flh.obj);
263}
264
265} // namespace face
266} // namespace nfd
267
268#endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP