blob: 292395a0fde5f7e6fcc75cf3973759afe66d5b5d [file] [log] [blame]
Weiwei Liu245d7912016-07-28 00:04:25 -07001/**
2 * Copyright (c) 2016, Arizona Board of Regents.
3 *
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
22 */
23
24#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
25#define NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
26
27#include "core/common.hpp"
28
29namespace ndn {
30namespace chunks {
31namespace aimd {
32
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 *
47 * This class implements the "Mean--Deviation" RTT estimator, as discussed in RFC6298,
48 * 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)
60 , k(4)
61 , 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 /**
80 * @brief create a RTT Estimator
81 *
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 *
91 * @note Don't take RTT measurement for retransmitted segments
92 * @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.
97 */
98 void
99 addMeasurement(uint64_t segNo, Milliseconds rtt, size_t nExpectedSamples);
100
101 /**
102 * @return estimated RTO
103 */
104 Milliseconds
105 getEstimatedRto() const;
106
107 /**
108 * @brief backoff RTO by the factor of RttEstimatorOptions::rtoBackoffMultiplier
109 */
110 void
111 backoffRto();
112
113 /**
114 * @brief Signals after rtt is measured
115 */
116 signal::Signal<RttEstimator, RttRtoSample> afterRttMeasurement;
117
118PUBLIC_WITH_TESTS_ELSE_PRIVATE:
119 const Options m_options;
120 Milliseconds m_sRtt; ///< smoothed round-trip time
121 Milliseconds m_rttVar; ///< round-trip time variation
122 Milliseconds m_rto; ///< retransmission timeout
123};
124
125/**
126 * @brief returns the estimated RTO value
127 */
128inline Milliseconds
129RttEstimator::getEstimatedRto() const
130{
131 return m_rto;
132}
133
134std::ostream&
135operator<<(std::ostream& os, const RttEstimator::Options& options);
136
137} // namespace aimd
138} // namespace chunks
139} // namespace ndn
140
141#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP