NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
rtt-estimator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (C) 2016-2019, Arizona Board of Regents.
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  * @author Shuo Yang
22  * @author Weiwei Liu
23  * @author Chavoosh Ghasemi
24  * @author Davide Pesavento
25  */
26 
27 #ifndef NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
28 #define NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
29 
30 #include "ndn-cxx/util/time.hpp"
31 
32 namespace ndn {
33 namespace util {
34 
42 {
43 public:
44  struct Options
45  {
46  double alpha = 0.125;
47  double beta = 0.25;
48  time::nanoseconds initialRto = 1_s;
49  time::nanoseconds minRto = 200_ms;
50  time::nanoseconds maxRto = 1_min;
51  int k = 4;
53  };
54 
59  explicit
60  RttEstimator(shared_ptr<const Options> options = nullptr);
61 
70  void
71  addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples = 1);
72 
73  bool
74  hasSamples() const
75  {
76  return m_sRtt != -1_ns;
77  }
78 
82  time::nanoseconds
84  {
85  return m_rto;
86  }
87 
92  time::nanoseconds
94  {
95  return m_sRtt;
96  }
97 
102  time::nanoseconds
104  {
105  return m_rttVar;
106  }
107 
111  void
112  backoffRto();
113 
114 protected:
115  shared_ptr<const Options> m_options;
116 
117 private:
118  time::nanoseconds m_sRtt{-1};
119  time::nanoseconds m_rttVar{-1};
120  time::nanoseconds m_rto;
121 };
122 
127 {
128 public:
129  using RttEstimator::Options;
131 
137 
146  void
147  addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples = 1);
148 
152  time::nanoseconds
153  getMinRtt() const
154  {
155  return m_rttMin;
156  }
157 
161  time::nanoseconds
162  getMaxRtt() const
163  {
164  return m_rttMax;
165  }
166 
170  time::nanoseconds
171  getAvgRtt() const
172  {
173  return m_rttAvg;
174  }
175 
176 private:
177  time::nanoseconds m_rttMin = time::nanoseconds::max();
178  time::nanoseconds m_rttMax = time::nanoseconds::min();
179  time::nanoseconds m_rttAvg = 0_ns;
180  int64_t m_nRttSamples = 0;
181 };
182 
183 } // namespace util
184 } // namespace ndn
185 
186 #endif // NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
ndn::util::RttEstimatorWithStats
RTT/RTO estimator that also maintains min/max/average RTT statistics.
Definition: rtt-estimator.hpp:127
ndn::util::RttEstimatorWithStats::getAvgRtt
time::nanoseconds getAvgRtt() const
Returns the average RTT.
Definition: rtt-estimator.hpp:171
ndn::util::RttEstimatorWithStats::getMaxRtt
time::nanoseconds getMaxRtt() const
Returns the maximum RTT observed.
Definition: rtt-estimator.hpp:162
ndn::util::RttEstimatorWithStats::addMeasurement
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
Definition: rtt-estimator.cpp:74
ndn::util::RttEstimator::Options::beta
double beta
weight of exponential moving average for RTT variation
Definition: rtt-estimator.hpp:47
ndn::util::RttEstimator::RttEstimator
RttEstimator(shared_ptr< const Options > options=nullptr)
Constructor.
Definition: rtt-estimator.cpp:32
ndn::util::RttEstimator::Options::k
int k
RTT variation multiplier used when calculating RTO.
Definition: rtt-estimator.hpp:51
ndn::util::RttEstimator::getRttVariation
time::nanoseconds getRttVariation() const
Returns the RTT variation (RTTVAR).
Definition: rtt-estimator.hpp:103
ndn::util::RttEstimator::m_options
shared_ptr< const Options > m_options
Definition: rtt-estimator.hpp:115
ndn::util::RttEstimator::Options::rtoBackoffMultiplier
int rtoBackoffMultiplier
RTO multiplier used in backoff operation.
Definition: rtt-estimator.hpp:52
ndn::util::RttEstimator::Options::minRto
time::nanoseconds minRto
lower bound of RTO
Definition: rtt-estimator.hpp:49
ndn::util::RttEstimator::getEstimatedRto
time::nanoseconds getEstimatedRto() const
Returns the estimated RTO value.
Definition: rtt-estimator.hpp:83
ndn::util::RttEstimator::Options::initialRto
time::nanoseconds initialRto
initial RTO value
Definition: rtt-estimator.hpp:48
ndn::util::RttEstimatorWithStats::getMinRtt
time::nanoseconds getMinRtt() const
Returns the minimum RTT observed.
Definition: rtt-estimator.hpp:153
ndn::util::RttEstimator::addMeasurement
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
Definition: rtt-estimator.cpp:46
ndn::util::RttEstimator
RTT/RTO estimator.
Definition: rtt-estimator.hpp:42
ndn::util::RttEstimator::Options
Definition: rtt-estimator.hpp:45
time.hpp
ndn::util::RttEstimator::Options::maxRto
time::nanoseconds maxRto
upper bound of RTO
Definition: rtt-estimator.hpp:50
ndn::util::RttEstimator::getSmoothedRtt
time::nanoseconds getSmoothedRtt() const
Returns the smoothed RTT value (SRTT).
Definition: rtt-estimator.hpp:93
ndn::util::RttEstimator::hasSamples
bool hasSamples() const
Definition: rtt-estimator.hpp:74
ndn::util::RttEstimator::backoffRto
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
Definition: rtt-estimator.cpp:67
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::util::RttEstimator::Options::alpha
double alpha
weight of exponential moving average for smoothed RTT
Definition: rtt-estimator.hpp:46