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-2020, 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 
91 };
92 
97  , protected virtual GenericLinkServiceCounters
98 {
99 public:
102  class Options
103  {
104  public:
105  Options() noexcept
106  {
107  }
108 
109  public:
112  bool allowLocalFields = false;
113 
116  bool allowFragmentation = false;
117 
121 
124  bool allowReassembly = false;
125 
129 
133 
136  bool allowCongestionMarking = false;
137 
144  time::nanoseconds baseCongestionMarkingInterval = 100_ms;
145 
152  size_t defaultCongestionThreshold = 65536;
153 
156  bool allowSelfLearning = true;
157 
166  ssize_t overrideMtu = std::numeric_limits<ssize_t>::max();
167  };
168 
172 
173  explicit
174  GenericLinkService(const Options& options = {});
175 
178  const Options&
179  getOptions() const;
180 
183  void
184  setOptions(const Options& options);
185 
186  const Counters&
187  getCounters() const OVERRIDE_WITH_TESTS_ELSE_FINAL;
188 
189  ssize_t
190  getEffectiveMtu() const OVERRIDE_WITH_TESTS_ELSE_FINAL;
191 
196  bool
197  canOverrideMtuTo(ssize_t mtu) const;
198 
202  void
203  requestIdlePacket();
204 
207  void
208  sendLpPacket(lp::Packet&& pkt);
209 
210  void
211  doSendInterest(const Interest& interest) OVERRIDE_WITH_TESTS_ELSE_FINAL;
212 
213  void
214  doSendData(const Data& data) OVERRIDE_WITH_TESTS_ELSE_FINAL;
215 
216  void
217  doSendNack(const ndn::lp::Nack& nack) OVERRIDE_WITH_TESTS_ELSE_FINAL;
218 
221  void
222  assignSequences(std::vector<lp::Packet>& pkts);
223 
224 private: // send path
229  void
230  encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
231 
236  void
237  sendNetPacket(lp::Packet&& pkt, bool isInterest);
238 
243  void
244  checkCongestionLevel(lp::Packet& pkt);
245 
246 private: // receive path
247  void
248  doReceivePacket(const Block& packet, const EndpointId& endpoint) OVERRIDE_WITH_TESTS_ELSE_FINAL;
249 
258  void
259  decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
260 
271  void
272  decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
273 
284  void
285  decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
286 
297  void
298  decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
299 
301  Options m_options;
302  LpFragmenter m_fragmenter;
303  LpReassembler m_reassembler;
304  LpReliability m_reliability;
305  lp::Sequence m_lastSeqNo;
306 
309  time::steady_clock::TimePoint m_nextMarkTime;
311  size_t m_nMarkedSinceInMarkingState;
312 
313  friend class LpReliability;
314 };
315 
316 inline const GenericLinkService::Options&
318 {
319  return m_options;
320 }
321 
322 inline const GenericLinkService::Counters&
324 {
325  return *this;
326 }
327 
328 } // namespace face
329 } // namespace nfd
330 
331 #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:71
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