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-2024, 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 #include <memory>
33 
34 namespace ndn::util {
35 
43 {
44 public:
45  struct Options
46  {
47  double alpha = 0.125;
48  double beta = 0.25;
52  int k = 4;
54  };
55 
60  explicit
61  RttEstimator(std::shared_ptr<const Options> options = nullptr);
62 
71  void
72  addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples = 1);
73 
74  bool
75  hasSamples() const
76  {
77  return m_sRtt != -1_ns;
78  }
79 
85  {
86  return m_rto;
87  }
88 
95  {
96  return m_sRtt;
97  }
98 
105  {
106  return m_rttVar;
107  }
108 
112  void
113  backoffRto();
114 
115 protected:
116  std::shared_ptr<const Options> m_options;
117 
118 private:
119  time::nanoseconds m_sRtt{-1};
120  time::nanoseconds m_rttVar{-1};
121  time::nanoseconds m_rto;
122 };
123 
128 {
129 public:
130  using RttEstimator::Options;
132 
138 
147  void
148  addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples = 1);
149 
154  getMinRtt() const
155  {
156  return m_rttMin;
157  }
158 
163  getMaxRtt() const
164  {
165  return m_rttMax;
166  }
167 
172  getAvgRtt() const
173  {
174  return m_rttAvg;
175  }
176 
177 private:
178  time::nanoseconds m_rttMin = time::nanoseconds::max();
179  time::nanoseconds m_rttMax = time::nanoseconds::min();
180  time::nanoseconds m_rttAvg = 0_ns;
181  int64_t m_nRttSamples = 0;
182 };
183 
184 } // namespace ndn::util
185 
186 #endif // NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
RTT/RTO estimator that also maintains min/max/average RTT statistics.
time::nanoseconds getMinRtt() const
Returns the minimum RTT observed.
time::nanoseconds getMaxRtt() const
Returns the maximum RTT observed.
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
time::nanoseconds getAvgRtt() const
Returns the average RTT.
RTT/RTO estimator.
time::nanoseconds getSmoothedRtt() const
Returns the smoothed RTT value (SRTT).
time::nanoseconds getRttVariation() const
Returns the RTT variation (RTTVAR).
std::shared_ptr< const Options > m_options
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
RttEstimator(std::shared_ptr< const Options > options=nullptr)
Constructor.
time::nanoseconds getEstimatedRto() const
Returns the estimated RTO value.
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54
time::nanoseconds maxRto
upper bound of RTO
time::nanoseconds minRto
lower bound of RTO
double alpha
weight of exponential moving average for smoothed RTT
time::nanoseconds initialRto
initial RTO value
int rtoBackoffMultiplier
RTO multiplier used in backoff operation.
double beta
weight of exponential moving average for RTT variation
int k
RTT variation multiplier used when calculating RTO.