lp-reliability.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_LP_RELIABILITY_HPP
27 #define NFD_DAEMON_FACE_LP_RELIABILITY_HPP
28 
29 #include "core/rtt-estimator.hpp"
30 
31 #include <ndn-cxx/lp/packet.hpp>
32 #include <ndn-cxx/lp/sequence.hpp>
33 
34 #include <queue>
35 
36 namespace nfd {
37 namespace face {
38 
39 class GenericLinkService;
40 
44 class LpReliability : noncopyable
45 {
46 public:
47  struct Options
48  {
51  bool isEnabled = false;
52 
55  size_t maxRetx = 3;
56 
59  time::nanoseconds idleAckTimerPeriod = 5_ms;
60 
64  size_t seqNumLossThreshold = 3;
65  };
66 
67  LpReliability(const Options& options, GenericLinkService* linkService);
68 
71  signal::Signal<LpReliability, Interest> onDroppedInterest;
72 
75  void
76  setOptions(const Options& options);
77 
82  const GenericLinkService*
83  getLinkService() const;
84 
90  void
91  handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest);
92 
96  void
97  processIncomingPacket(const lp::Packet& pkt);
98 
103  void
104  piggyback(lp::Packet& pkt, ssize_t mtu);
105 
107  class UnackedFrag;
108  class NetPkt;
109  using UnackedFrags = std::map<lp::Sequence, UnackedFrag>;
110 
117  lp::Sequence
118  assignTxSequence(lp::Packet& frag);
119 
126  void
127  startIdleAckTimer();
128 
131  void
132  stopIdleAckTimer();
133 
139  std::vector<lp::Sequence>
140  findLostLpPackets(UnackedFrags::iterator ackIt);
141 
145  std::vector<lp::Sequence>
146  onLpPacketLost(lp::Sequence txSeq);
147 
155  void
156  onLpPacketAcknowledged(UnackedFrags::iterator fragIt);
157 
165  void
166  deleteUnackedFrag(UnackedFrags::iterator fragIt);
167 
171  class UnackedFrag
172  {
173  public:
174  explicit
175  UnackedFrag(lp::Packet pkt);
176 
177  public:
178  lp::Packet pkt;
179  scheduler::ScopedEventId rtoTimer;
180  time::steady_clock::TimePoint sendTime;
181  size_t retxCount;
182  size_t nGreaterSeqAcks;
183  shared_ptr<NetPkt> netPkt;
184  };
185 
188  class NetPkt
189  {
190  public:
191  NetPkt(lp::Packet&& pkt, bool isInterest);
192 
193  public:
194  std::vector<UnackedFrags::iterator> unackedFrags;
195  lp::Packet pkt;
196  bool isInterest;
197  bool didRetx;
198  };
199 
200 public:
202  static constexpr size_t RESERVED_HEADER_SPACE = 3 + 1 + sizeof(lp::Sequence);
203 
205  Options m_options;
206  GenericLinkService* m_linkService;
207  UnackedFrags m_unackedFrags;
213  UnackedFrags::iterator m_firstUnackedFrag;
214  std::queue<lp::Sequence> m_ackQueue;
215  lp::Sequence m_lastTxSeqNo;
216  scheduler::ScopedEventId m_idleAckTimer;
217  bool m_isIdleAckTimerRunning;
218  RttEstimator m_rto;
219 };
220 
221 } // namespace face
222 } // namespace nfd
223 
224 #endif // NFD_DAEMON_FACE_LP_RELIABILITY_HPP
void processIncomingPacket(const lp::Packet &pkt)
extract and parse all Acks and add Ack for contained Fragment (if any) to AckQueue ...
const GenericLinkService * getLinkService() const
void piggyback(lp::Packet &pkt, ssize_t mtu)
called by GenericLinkService to attach Acks onto an outgoing LpPacket
bool isEnabled
enables link-layer reliability
implements the Mean-Deviation RTT estimator
size_t maxRetx
maximum number of retransmissions for an LpPacket
Table::const_iterator iterator
Definition: cs-internal.hpp:41
static constexpr size_t RESERVED_HEADER_SPACE
TxSequence TLV-TYPE (3 octets) + TxSequence TLV-LENGTH (1 octet) + sizeof(lp::Sequence) ...
size_t seqNumLossThreshold
a fragment is considered lost if this number of fragments with greater sequence numbers are acknowled...
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
LpReliability(const Options &options, GenericLinkService *linkService)
void handleOutgoing(std::vector< lp::Packet > &frags, lp::Packet &&pkt, bool isInterest)
observe outgoing fragment(s) of a network packet and store for potential retransmission ...
time::nanoseconds idleAckTimerPeriod
period between sending pending Acks in an IDLE packet
void setOptions(const Options &options)
set options for reliability
signal::Signal< LpReliability, Interest > onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx ...
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41