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-2018, Regents of the University of California,
4  * Colorado State University,
5  * University Pierre & Marie Curie, Sorbonne University.
6  *
7  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
8  *
9  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free Software
11  * Foundation, either version 3 of the License, or (at your option) any later version.
12  *
13  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16  *
17  * You should have received copies of the GNU General Public License and GNU Lesser
18  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22  *
23  * @author Shuo Yang
24  * @author Weiwei Liu
25  * @author Chavoosh Ghasemi
26  */
27 
28 #ifndef NDN_UTIL_SEGMENT_FETCHER_HPP
29 #define NDN_UTIL_SEGMENT_FETCHER_HPP
30 
31 #include "ndn-cxx/face.hpp"
35 #include "ndn-cxx/util/signal.hpp"
36 
37 #include <queue>
38 
39 namespace ndn {
40 namespace util {
41 
97 class SegmentFetcher : noncopyable
98 {
99 public:
103  enum ErrorCode {
114  };
115 
116  class Options
117  {
118  public:
120  {
121  }
122 
123  void
124  validate();
125 
126  public:
127  bool useConstantCwnd = false;
129  time::milliseconds maxTimeout = 60_s;
130  time::milliseconds interestLifetime = 4_s;
131  double initCwnd = 1.0;
132  double initSsthresh = std::numeric_limits<double>::max();
133  double aiStep = 1.0;
134  double mdCoef = 0.5;
135  bool disableCwa = false;
136  bool resetCwndToInit = false;
137  bool ignoreCongMarks = false;
139  };
140 
163  static shared_ptr<SegmentFetcher>
164  start(Face& face,
165  const Interest& baseInterest,
166  security::v2::Validator& validator,
167  const Options& options = Options());
168 
174  void
175  stop();
176 
177 private:
178  class PendingSegment;
179 
180  SegmentFetcher(Face& face, security::v2::Validator& validator, const Options& options);
181 
182  static bool
183  shouldStop(const weak_ptr<SegmentFetcher>& weakSelf);
184 
185  void
186  fetchFirstSegment(const Interest& baseInterest, bool isRetransmission);
187 
188  void
189  fetchSegmentsInWindow(const Interest& origInterest);
190 
191  void
192  afterSegmentReceivedCb(const Interest& origInterest, const Data& data,
193  const weak_ptr<SegmentFetcher>& weakSelf);
194 
195  void
196  afterValidationSuccess(const Data& data, const Interest& origInterest,
198  const weak_ptr<SegmentFetcher>& weakSelf);
199 
200  void
201  afterValidationFailure(const Data& data,
202  const security::v2::ValidationError& error,
203  const weak_ptr<SegmentFetcher>& weakSelf);
204 
205  void
206  afterNackReceivedCb(const Interest& origInterest, const lp::Nack& nack,
207  const weak_ptr<SegmentFetcher>& weakSelf);
208 
209  void
210  afterTimeoutCb(const Interest& origInterest,
211  const weak_ptr<SegmentFetcher>& weakSelf);
212 
213  void
214  afterNackOrTimeout(const Interest& origInterest);
215 
216  void
217  finalizeFetch();
218 
219  void
220  windowIncrease();
221 
222  void
223  windowDecrease();
224 
225  void
226  signalError(uint32_t code, const std::string& msg);
227 
228  void
229  updateRetransmittedSegment(uint64_t segmentNum,
230  const PendingInterestId* pendingInterest,
231  scheduler::EventId timeoutEvent);
232 
233  void
234  cancelExcessInFlightSegments();
235 
236  bool
237  checkAllSegmentsReceived();
238 
239  time::milliseconds
240  getEstimatedRto();
241 
242 public:
247 
254 
259 
264 
269 
274 
275 private:
276  enum class SegmentState {
277  FirstInterest,
278  InRetxQueue,
279  Retransmitted,
280  };
281 
282  class PendingSegment
283  {
284  public:
285  SegmentState state;
287  const PendingInterestId* id;
288  scheduler::EventId timeoutEvent;
289  };
290 
292  static constexpr double MIN_SSTHRESH = 2.0;
293 
294  shared_ptr<SegmentFetcher> m_this;
295 
296  Options m_options;
297  Face& m_face;
298  Scheduler m_scheduler;
299  security::v2::Validator& m_validator;
300  RttEstimator m_rttEstimator;
301  time::milliseconds m_timeout;
302 
303  time::steady_clock::TimePoint m_timeLastSegmentReceived;
304  std::queue<uint64_t> m_retxQueue;
305  Name m_versionedDataName;
306  uint64_t m_nextSegmentNum;
307  double m_cwnd;
308  double m_ssthresh;
309  int64_t m_nSegmentsInFlight;
310  int64_t m_nSegments;
311  uint64_t m_highInterest;
312  uint64_t m_highData;
313  uint64_t m_recPoint;
314  int64_t m_nReceived;
315  int64_t m_nBytesReceived;
316 
317  std::map<uint64_t, Buffer> m_receivedSegments;
318  std::map<uint64_t, PendingSegment> m_pendingSegments;
319 };
320 
321 } // namespace util
322 } // namespace ndn
323 
324 #endif // NDN_UTIL_SEGMENT_FETCHER_HPP
time_point TimePoint
Definition: time.hpp:225
Copyright (c) 2011-2015 Regents of the University of California.
time::milliseconds interestLifetime
lifetime of sent Interests - independent of Interest timeout
An unrecoverable Nack was received during retrieval.
double mdCoef
multiplicative decrease coefficient
Signal< SegmentFetcher, ConstBufferPtr > onComplete
Emits upon successful retrieval of the complete data.
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:44
provides a lightweight signal / event system
Definition: signal.hpp:51
void stop()
Stops fetching.
represents a Network Nack
Definition: nack.hpp:38
Table::const_iterator iterator
Definition: cs-internal.hpp:41
double aiStep
additive increase step (in segments)
bool disableCwa
disable Conservative Window Adaptation
One of the retrieved segments failed user-provided validation.
ErrorCode
Error codes passed to onError.
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::v2::Validator &validator, const Options &options=Options())
Initiates segment fetching.
Signal< SegmentFetcher > afterSegmentNacked
Emits whenever an Interest for a data segment is nacked.
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:93
Signal< SegmentFetcher, Data > afterSegmentValidated
Emits 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:43
Represents an absolute name.
Definition: name.hpp:43
double initSsthresh
initial slow start threshold
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
Emits whenever a data segment received.
Signal< SegmentFetcher > afterSegmentTimedOut
Emits whenever an Interest for a data segment times out.
RttEstimator::Options rttOptions
options for RTT estimator
Validation error code and optional detailed error message.
ndn RttEstimator
Signal< SegmentFetcher, uint32_t, std::string > onError
Emits when the retrieval could not be completed due to an error.
A handle of scheduled event.
Definition: scheduler.hpp:55
Represents a Data packet.
Definition: data.hpp:35
A received FinalBlockId did not contain a segment component.
bool useConstantCwnd
if true, window size is kept at initCwnd
Interface for validating data and interest packets.
Definition: validator.hpp:61