generic-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_GENERIC_LINK_SERVICE_HPP
27 #define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
28 
29 #include "link-service.hpp"
30 #include "lp-fragmenter.hpp"
31 #include "lp-reassembler.hpp"
32 #include "lp-reliability.hpp"
33 
34 namespace nfd {
35 namespace face {
36 
42 {
43 public:
47 
53 
57 
61 
65 
69 
73 
78 
83 
87 };
88 
93  , protected virtual GenericLinkServiceCounters
94 {
95 public:
98  class Options
99  {
100  public:
101  constexpr
102  Options() noexcept
103  {
104  }
105 
106  public:
109  bool allowLocalFields = false;
110 
113  bool allowFragmentation = false;
114 
118 
121  bool allowReassembly = false;
122 
126 
130 
133  bool allowCongestionMarking = false;
134 
141  time::nanoseconds baseCongestionMarkingInterval = 100_ms;
142 
149  size_t defaultCongestionThreshold = 65536;
150 
153  bool allowSelfLearning = true;
154  };
155 
159 
160  explicit
161  GenericLinkService(const Options& options = {});
162 
165  const Options&
166  getOptions() const;
167 
170  void
171  setOptions(const Options& options);
172 
173  const Counters&
174  getCounters() const OVERRIDE_WITH_TESTS_ELSE_FINAL;
175 
179  void
180  requestIdlePacket(const EndpointId& endpointId);
181 
184  void
185  sendLpPacket(lp::Packet&& pkt, const EndpointId& endpointId);
186 
189  void
190  doSendInterest(const Interest& interest, const EndpointId& endpointId) OVERRIDE_WITH_TESTS_ELSE_FINAL;
191 
194  void
195  doSendData(const Data& data, const EndpointId& endpointId) OVERRIDE_WITH_TESTS_ELSE_FINAL;
196 
199  void
200  doSendNack(const ndn::lp::Nack& nack, const EndpointId& endpointId) OVERRIDE_WITH_TESTS_ELSE_FINAL;
201 
202 private: // send path
207  void
208  encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
209 
215  void
216  sendNetPacket(lp::Packet&& pkt, const EndpointId& endpointId, bool isInterest);
217 
220  void
221  assignSequence(lp::Packet& pkt);
222 
225  void
226  assignSequences(std::vector<lp::Packet>& pkts);
227 
232  void
233  checkCongestionLevel(lp::Packet& pkt);
234 
235 private: // receive path
238  void
239  doReceivePacket(const Block& packet, const EndpointId& endpoint) OVERRIDE_WITH_TESTS_ELSE_FINAL;
240 
249  void
250  decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
251 
262  void
263  decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
264 
275  void
276  decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
277 
288  void
289  decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
290 
292  Options m_options;
293  LpFragmenter m_fragmenter;
294  LpReassembler m_reassembler;
295  LpReliability m_reliability;
296  lp::Sequence m_lastSeqNo;
297 
300  time::steady_clock::TimePoint m_nextMarkTime;
302  size_t m_nMarkedSinceInMarkingState;
303 
304  friend class LpReliability;
305 };
306 
307 inline const GenericLinkService::Options&
309 {
310  return m_options;
311 }
312 
313 inline const GenericLinkService::Counters&
315 {
316  return *this;
317 }
318 
319 } // namespace face
320 } // namespace nfd
321 
322 #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
provides a counter that observes the size of a table
Definition: counter.hpp:103
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
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
provides for reliable sending and receiving of link-layer packets
#define OVERRIDE_WITH_TESTS_ELSE_FINAL
Definition: common.hpp:43
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
Options that control the behavior of LpReassembler.
fragments network-layer packets into NDNLPv2 link-layer packets
reassembles fragmented network-layer packets
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
Options that control the behavior of LpFragmenter.
#define FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44