blob: 47f2ac88409499768829057347eb307e295d2c74 [file] [log] [blame]
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -07001/*
schneiderklausd8197df2019-03-16 11:31:40 -07002 * Copyright (c) 2016-2019, 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
schneiderklausd8197df2019-03-16 11:31:40 -070025#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP
26#define NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP
Weiwei Liu245d7912016-07-28 00:04:25 -070027
28#include "core/common.hpp"
29
30namespace ndn {
31namespace chunks {
Weiwei Liu245d7912016-07-28 00:04:25 -070032
33typedef time::duration<double, time::milliseconds::period> Milliseconds;
34
35struct RttRtoSample
36{
37 uint64_t segNo;
38 Milliseconds rtt; ///< measured RTT
39 Milliseconds sRtt; ///< smoothed RTT
40 Milliseconds rttVar; ///< RTT variation
41 Milliseconds rto; ///< retransmission timeout
42};
43
44/**
45 * @brief RTT Estimator.
46 *
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070047 * This class implements the "Mean-Deviation" RTT estimator, as discussed in RFC 6298,
Weiwei Liu245d7912016-07-28 00:04:25 -070048 * with the modifications to RTO calculation described in RFC 7323 Appendix G.
49 */
50class RttEstimator
51{
52public:
53 class Options
54 {
55 public:
56 Options()
57 : isVerbose(false)
58 , alpha(0.125)
59 , beta(0.25)
Klaus Schneider9e5122b2019-03-19 17:03:25 -070060 , k(8)
Weiwei Liu245d7912016-07-28 00:04:25 -070061 , initialRto(1000.0)
62 , minRto(200.0)
63 , maxRto(20000.0)
64 , rtoBackoffMultiplier(2)
65 {
66 }
67
68 public:
69 bool isVerbose;
70 double alpha; ///< parameter for RTT estimation
71 double beta; ///< parameter for RTT variation calculation
72 int k; ///< factor of RTT variation when calculating RTO
73 Milliseconds initialRto; ///< initial RTO value
74 Milliseconds minRto; ///< lower bound of RTO
75 Milliseconds maxRto; ///< upper bound of RTO
76 int rtoBackoffMultiplier;
77 };
78
79 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070080 * @brief Create a RTT Estimator
Weiwei Liu245d7912016-07-28 00:04:25 -070081 *
82 * Configures the RTT Estimator with the default parameters if an instance of Options
83 * is not passed to the constructor.
84 */
85 explicit
86 RttEstimator(const Options& options = Options());
87
88 /**
89 * @brief Add a new RTT measurement to the estimator for the given received segment.
90 *
Weiwei Liu245d7912016-07-28 00:04:25 -070091 * @param segNo the segment number of the received segmented Data
92 * @param rtt the sampled rtt
93 * @param nExpectedSamples number of expected samples, must be greater than 0.
94 * It should be set to current number of in-flight Interests. Please
95 * refer to Appendix G of RFC 7323 for details.
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070096 * @note Don't take RTT measurement for retransmitted segments
Weiwei Liu245d7912016-07-28 00:04:25 -070097 */
98 void
99 addMeasurement(uint64_t segNo, Milliseconds rtt, size_t nExpectedSamples);
100
101 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700102 * @brief Returns the estimated RTO value
Weiwei Liu245d7912016-07-28 00:04:25 -0700103 */
104 Milliseconds
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700105 getEstimatedRto() const
106 {
107 return m_rto;
108 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700109
110 /**
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700111 * @brief Returns the minimum RTT observed
112 */
113 double
114 getMinRtt() const
115 {
116 return m_rttMin;
117 }
118
119 /**
120 * @brief Returns the maximum RTT observed
121 */
122 double
123 getMaxRtt() const
124 {
125 return m_rttMax;
126 }
127
128 /**
129 * @brief Returns the average RTT
130 */
131 double
132 getAvgRtt() const
133 {
134 return m_rttAvg;
135 }
136
137 /**
138 * @brief Backoff RTO by a factor of Options::rtoBackoffMultiplier
Weiwei Liu245d7912016-07-28 00:04:25 -0700139 */
140 void
141 backoffRto();
142
143 /**
144 * @brief Signals after rtt is measured
145 */
146 signal::Signal<RttEstimator, RttRtoSample> afterRttMeasurement;
147
148PUBLIC_WITH_TESTS_ELSE_PRIVATE:
149 const Options m_options;
150 Milliseconds m_sRtt; ///< smoothed round-trip time
151 Milliseconds m_rttVar; ///< round-trip time variation
152 Milliseconds m_rto; ///< retransmission timeout
Weiwei Liu245d7912016-07-28 00:04:25 -0700153
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700154 double m_rttMin;
155 double m_rttMax;
156 double m_rttAvg;
157 int64_t m_nRttSamples; ///< number of RTT samples
158};
Weiwei Liu245d7912016-07-28 00:04:25 -0700159
160std::ostream&
161operator<<(std::ostream& os, const RttEstimator::Options& options);
162
Weiwei Liu245d7912016-07-28 00:04:25 -0700163} // namespace chunks
164} // namespace ndn
165
schneiderklausd8197df2019-03-16 11:31:40 -0700166#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP