NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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-2017, 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 #include "core/scheduler.hpp"
31 
32 #include <ndn-cxx/lp/packet.hpp>
33 #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 
60  time::nanoseconds idleAckTimerPeriod = time::milliseconds(5);
61 
65  size_t seqNumLossThreshold = 3;
66  };
67 
68  LpReliability(const Options& options, GenericLinkService* linkService);
69 
72  void
73  setOptions(const Options& options);
74 
79  const GenericLinkService*
80  getLinkService() const;
81 
85  void
86  handleOutgoing(std::vector<lp::Packet>& frags);
87 
91  void
93 
98  void
99  piggyback(lp::Packet& pkt, ssize_t mtu);
100 
102  class UnackedFrag;
103  class NetPkt;
104  using UnackedFrags = std::map<lp::Sequence, UnackedFrag>;
105 
113  assignTxSequence(lp::Packet& frag);
114 
121  void
122  startIdleAckTimer();
123 
126  void
127  stopIdleAckTimer();
128 
134  std::vector<UnackedFrags::iterator>
135  findLostLpPackets(UnackedFrags::iterator ackIt);
136 
139  void
140  onLpPacketLost(UnackedFrags::iterator txSeqIt);
141 
149  void
150  onLpPacketAcknowledged(UnackedFrags::iterator fragIt);
151 
159  void
160  deleteUnackedFrag(UnackedFrags::iterator fragIt);
161 
165  class UnackedFrag
166  {
167  public:
168  explicit
169  UnackedFrag(lp::Packet pkt);
170 
171  public:
172  lp::Packet pkt;
173  scheduler::ScopedEventId rtoTimer;
175  size_t retxCount;
176  size_t nGreaterSeqAcks;
177  shared_ptr<NetPkt> netPkt;
178  };
179 
182  class NetPkt
183  {
184  public:
185  std::vector<UnackedFrags::iterator> unackedFrags;
186  bool didRetx = false;
187  };
188 
189 public:
191  static constexpr size_t RESERVED_HEADER_SPACE = 3 + 1 + sizeof(lp::Sequence);
192 
194  Options m_options;
195  GenericLinkService* m_linkService;
196  UnackedFrags m_unackedFrags;
202  UnackedFrags::iterator m_firstUnackedFrag;
203  std::queue<lp::Sequence> m_ackQueue;
204  lp::Sequence m_lastTxSeqNo;
205  scheduler::ScopedEventId m_idleAckTimer;
206  bool m_isIdleAckTimerRunning;
207  RttEstimator m_rto;
208 };
209 
210 } // namespace face
211 } // namespace nfd
212 
213 #endif // NFD_DAEMON_FACE_LP_RELIABILITY_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
size_t maxRetx
maximum number of retransmissions for an LpPacket
time_point TimePoint
Definition: time.hpp:120
void setOptions(const Options &options)
set options for reliability
GenericLinkService is a LinkService that implements the NDNLPv2 protocol.
void processIncomingPacket(const lp::Packet &pkt)
extract and parse all Acks and add Ack for contained Fragment (if any) to AckQueue ...
void piggyback(lp::Packet &pkt, ssize_t mtu)
called by GenericLinkService to attach Acks onto an outgoing LpPacket
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
bool isEnabled
enables link-layer reliability
uint64_t Sequence
represents a sequence number
Definition: sequence.hpp:35
static constexpr size_t RESERVED_HEADER_SPACE
TxSequence TLV-TYPE (3 octets) + TxSequence TLV-LENGTH (1 octet) + sizeof(lp::Sequence) ...
Table::const_iterator iterator
Definition: cs-internal.hpp:41
size_t seqNumLossThreshold
a fragment is considered lost if this number of fragments with greater sequence numbers are acknowled...
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void handleOutgoing(std::vector< lp::Packet > &frags)
observe outgoing fragment(s) of a network packet and store for potential retransmission ...
cancels an event automatically upon destruction
Definition: scheduler.hpp:59
LpReliability(const Options &options, GenericLinkService *linkService)
const GenericLinkService * getLinkService() const
implements the Mean-Deviation RTT estimator
time::nanoseconds idleAckTimerPeriod
period between sending pending Acks in an IDLE packet
provides for reliable sending and receiving of link-layer packets