blob: d7d1acaeb968fda072e314b6dbfd1900599ceb6f [file] [log] [blame]
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -07001/*
2 * Copyright (c) 2016-2018, Arizona Board of Regents.
Weiwei Liu245d7912016-07-28 00:04:25 -07003 *
4 * This file is part of ndn-tools (Named Data Networking Essential Tools).
5 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
6 *
7 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation,
9 * either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
19 *
20 * @author Shuo Yang
21 * @author Weiwei Liu
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070022 * @author Chavoosh Ghasemi
Weiwei Liu245d7912016-07-28 00:04:25 -070023 */
24
25#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
26#define NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
27
28#include "core/common.hpp"
29
30namespace ndn {
31namespace chunks {
32namespace aimd {
33
34typedef time::duration<double, time::milliseconds::period> Milliseconds;
35
36struct RttRtoSample
37{
38 uint64_t segNo;
39 Milliseconds rtt; ///< measured RTT
40 Milliseconds sRtt; ///< smoothed RTT
41 Milliseconds rttVar; ///< RTT variation
42 Milliseconds rto; ///< retransmission timeout
43};
44
45/**
46 * @brief RTT Estimator.
47 *
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070048 * This class implements the "Mean-Deviation" RTT estimator, as discussed in RFC 6298,
Weiwei Liu245d7912016-07-28 00:04:25 -070049 * with the modifications to RTO calculation described in RFC 7323 Appendix G.
50 */
51class RttEstimator
52{
53public:
54 class Options
55 {
56 public:
57 Options()
58 : isVerbose(false)
59 , alpha(0.125)
60 , beta(0.25)
61 , k(4)
62 , initialRto(1000.0)
63 , minRto(200.0)
64 , maxRto(20000.0)
65 , rtoBackoffMultiplier(2)
66 {
67 }
68
69 public:
70 bool isVerbose;
71 double alpha; ///< parameter for RTT estimation
72 double beta; ///< parameter for RTT variation calculation
73 int k; ///< factor of RTT variation when calculating RTO
74 Milliseconds initialRto; ///< initial RTO value
75 Milliseconds minRto; ///< lower bound of RTO
76 Milliseconds maxRto; ///< upper bound of RTO
77 int rtoBackoffMultiplier;
78 };
79
80 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070081 * @brief Create a RTT Estimator
Weiwei Liu245d7912016-07-28 00:04:25 -070082 *
83 * Configures the RTT Estimator with the default parameters if an instance of Options
84 * is not passed to the constructor.
85 */
86 explicit
87 RttEstimator(const Options& options = Options());
88
89 /**
90 * @brief Add a new RTT measurement to the estimator for the given received segment.
91 *
Weiwei Liu245d7912016-07-28 00:04:25 -070092 * @param segNo the segment number of the received segmented Data
93 * @param rtt the sampled rtt
94 * @param nExpectedSamples number of expected samples, must be greater than 0.
95 * It should be set to current number of in-flight Interests. Please
96 * refer to Appendix G of RFC 7323 for details.
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070097 * @note Don't take RTT measurement for retransmitted segments
Weiwei Liu245d7912016-07-28 00:04:25 -070098 */
99 void
100 addMeasurement(uint64_t segNo, Milliseconds rtt, size_t nExpectedSamples);
101
102 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700103 * @brief Returns the estimated RTO value
Weiwei Liu245d7912016-07-28 00:04:25 -0700104 */
105 Milliseconds
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700106 getEstimatedRto() const
107 {
108 return m_rto;
109 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700110
111 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700112 * @brief Returns the minimum RTT observed
113 */
114 double
115 getMinRtt() const
116 {
117 return m_rttMin;
118 }
119
120 /**
121 * @brief Returns the maximum RTT observed
122 */
123 double
124 getMaxRtt() const
125 {
126 return m_rttMax;
127 }
128
129 /**
130 * @brief Returns the average RTT
131 */
132 double
133 getAvgRtt() const
134 {
135 return m_rttAvg;
136 }
137
138 /**
139 * @brief Backoff RTO by a factor of Options::rtoBackoffMultiplier
Weiwei Liu245d7912016-07-28 00:04:25 -0700140 */
141 void
142 backoffRto();
143
144 /**
145 * @brief Signals after rtt is measured
146 */
147 signal::Signal<RttEstimator, RttRtoSample> afterRttMeasurement;
148
149PUBLIC_WITH_TESTS_ELSE_PRIVATE:
150 const Options m_options;
151 Milliseconds m_sRtt; ///< smoothed round-trip time
152 Milliseconds m_rttVar; ///< round-trip time variation
153 Milliseconds m_rto; ///< retransmission timeout
Weiwei Liu245d7912016-07-28 00:04:25 -0700154
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700155 double m_rttMin;
156 double m_rttMax;
157 double m_rttAvg;
158 int64_t m_nRttSamples; ///< number of RTT samples
159};
Weiwei Liu245d7912016-07-28 00:04:25 -0700160
161std::ostream&
162operator<<(std::ostream& os, const RttEstimator::Options& options);
163
164} // namespace aimd
165} // namespace chunks
166} // namespace ndn
167
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700168#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP