blob: 1823b37efcbb552b011ae667e1e6bc8e5fc136c2 [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/*
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
Eric Newberrya98bf932015-09-21 00:58:47 -070029#include "link-service.hpp"
Eric Newberry4c3e6b82015-11-10 16:48:42 -070030#include "lp-fragmenter.hpp"
31#include "lp-reassembler.hpp"
Eric Newberry185ab292017-03-28 06:45:39 +000032#include "lp-reliability.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070033
34namespace nfd {
35namespace face {
36
Eric Newberry4c3e6b82015-11-10 16:48:42 -070037/** \brief counters provided by GenericLinkService
38 * \note The type name 'GenericLinkServiceCounters' is implementation detail.
39 * Use 'GenericLinkService::Counters' in public API.
40 */
41class GenericLinkServiceCounters : public virtual LinkService::Counters
42{
43public:
Eric Newberry4c3e6b82015-11-10 16:48:42 -070044 /** \brief count of failed fragmentations
45 */
46 PacketCounter nFragmentationErrors;
47
48 /** \brief count of outgoing LpPackets dropped due to exceeding MTU limit
49 *
50 * If this counter is non-zero, the operator should enable fragmentation.
51 */
52 PacketCounter nOutOverMtu;
53
54 /** \brief count of invalid LpPackets dropped before reassembly
55 */
56 PacketCounter nInLpInvalid;
57
58 /** \brief count of network-layer packets currently being reassembled
59 */
60 SizeCounter<LpReassembler> nReassembling;
61
62 /** \brief count of dropped partial network-layer packets due to reassembly timeout
63 */
64 PacketCounter nReassemblyTimeouts;
65
66 /** \brief count of invalid reassembled network-layer packets dropped
67 */
68 PacketCounter nInNetInvalid;
Eric Newberry185ab292017-03-28 06:45:39 +000069
70 /** \brief count of network-layer packets that did not require retransmission of a fragment
71 */
72 PacketCounter nAcknowledged;
73
74 /** \brief count of network-layer packets that had at least one fragment retransmitted, but were
75 * eventually received in full
76 */
77 PacketCounter nRetransmitted;
78
79 /** \brief count of network-layer packets dropped because a fragment reached the maximum number
80 * of retransmissions
81 */
82 PacketCounter nRetxExhausted;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070083};
84
Eric Newberry86d31872015-09-23 16:24:59 -070085/** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol
Eric Newberry185ab292017-03-28 06:45:39 +000086 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Eric Newberrya98bf932015-09-21 00:58:47 -070087 */
88class GenericLinkService : public LinkService
Eric Newberry73bcad32017-04-25 17:57:35 -070089 , protected virtual GenericLinkServiceCounters
Eric Newberrya98bf932015-09-21 00:58:47 -070090{
Eric Newberry86d31872015-09-23 16:24:59 -070091public:
92 /** \brief Options that control the behavior of GenericLinkService
93 */
94 class Options
95 {
96 public:
97 Options();
98
99 public:
Eric Newberry86d31872015-09-23 16:24:59 -0700100 /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
101 */
102 bool allowLocalFields;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700103
104 /** \brief enables fragmentation
105 */
106 bool allowFragmentation;
107
108 /** \brief options for fragmentation
109 */
110 LpFragmenter::Options fragmenterOptions;
111
112 /** \brief enables reassembly
113 */
114 bool allowReassembly;
115
116 /** \brief options for reassembly
117 */
118 LpReassembler::Options reassemblerOptions;
Eric Newberry185ab292017-03-28 06:45:39 +0000119
120 /** \brief options for reliability
121 */
122 LpReliability::Options reliabilityOptions;
Eric Newberry86d31872015-09-23 16:24:59 -0700123 };
124
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700125 /** \brief counters provided by GenericLinkService
126 */
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000127 using Counters = GenericLinkServiceCounters;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700128
Eric Newberry86d31872015-09-23 16:24:59 -0700129 explicit
130 GenericLinkService(const Options& options = Options());
131
132 /** \brief get Options used by GenericLinkService
133 */
134 const Options&
135 getOptions() const;
136
137 /** \brief sets Options used by GenericLinkService
138 */
139 void
140 setOptions(const Options& options);
141
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000142 const Counters&
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200143 getCounters() const override;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700144
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000145PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path
Eric Newberry185ab292017-03-28 06:45:39 +0000146 /** \brief request an IDLE packet to transmit pending service fields
147 */
148 void
149 requestIdlePacket();
150
151 /** \brief send an LpPacket fragment
152 * \param pkt LpPacket to send
153 */
154 void
155 sendLpPacket(lp::Packet&& pkt);
156
Junxiao Shi0de23a22015-12-03 20:07:02 +0000157 /** \brief send Interest
Eric Newberrya98bf932015-09-21 00:58:47 -0700158 */
159 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200160 doSendInterest(const Interest& interest) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700161
Junxiao Shi0de23a22015-12-03 20:07:02 +0000162 /** \brief send Data
Eric Newberrya98bf932015-09-21 00:58:47 -0700163 */
164 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200165 doSendData(const Data& data) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700166
Junxiao Shi0de23a22015-12-03 20:07:02 +0000167 /** \brief send Nack
Eric Newberrya98bf932015-09-21 00:58:47 -0700168 */
169 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200170 doSendNack(const ndn::lp::Nack& nack) override;
Eric Newberrya98bf932015-09-21 00:58:47 -0700171
Eric Newberry185ab292017-03-28 06:45:39 +0000172private: // send path
Eric Newberryee400b52016-11-24 14:12:48 +0000173 /** \brief encode link protocol fields from tags onto an outgoing LpPacket
174 * \param netPkt network-layer packet to extract tags from
175 * \param lpPacket LpPacket to add link protocol fields to
Eric Newberry86d31872015-09-23 16:24:59 -0700176 */
Eric Newberryee400b52016-11-24 14:12:48 +0000177 void
Eric Newberry41aba102017-11-01 16:42:13 -0700178 encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
Eric Newberry86d31872015-09-23 16:24:59 -0700179
Junxiao Shi0de23a22015-12-03 20:07:02 +0000180 /** \brief send a complete network layer packet
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700181 * \param pkt LpPacket containing a complete network layer packet
Eric Newberry41aba102017-11-01 16:42:13 -0700182 * \param isInterest whether the network layer packet is an Interest
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700183 */
184 void
Eric Newberry41aba102017-11-01 16:42:13 -0700185 sendNetPacket(lp::Packet&& pkt, bool isInterest);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700186
187 /** \brief assign a sequence number to an LpPacket
188 */
189 void
190 assignSequence(lp::Packet& pkt);
191
192 /** \brief assign consecutive sequence numbers to LpPackets
193 */
194 void
195 assignSequences(std::vector<lp::Packet>& pkts);
196
197private: // receive path
198 /** \brief receive Packet from Transport
199 */
200 void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +0200201 doReceivePacket(Transport::Packet&& packet) override;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700202
203 /** \brief decode incoming network-layer packet
204 * \param netPkt reassembled network-layer packet
205 * \param firstPkt LpPacket of first fragment
206 *
207 * If decoding is successful, a receive signal is emitted;
208 * otherwise, a warning is logged.
209 */
210 void
211 decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt);
212
Eric Newberry86d31872015-09-23 16:24:59 -0700213 /** \brief decode incoming Interest
214 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
215 * \param firstPkt LpPacket of first fragment; must not have Nack field
216 *
217 * If decoding is successful, receiveInterest signal is emitted;
218 * otherwise, a warning is logged.
219 *
220 * \throw tlv::Error parse error in an LpHeader field
221 */
222 void
223 decodeInterest(const Block& netPkt, const lp::Packet& firstPkt);
224
225 /** \brief decode incoming Interest
226 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data
227 * \param firstPkt LpPacket of first fragment
228 *
229 * If decoding is successful, receiveData signal is emitted;
230 * otherwise, a warning is logged.
231 *
232 * \throw tlv::Error parse error in an LpHeader field
233 */
234 void
235 decodeData(const Block& netPkt, const lp::Packet& firstPkt);
236
237 /** \brief decode incoming Interest
238 * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
239 * \param firstPkt LpPacket of first fragment; must have Nack field
240 *
241 * If decoding is successful, receiveNack signal is emitted;
242 * otherwise, a warning is logged.
243 *
244 * \throw tlv::Error parse error in an LpHeader field
245 */
246 void
247 decodeNack(const Block& netPkt, const lp::Packet& firstPkt);
248
Eric Newberry185ab292017-03-28 06:45:39 +0000249PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Eric Newberry86d31872015-09-23 16:24:59 -0700250 Options m_options;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700251 LpFragmenter m_fragmenter;
252 LpReassembler m_reassembler;
Eric Newberry185ab292017-03-28 06:45:39 +0000253 LpReliability m_reliability;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700254 lp::Sequence m_lastSeqNo;
Eric Newberry185ab292017-03-28 06:45:39 +0000255
256 friend class LpReliability;
Eric Newberrya98bf932015-09-21 00:58:47 -0700257};
258
Eric Newberry86d31872015-09-23 16:24:59 -0700259inline const GenericLinkService::Options&
260GenericLinkService::getOptions() const
261{
262 return m_options;
263}
264
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700265inline const GenericLinkService::Counters&
266GenericLinkService::getCounters() const
267{
268 return *this;
269}
270
Eric Newberrya98bf932015-09-21 00:58:47 -0700271} // namespace face
272} // namespace nfd
273
Eric Newberry86d31872015-09-23 16:24:59 -0700274#endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP