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
Definition: data.cpp:26
time::nanoseconds getEstimatedRto() const
Returns the estimated RTO value.
RTT/RTO estimator.
shared_ptr< const Options > m_options
time::nanoseconds initialRto
initial RTO value
time::nanoseconds maxRto
upper bound of RTO
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
time::nanoseconds getMinRtt() const
Returns the minimum RTT observed.
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
double alpha
weight of exponential moving average for smoothed RTT
RTT/RTO estimator that also maintains min/max/average RTT statistics.
time::nanoseconds minRto
lower bound of RTO
RttEstimator(shared_ptr< const Options > options=nullptr)
Constructor.
int k
RTT variation multiplier used when calculating RTO.
time::nanoseconds getAvgRtt() const
Returns the average RTT.
double beta
weight of exponential moving average for RTT variation
time::nanoseconds getSmoothedRtt() const
Returns the smoothed RTT value (SRTT).
time::nanoseconds getMaxRtt() const
Returns the maximum RTT observed.
time::nanoseconds getRttVariation() const
Returns the RTT variation (RTTVAR).
int rtoBackoffMultiplier
RTO multiplier used in backoff operation.