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-2022, 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::face {
35 
41 {
42 public:
46 
52 
56 
60 
64 
68 
72 
77 
82 
86 
90 };
91 
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 
137 
144  time::nanoseconds baseCongestionMarkingInterval = 100_ms;
145 
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  {
181  return m_options;
182  }
183 
186  void
187  setOptions(const Options& options);
188 
189  const Counters&
191  {
192  return *this;
193  }
194 
195  ssize_t
197 
202  bool
203  canOverrideMtuTo(ssize_t mtu) const;
204 
208  void
209  requestIdlePacket();
210 
213  void
214  sendLpPacket(lp::Packet&& pkt);
215 
216  void
217  doSendInterest(const Interest& interest) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
218 
219  void
220  doSendData(const Data& data) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
221 
222  void
223  doSendNack(const ndn::lp::Nack& nack) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
224 
227  void
228  assignSequences(std::vector<lp::Packet>& pkts);
229 
230 private: // send path
235  void
236  encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
237 
242  void
243  sendNetPacket(lp::Packet&& pkt, bool isInterest);
244 
249  void
250  checkCongestionLevel(lp::Packet& pkt);
251 
252 private: // receive path
253  void
254  doReceivePacket(const Block& packet, const EndpointId& endpoint) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
255 
264  void
265  decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
266 
277  void
278  decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
279 
290  void
291  decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
292 
303  void
304  decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
305 
307  Options m_options;
308  LpFragmenter m_fragmenter;
309  LpReassembler m_reassembler;
310  LpReliability m_reliability;
311  lp::Sequence m_lastSeqNo;
312 
315  time::steady_clock::time_point m_nextMarkTime;
317  size_t m_nMarkedSinceInMarkingState;
318 
319  friend LpReliability;
320 };
321 
322 } // namespace nfd::face
323 
324 #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
Represents a counter of number of packets.
Definition: counter.hpp:70
Provides a counter that observes the size of a table.
Definition: counter.hpp:107
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:77
Options that control the behavior of LpFragmenter.
Options that control the behavior of LpReassembler.