NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
segment-fetcher.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2021 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_UTIL_SEGMENT_FETCHER_HPP
23 #define NDN_CXX_UTIL_SEGMENT_FETCHER_HPP
24 
25 #include "ndn-cxx/face.hpp"
29 #include "ndn-cxx/util/signal.hpp"
30 
31 #include <queue>
32 #include <set>
33 
34 namespace ndn {
35 namespace util {
36 
80 class SegmentFetcher : noncopyable
81 {
82 public:
86  enum ErrorCode {
97  };
98 
99  class Options
100  {
101  public:
103  {
104  }
105 
106  void
107  validate();
108 
109  public:
112  bool inOrder = false;
114  bool useConstantCwnd = false;
115  bool disableCwa = false;
116  bool resetCwndToInit = false;
117  bool ignoreCongMarks = false;
118  double initCwnd = 1.0;
119  double initSsthresh = std::numeric_limits<double>::max();
120  double aiStep = 1.0;
121  double mdCoef = 0.5;
123  size_t flowControlWindow = 25000;
124  };
125 
148  static shared_ptr<SegmentFetcher>
149  start(Face& face,
150  const Interest& baseInterest,
151  security::Validator& validator,
152  const Options& options = Options());
153 
159  void
160  stop();
161 
162 private:
163  class PendingSegment;
164 
165  SegmentFetcher(Face& face, security::Validator& validator, const Options& options);
166 
167  static bool
168  shouldStop(const weak_ptr<SegmentFetcher>& weakSelf);
169 
170  void
171  fetchFirstSegment(const Interest& baseInterest, bool isRetransmission);
172 
173  void
174  fetchSegmentsInWindow(const Interest& origInterest);
175 
176  void
177  sendInterest(uint64_t segNum, const Interest& interest, bool isRetransmission);
178 
179  void
180  afterSegmentReceivedCb(const Interest& origInterest, const Data& data,
181  const weak_ptr<SegmentFetcher>& weakSelf);
182 
183  void
184  afterValidationSuccess(const Data& data, const Interest& origInterest,
185  std::map<uint64_t, PendingSegment>::iterator pendingSegmentIt,
186  const weak_ptr<SegmentFetcher>& weakSelf);
187 
188  void
189  afterValidationFailure(const Data& data,
190  const security::ValidationError& error,
191  const weak_ptr<SegmentFetcher>& weakSelf);
192 
193  void
194  afterNackReceivedCb(const Interest& origInterest, const lp::Nack& nack,
195  const weak_ptr<SegmentFetcher>& weakSelf);
196 
197  void
198  afterTimeoutCb(const Interest& origInterest,
199  const weak_ptr<SegmentFetcher>& weakSelf);
200 
201  void
202  afterNackOrTimeout(const Interest& origInterest);
203 
204  void
205  finalizeFetch();
206 
207  void
208  windowIncrease();
209 
210  void
211  windowDecrease();
212 
213  void
214  signalError(uint32_t code, const std::string& msg);
215 
216  void
217  updateRetransmittedSegment(uint64_t segmentNum,
218  const PendingInterestHandle& pendingInterest,
219  scheduler::EventId timeoutEvent);
220 
221  void
222  cancelExcessInFlightSegments();
223 
224  bool
225  checkAllSegmentsReceived();
226 
228  getEstimatedRto();
229 
230 public:
236 
243 
248 
253 
258 
263 
269 
275 
276 private:
277  enum class SegmentState {
278  FirstInterest,
279  InRetxQueue,
280  Retransmitted,
281  };
282 
283  class PendingSegment
284  {
285  public:
286  SegmentState state;
289  scheduler::ScopedEventId timeoutEvent;
290  };
291 
293  static constexpr double MIN_SSTHRESH = 2.0;
294 
295  shared_ptr<SegmentFetcher> m_this;
296 
297  Options m_options;
298  Face& m_face;
299  Scheduler m_scheduler;
300  security::Validator& m_validator;
301  RttEstimator m_rttEstimator;
302 
303  time::steady_clock::TimePoint m_timeLastSegmentReceived;
304  std::queue<uint64_t> m_retxQueue;
305  Name m_versionedDataName;
306  uint64_t m_nextSegmentNum = 0;
307  double m_cwnd;
308  double m_ssthresh;
309  int64_t m_nSegmentsInFlight = 0;
310  int64_t m_nSegments = 0;
311  uint64_t m_highInterest = 0;
312  uint64_t m_highData = 0;
313  uint64_t m_recPoint = 0;
314  int64_t m_nReceived = 0;
315  int64_t m_nBytesReceived = 0;
316  uint64_t m_nextSegmentInOrder = 0;
317 
318  std::map<uint64_t, Buffer> m_segmentBuffer;
319  std::map<uint64_t, PendingSegment> m_pendingSegments;
320  std::set<uint64_t> m_receivedSegments;
321 };
322 
323 } // namespace util
324 } // namespace ndn
325 
326 #endif // NDN_CXX_UTIL_SEGMENT_FETCHER_HPP
bool inOrder
true for &#39;in order&#39; mode, false for &#39;block&#39; mode
Copyright (c) 2011-2015 Regents of the University of California.
time::milliseconds interestLifetime
lifetime of sent Interests - independent of Interest timeout
ndn security Validator
Definition: validator.cpp:32
RTT/RTO estimator.
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options=Options())
Initiates segment fetching.
An unrecoverable Nack was received during retrieval.
double mdCoef
multiplicative decrease coefficient
Signal< SegmentFetcher, ConstBufferPtr > onComplete
Emitted upon successful retrieval of the complete object (all segments).
time::milliseconds maxTimeout
maximum allowed time between successful receipt of segments
bool useConstantInterestTimeout
if true, Interest timeout is kept at maxTimeout
Utility class to fetch the latest version of a segmented object.
Represents an Interest packet.
Definition: interest.hpp:48
provides a lightweight signal / event system
Definition: signal.hpp:52
Signal< SegmentFetcher > onInOrderComplete
Emitted on successful retrieval of all segments in &#39;in order&#39; mode.
void stop()
Stops fetching.
A handle for a scheduled event.
Definition: scheduler.hpp:58
represents a Network Nack
Definition: nack.hpp:38
double aiStep
additive increase step (in segments)
size_t flowControlWindow
maximum number of segments stored in the reorder buffer
bool disableCwa
disable Conservative Window Adaptation
One of the retrieved segments failed user-provided validation.
ErrorCode
Error codes passed to onError.
Handle for a pending Interest.
Definition: face.hpp:437
Signal< SegmentFetcher > afterSegmentNacked
Emitted whenever an Interest for a data segment is nacked.
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
Signal< SegmentFetcher, Data > afterSegmentValidated
Emitted whenever a received data segment has been successfully validated.
Retrieval timed out because the maximum timeout between the successful receipt of segments was exceed...
One of the retrieved Data packets lacked a segment number in the last Name component (excl...
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Represents an absolute name.
Definition: name.hpp:41
double initSsthresh
initial slow start threshold
Generic time-based scheduler.
Definition: scheduler.hpp:132
double initCwnd
initial congestion window size
bool ignoreCongMarks
disable window decrease after congestion mark received
bool resetCwndToInit
reduce cwnd to initCwnd when loss event occurs
Signal< SegmentFetcher, Data > afterSegmentReceived
Emitted whenever a data segment received.
Signal< SegmentFetcher > afterSegmentTimedOut
Emitted whenever an Interest for a data segment times out.
RttEstimator::Options rttOptions
options for RTT estimator
Signal< SegmentFetcher, uint32_t, std::string > onError
Emitted when the retrieval could not be completed due to an error.
Represents a Data packet.
Definition: data.hpp:37
A received FinalBlockId did not contain a segment component.
bool useConstantCwnd
if true, window size is kept at initCwnd
Signal< SegmentFetcher, ConstBufferPtr > onInOrderData
Emitted after each data segment in segment order has been validated.
time_point TimePoint
Definition: time.hpp:233
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48