NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2021, 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 "face-common.hpp"
30 
31 #include <ndn-cxx/lp/packet.hpp>
32 #include <ndn-cxx/lp/sequence.hpp>
34 
35 #include <queue>
36 
37 namespace nfd {
38 namespace face {
39 
40 class GenericLinkService;
41 
45 class LpReliability : noncopyable
46 {
47 public:
48  struct Options
49  {
52  bool isEnabled = false;
53 
56  size_t maxRetx = 3;
57 
61 
65  size_t seqNumLossThreshold = 3;
66  };
67 
68  LpReliability(const Options& options, GenericLinkService* linkService);
69 
73 
76  void
77  setOptions(const Options& options);
78 
83  const GenericLinkService*
84  getLinkService() const;
85 
91  void
92  handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest);
93 
98  bool
100 
105  void
106  piggyback(lp::Packet& pkt, ssize_t mtu);
107 
109  class UnackedFrag;
110  class NetPkt;
111  using UnackedFrags = std::map<lp::Sequence, UnackedFrag>;
112 
120  assignTxSequence(lp::Packet& frag);
121 
128  void
130 
136  std::vector<lp::Sequence>
137  findLostLpPackets(UnackedFrags::iterator ackIt);
138 
142  std::vector<lp::Sequence>
143  onLpPacketLost(lp::Sequence txSeq, bool isTimeout);
144 
152  void
153  onLpPacketAcknowledged(UnackedFrags::iterator fragIt);
154 
162  void
163  deleteUnackedFrag(UnackedFrags::iterator fragIt);
164 
168  class UnackedFrag
169  {
170  public:
171  explicit
172  UnackedFrag(lp::Packet pkt);
173 
174  public:
178  size_t retxCount;
180  shared_ptr<NetPkt> netPkt;
181  };
182 
185  class NetPkt
186  {
187  public:
188  NetPkt(lp::Packet&& pkt, bool isInterest);
189 
190  public:
191  std::vector<UnackedFrags::iterator> unackedFrags;
194  bool didRetx;
195  };
196 
197 public:
201  sizeof(lp::Sequence);
202 
204  Options m_options;
212  UnackedFrags::iterator m_firstUnackedFrag;
213  std::queue<lp::Sequence> m_ackQueue;
214  std::map<lp::Sequence, time::steady_clock::TimePoint> m_recentRecvSeqs;
215  std::queue<lp::Sequence> m_recentRecvSeqsQueue;
219 };
220 
221 std::ostream&
222 operator<<(std::ostream& os, const FaceLogHelper<LpReliability>& flh);
223 
224 } // namespace face
225 } // namespace nfd
226 
227 #endif // NFD_DAEMON_FACE_LP_RELIABILITY_HPP
size_t maxRetx
maximum number of retransmissions for an LpPacket
ndn::util::RttEstimator m_rttEst
void setOptions(const Options &options)
set options for reliability
RTT/RTO estimator.
void piggyback(lp::Packet &pkt, ssize_t mtu)
called by GenericLinkService to attach Acks onto an outgoing LpPacket
contains a network-layer packet with unacknowledged fragments
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 ...
std::vector< lp::Sequence > onLpPacketLost(lp::Sequence txSeq, bool isTimeout)
resend (or give up on) a lost fragment
std::vector< UnackedFrags::iterator > unackedFrags
void startIdleAckTimer()
start the idle Ack timer
std::vector< lp::Sequence > findLostLpPackets(UnackedFrags::iterator ackIt)
find and mark as lost fragments where a configurable number of Acks (m_options.seqNumLossThreshold) h...
provides a lightweight signal / event system
Definition: signal.hpp:52
UnackedFrags::iterator m_firstUnackedFrag
An iterator that points to the first unacknowledged fragment in the current window.
bool isEnabled
enables link-layer reliability
uint64_t Sequence
represents a sequence number
Definition: sequence.hpp:35
std::queue< lp::Sequence > m_ackQueue
static constexpr size_t RESERVED_HEADER_SPACE
TxSequence TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
std::map< lp::Sequence, time::steady_clock::TimePoint > m_recentRecvSeqs
scheduler::ScopedEventId m_idleAckTimer
size_t seqNumLossThreshold
a fragment is considered lost if this number of fragments with greater sequence numbers are acknowled...
constexpr size_t sizeOfVarNumber(uint64_t number) noexcept
Get the number of bytes necessary to hold the value of number encoded as VAR-NUMBER.
Definition: tlv.hpp:454
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
const GenericLinkService * getLinkService() const
shared_ptr< NetPkt > netPkt
LpReliability(const Options &options, GenericLinkService *linkService)
void deleteUnackedFrag(UnackedFrags::iterator fragIt)
delete a fragment from UnackedFrags and advance acknowledge window if necessary
scheduler::ScopedEventId rtoTimer
time::steady_clock::TimePoint sendTime
bool processIncomingPacket(const lp::Packet &pkt)
extract and parse all Acks and add Ack for contained Fragment (if any) to AckQueue ...
signal::Signal< LpReliability, Interest > onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx ...
GenericLinkService * m_linkService
std::queue< lp::Sequence > m_recentRecvSeqsQueue
time::nanoseconds idleAckTimerPeriod
period between sending pending Acks in an IDLE packet
void onLpPacketAcknowledged(UnackedFrags::iterator fragIt)
remove the fragment with the given sequence number from the map of unacknowledged fragments...
std::map< lp::Sequence, UnackedFrag > UnackedFrags
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
provides for reliable sending and receiving of link-layer packets
time_point TimePoint
Definition: time.hpp:233
size_t nGreaterSeqAcks
number of Acks received for sequences greater than this fragment