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 
139  time::nanoseconds baseCongestionMarkingInterval = 100_ms;
140 
145  size_t defaultCongestionThreshold = 65536;
146 
149  bool allowSelfLearning = true;
150  };
151 
155 
156  explicit
157  GenericLinkService(const Options& options = {});
158 
161  const Options&
162  getOptions() const;
163 
166  void
167  setOptions(const Options& options);
168 
169  const Counters&
170  getCounters() const override;
171 
175  void
176  requestIdlePacket();
177 
181  void
182  sendLpPacket(lp::Packet&& pkt);
183 
186  void
187  doSendInterest(const Interest& interest) override;
188 
191  void
192  doSendData(const Data& data) override;
193 
196  void
197  doSendNack(const ndn::lp::Nack& nack) override;
198 
199 private: // send path
204  void
205  encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
206 
211  void
212  sendNetPacket(lp::Packet&& pkt, bool isInterest);
213 
216  void
217  assignSequence(lp::Packet& pkt);
218 
221  void
222  assignSequences(std::vector<lp::Packet>& pkts);
223 
228  void
229  checkCongestionLevel(lp::Packet& pkt);
230 
231 private: // receive path
234  void
235  doReceivePacket(Transport::Packet&& packet) override;
236 
244  void
245  decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt);
246 
256  void
257  decodeInterest(const Block& netPkt, const lp::Packet& firstPkt);
258 
268  void
269  decodeData(const Block& netPkt, const lp::Packet& firstPkt);
270 
280  void
281  decodeNack(const Block& netPkt, const lp::Packet& firstPkt);
282 
284  Options m_options;
285  LpFragmenter m_fragmenter;
286  LpReassembler m_reassembler;
287  LpReliability m_reliability;
288  lp::Sequence m_lastSeqNo;
289 
292  static constexpr size_t CONGESTION_MARK_SIZE = 3 + 1 + sizeof(uint64_t);
293 
295  time::steady_clock::TimePoint m_nextMarkTime;
297  time::steady_clock::TimePoint m_lastMarkTime;
299  size_t m_nMarkedSinceInMarkingState;
300 
301  friend class LpReliability;
302 };
303 
304 inline const GenericLinkService::Options&
306 {
307  return m_options;
308 }
309 
310 inline const GenericLinkService::Counters&
312 {
313  return *this;
314 }
315 
316 } // namespace face
317 } // namespace nfd
318 
319 #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
provides a counter that observes the size of a table
Definition: counter.hpp:114
stores a packet along with the remote endpoint
Definition: transport.hpp:122
represents a counter of number of packets
Definition: counter.hpp:77
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
provides for reliable sending and receiving of link-layer packets
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:40
Options that control the behavior of LpFragmenter.