blob: 89d4a696f613382fec6a5fd5a5f63854e2b830b0 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifab9e0d2017-02-02 06:04:59 +00003 * 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_GENERIC_LINK_SERVICE_HPP
27#define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
28
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070030#include "core/logger.hpp"
31
32#include "link-service.hpp"
Eric Newberry4c3e6b82015-11-10 16:48:42 -070033#include "lp-fragmenter.hpp"
34#include "lp-reassembler.hpp"
Eric Newberry185ab292017-03-28 06:45:39 +000035#include "lp-reliability.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070036
37namespace nfd {
38namespace face {
39
Eric Newberry4c3e6b82015-11-10 16:48:42 -070040/** \brief counters provided by GenericLinkService
41 * \note The type name 'GenericLinkServiceCounters' is implementation detail.
42 * Use 'GenericLinkService::Counters' in public API.
43 */
44class GenericLinkServiceCounters : public virtual LinkService::Counters
45{
46public:
47 explicit
48 GenericLinkServiceCounters(const LpReassembler& reassembler);
49
50 /** \brief count of failed fragmentations
51 */
52 PacketCounter nFragmentationErrors;
53
54 /** \brief count of outgoing LpPackets dropped due to exceeding MTU limit
55 *
56 * If this counter is non-zero, the operator should enable fragmentation.
57 */
58 PacketCounter nOutOverMtu;
59
60 /** \brief count of invalid LpPackets dropped before reassembly
61 */
62 PacketCounter nInLpInvalid;
63
64 /** \brief count of network-layer packets currently being reassembled
65 */
66 SizeCounter<LpReassembler> nReassembling;
67
68 /** \brief count of dropped partial network-layer packets due to reassembly timeout
69 */
70 PacketCounter nReassemblyTimeouts;
71
72 /** \brief count of invalid reassembled network-layer packets dropped
73 */
74 PacketCounter nInNetInvalid;
Eric Newberry185ab292017-03-28 06:45:39 +000075
76 /** \brief count of network-layer packets that did not require retransmission of a fragment
77 */
78 PacketCounter nAcknowledged;
79
80 /** \brief count of network-layer packets that had at least one fragment retransmitted, but were
81 * eventually received in full
82 */
83 PacketCounter nRetransmitted;
84
85 /** \brief count of network-layer packets dropped because a fragment reached the maximum number
86 * of retransmissions
87 */
88 PacketCounter nRetxExhausted;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070089};
90
Eric Newberry86d31872015-09-23 16:24:59 -070091/** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol
Eric Newberry185ab292017-03-28 06:45:39 +000092 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Junxiao Shifab9e0d2017-02-02 06:04:59 +000093 * \todo #3941 declare GenericLinkServiceCounters as virtual inheritance
Eric Newberrya98bf932015-09-21 00:58:47 -070094 */
95class GenericLinkService : public LinkService
Junxiao Shifab9e0d2017-02-02 06:04:59 +000096 , protected GenericLinkServiceCounters
Eric Newberrya98bf932015-09-21 00:58:47 -070097{
Eric Newberry86d31872015-09-23 16:24:59 -070098public:
99 /** \brief Options that control the behavior of GenericLinkService
100 */
101 class Options
102 {
103 public:
104 Options();
105
106 public:
Eric Newberry86d31872015-09-23 16:24:59 -0700107 /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
108 */
109 bool allowLocalFields;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700110
111 /** \brief enables fragmentation
112 */
113 bool allowFragmentation;
114
115 /** \brief options for fragmentation
116 */
117 LpFragmenter::Options fragmenterOptions;
118
119 /** \brief enables reassembly
120 */
121 bool allowReassembly;
122
123 /** \brief options for reassembly
124 */
125 LpReassembler::Options reassemblerOptions;
Eric Newberry185ab292017-03-28 06:45:39 +0000126
127 /** \brief options for reliability
128 */
129 LpReliability::Options reliabilityOptions;
Eric Newberry86d31872015-09-23 16:24:59 -0700130 };
131
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700132 /** \brief counters provided by GenericLinkService
133 */
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000134 using Counters = GenericLinkServiceCounters;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700135
Eric Newberry86d31872015-09-23 16:24:59 -0700136 explicit
137 GenericLinkService(const Options& options = Options());
138
139 /** \brief get Options used by GenericLinkService
140 */
141 const Options&
142 getOptions() const;
143
144 /** \brief sets Options used by GenericLinkService
145 */
146 void
147 setOptions(const Options& options);
148
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000149 const Counters&
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200150 getCounters() const override;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700151
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000152PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path
Eric Newberry185ab292017-03-28 06:45:39 +0000153 /** \brief request an IDLE packet to transmit pending service fields
154 */
155 void
156 requestIdlePacket();
157
158 /** \brief send an LpPacket fragment
159 * \param pkt LpPacket to send
160 */
161 void
162 sendLpPacket(lp::Packet&& pkt);
163
Junxiao Shi0de23a22015-12-03 20:07:02 +0000164 /** \brief send Interest
Eric Newberrya98bf932015-09-21 00:58:47 -0700165 */
166 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200167 doSendInterest(const Interest& interest) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700168
Junxiao Shi0de23a22015-12-03 20:07:02 +0000169 /** \brief send Data
Eric Newberrya98bf932015-09-21 00:58:47 -0700170 */
171 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200172 doSendData(const Data& data) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700173
Junxiao Shi0de23a22015-12-03 20:07:02 +0000174 /** \brief send Nack
Eric Newberrya98bf932015-09-21 00:58:47 -0700175 */
176 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200177 doSendNack(const ndn::lp::Nack& nack) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700178
Eric Newberry185ab292017-03-28 06:45:39 +0000179private: // send path
Eric Newberryee400b52016-11-24 14:12:48 +0000180 /** \brief encode link protocol fields from tags onto an outgoing LpPacket
181 * \param netPkt network-layer packet to extract tags from
182 * \param lpPacket LpPacket to add link protocol fields to
Eric Newberry86d31872015-09-23 16:24:59 -0700183 */
Eric Newberryee400b52016-11-24 14:12:48 +0000184 void
185 encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket);
Eric Newberry86d31872015-09-23 16:24:59 -0700186
Junxiao Shi0de23a22015-12-03 20:07:02 +0000187 /** \brief send a complete network layer packet
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700188 * \param pkt LpPacket containing a complete network layer packet
189 */
190 void
191 sendNetPacket(lp::Packet&& pkt);
192
193 /** \brief assign a sequence number to an LpPacket
194 */
195 void
196 assignSequence(lp::Packet& pkt);
197
198 /** \brief assign consecutive sequence numbers to LpPackets
199 */
200 void
201 assignSequences(std::vector<lp::Packet>& pkts);
202
203private: // receive path
204 /** \brief receive Packet from Transport
205 */
206 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200207 doReceivePacket(Transport::Packet&& packet) override;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700208
209 /** \brief decode incoming network-layer packet
210 * \param netPkt reassembled network-layer packet
211 * \param firstPkt LpPacket of first fragment
212 *
213 * If decoding is successful, a receive signal is emitted;
214 * otherwise, a warning is logged.
215 */
216 void
217 decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt);
218
Eric Newberry86d31872015-09-23 16:24:59 -0700219 /** \brief decode incoming Interest
220 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
221 * \param firstPkt LpPacket of first fragment; must not have Nack field
222 *
223 * If decoding is successful, receiveInterest signal is emitted;
224 * otherwise, a warning is logged.
225 *
226 * \throw tlv::Error parse error in an LpHeader field
227 */
228 void
229 decodeInterest(const Block& netPkt, const lp::Packet& firstPkt);
230
231 /** \brief decode incoming Interest
232 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data
233 * \param firstPkt LpPacket of first fragment
234 *
235 * If decoding is successful, receiveData signal is emitted;
236 * otherwise, a warning is logged.
237 *
238 * \throw tlv::Error parse error in an LpHeader field
239 */
240 void
241 decodeData(const Block& netPkt, const lp::Packet& firstPkt);
242
243 /** \brief decode incoming Interest
244 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
245 * \param firstPkt LpPacket of first fragment; must have Nack field
246 *
247 * If decoding is successful, receiveNack signal is emitted;
248 * otherwise, a warning is logged.
249 *
250 * \throw tlv::Error parse error in an LpHeader field
251 */
252 void
253 decodeNack(const Block& netPkt, const lp::Packet& firstPkt);
254
Eric Newberry185ab292017-03-28 06:45:39 +0000255PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Eric Newberry86d31872015-09-23 16:24:59 -0700256 Options m_options;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700257 LpFragmenter m_fragmenter;
258 LpReassembler m_reassembler;
Eric Newberry185ab292017-03-28 06:45:39 +0000259 LpReliability m_reliability;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700260 lp::Sequence m_lastSeqNo;
Eric Newberry185ab292017-03-28 06:45:39 +0000261
262 friend class LpReliability;
Eric Newberrya98bf932015-09-21 00:58:47 -0700263};
264
Eric Newberry86d31872015-09-23 16:24:59 -0700265inline const GenericLinkService::Options&
266GenericLinkService::getOptions() const
267{
268 return m_options;
269}
270
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700271inline const GenericLinkService::Counters&
272GenericLinkService::getCounters() const
273{
274 return *this;
275}
276
Eric Newberrya98bf932015-09-21 00:58:47 -0700277} // namespace face
278} // namespace nfd
279
Eric Newberry86d31872015-09-23 16:24:59 -0700280#endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP