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-2018, 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  */
25 
26 #ifndef NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
27 #define NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
28 
29 #include "../common.hpp"
30 #include "signal.hpp"
31 #include "time.hpp"
32 
33 namespace ndn {
34 namespace util {
35 
43 {
44 public:
45  using MillisecondsDouble = time::duration<double, time::milliseconds::period>;
46 
47 public:
48  class Options
49  {
50  public:
51  constexpr
52  Options() noexcept
53  {
54  }
55 
56  public:
57  double alpha = 0.125;
58  double beta = 0.25;
59  int k = 4;
64  };
65 
72  explicit
73  RttEstimator(const Options& options = Options());
74 
84  void
85  addMeasurement(MillisecondsDouble rtt, size_t nExpectedSamples);
86 
92  {
93  return m_rto;
94  }
95 
100  getMinRtt() const
101  {
102  return m_rttMin;
103  }
104 
109  getMaxRtt() const
110  {
111  return m_rttMax;
112  }
113 
118  getAvgRtt() const
119  {
120  return m_rttAvg;
121  }
122 
126  void
127  backoffRto();
128 
129 private:
130  const Options m_options;
131  MillisecondsDouble m_sRtt;
132  MillisecondsDouble m_rttVar;
133  MillisecondsDouble m_rto;
134  MillisecondsDouble m_rttMin;
135  MillisecondsDouble m_rttMax;
136  MillisecondsDouble m_rttAvg;
137  int64_t m_nRttSamples;
138 };
139 
140 } // namespace util
141 } // namespace ndn
142 
143 #endif // NDN_CXX_UTIL_RTT_ESTIMATOR_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:65
MillisecondsDouble minRto
lower bound of RTO
double alpha
weight of exponential moving average for meanRtt
double beta
weight of exponential moving average for varRtt
MillisecondsDouble getEstimatedRto() const
Returns the estimated RTO value.
MillisecondsDouble getMaxRtt() const
Returns the maximum RTT observed.
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
RttEstimator(const Options &options=Options())
Create a RTT Estimator.
MillisecondsDouble initialRto
initial RTO value
void addMeasurement(MillisecondsDouble rtt, size_t nExpectedSamples)
Add a new RTT measurement to the estimator.
MillisecondsDouble getAvgRtt() const
Returns the average RTT.
MillisecondsDouble maxRto
upper bound of RTO
MillisecondsDouble getMinRtt() const
Returns the minimum RTT observed.
int k
factor of RTT variation when calculating RTO
time::duration< double, time::milliseconds::period > MillisecondsDouble