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-2024, 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 #include <limits>
35 
36 namespace nfd::face {
37 
44 {
45 public:
48 
55 
58 
61 
64 
67 
70 
76 
82 
85 
88 };
89 
96 {
99  bool allowLocalFields = false;
100 
103  bool allowFragmentation = false;
104 
108 
111  bool allowReassembly = false;
112 
116 
120 
124 
131  time::nanoseconds baseCongestionMarkingInterval = 100_ms;
132 
140 
143  bool allowSelfLearning = true;
144 
153  ssize_t overrideMtu = std::numeric_limits<ssize_t>::max();
154 };
155 
161  , protected virtual GenericLinkServiceCounters
162 {
163 public:
168 
173 
174  explicit
175  GenericLinkService(const Options& options = {});
176 
180  const Options&
181  getOptions() const
182  {
183  return m_options;
184  }
185 
189  void
190  setOptions(const Options& options);
191 
192  const Counters&
194  {
195  return *this;
196  }
197 
198  ssize_t
200 
205  bool
206  canOverrideMtuTo(ssize_t mtu) const;
207 
211  void
212  requestIdlePacket();
213 
216  void
217  sendLpPacket(lp::Packet&& pkt);
218 
219  void
220  doSendInterest(const Interest& interest) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
221 
222  void
223  doSendData(const Data& data) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
224 
225  void
226  doSendNack(const ndn::lp::Nack& nack) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
227 
230  void
231  assignSequences(std::vector<lp::Packet>& pkts);
232 
233 private: // send path
238  void
239  encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
240 
245  void
246  sendNetPacket(lp::Packet&& pkt, bool isInterest);
247 
252  void
253  checkCongestionLevel(lp::Packet& pkt);
254 
255 private: // receive path
256  void
257  doReceivePacket(const Block& packet, const EndpointId& endpoint) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
258 
267  void
268  decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
269 
280  void
281  decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
282 
293  void
294  decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
295 
306  void
307  decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
308 
310  Options m_options;
311  LpFragmenter m_fragmenter;
312  LpReassembler m_reassembler;
313  LpReliability m_reliability;
314  lp::Sequence m_lastSeqNo = static_cast<lp::Sequence>(-2);
315 
318  time::steady_clock::time_point m_nextMarkTime = time::steady_clock::time_point::max();
320  size_t m_nMarkedSinceInMarkingState = 0;
321 
322  friend LpReliability;
323 };
324 
325 } // namespace nfd::face
326 
327 #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
Represents a counter of number of packets.
Definition: counter.hpp:71
Provides a counter that observes the size of a table.
Definition: counter.hpp:111
Fragments network-layer packets into NDNLPv2 link-layer packets.
Reassembles fragmented network-layer packets.
Provides for reliable sending and receiving of link-layer packets.
#define NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL
Definition: common.hpp:43
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
#define NFD_FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
#define NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
Definition: dns-srv.cpp:44
std::variant< std::monostate, ethernet::Address, udp::Endpoint > EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:78
Options that control the behavior of LpFragmenter.
Options that control the behavior of LpReassembler.