Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 1 | /* |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2019, Arizona Board of Regents. |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 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 |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 22 | * @author Chavoosh Ghasemi |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 25 | #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP |
| 26 | #define NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 27 | |
| 28 | #include "core/common.hpp" |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace chunks { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 32 | |
| 33 | typedef time::duration<double, time::milliseconds::period> Milliseconds; |
| 34 | |
| 35 | struct 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 Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 47 | * This class implements the "Mean-Deviation" RTT estimator, as discussed in RFC 6298, |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 48 | * with the modifications to RTO calculation described in RFC 7323 Appendix G. |
| 49 | */ |
| 50 | class RttEstimator |
| 51 | { |
| 52 | public: |
| 53 | class Options |
| 54 | { |
| 55 | public: |
| 56 | Options() |
| 57 | : isVerbose(false) |
| 58 | , alpha(0.125) |
| 59 | , beta(0.25) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame^] | 60 | , k(8) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 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 | /** |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 80 | * @brief Create a RTT Estimator |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 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 | * |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 91 | * @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 Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 96 | * @note Don't take RTT measurement for retransmitted segments |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 97 | */ |
| 98 | void |
| 99 | addMeasurement(uint64_t segNo, Milliseconds rtt, size_t nExpectedSamples); |
| 100 | |
| 101 | /** |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 102 | * @brief Returns the estimated RTO value |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 103 | */ |
| 104 | Milliseconds |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 105 | getEstimatedRto() const |
| 106 | { |
| 107 | return m_rto; |
| 108 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 111 | * @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 Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 139 | */ |
| 140 | void |
| 141 | backoffRto(); |
| 142 | |
| 143 | /** |
| 144 | * @brief Signals after rtt is measured |
| 145 | */ |
| 146 | signal::Signal<RttEstimator, RttRtoSample> afterRttMeasurement; |
| 147 | |
| 148 | PUBLIC_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 Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 153 | |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 154 | double m_rttMin; |
| 155 | double m_rttMax; |
| 156 | double m_rttAvg; |
| 157 | int64_t m_nRttSamples; ///< number of RTT samples |
| 158 | }; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 159 | |
| 160 | std::ostream& |
| 161 | operator<<(std::ostream& os, const RttEstimator::Options& options); |
| 162 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 163 | } // namespace chunks |
| 164 | } // namespace ndn |
| 165 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 166 | #endif // NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP |