blob: d254985f8087eb982142235da5da8378dd64eb50 [file] [log] [blame]
Weiwei Liu245d7912016-07-28 00:04:25 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -07002/*
3 * Copyright (c) 2016-2018, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Weiwei Liu245d7912016-07-28 00:04:25 -07006 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Weiwei Liu
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070024 * @author Chavoosh Ghasemi
Weiwei Liu245d7912016-07-28 00:04:25 -070025 */
26
27#include "tools/chunks/catchunks/aimd-rtt-estimator.hpp"
28
29#include "tests/test-common.hpp"
30
31namespace ndn {
32namespace chunks {
33namespace aimd {
34namespace tests {
35
36class RttEstimatorFixture
37{
38protected:
39 RttEstimatorFixture()
40 : options(makeRttEstimatorOptions())
41 , rttEstimator(options)
42 {
43 }
44
45private:
46 static RttEstimator::Options
47 makeRttEstimatorOptions()
48 {
49 RttEstimator::Options rttOptions;
50 rttOptions.alpha = 0.125;
51 rttOptions.beta = 0.25;
52 rttOptions.k = 4;
53 rttOptions.minRto = Milliseconds(200.0);
54 rttOptions.maxRto = Milliseconds(4000.0);
55 return rttOptions;
56 }
57
58protected:
59 RttEstimator::Options options;
60 RttEstimator rttEstimator;
61};
62
63BOOST_AUTO_TEST_SUITE(Chunks)
64BOOST_FIXTURE_TEST_SUITE(TestAimdRttEstimator, RttEstimatorFixture)
65
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070066BOOST_AUTO_TEST_CASE(MinAvgMaxRtt)
67{
68 // check initial values
69 BOOST_CHECK_CLOSE(rttEstimator.m_rttMin, std::numeric_limits<double>::max(), 0.1);
70 BOOST_CHECK_CLOSE(rttEstimator.m_rttAvg, 0.0, 0.1);
71 BOOST_CHECK_CLOSE(rttEstimator.m_rttMax, std::numeric_limits<double>::min(), 0.1);
72 BOOST_CHECK_EQUAL(rttEstimator.m_nRttSamples, 0);
73
74 // start with three samples
75 rttEstimator.addMeasurement(1, Milliseconds(100), 1);
76 rttEstimator.addMeasurement(2, Milliseconds(400), 1);
77 rttEstimator.addMeasurement(3, Milliseconds(250), 1);
78
79 BOOST_CHECK_CLOSE(rttEstimator.m_rttMin, 100, 0.1);
80 BOOST_CHECK_CLOSE(rttEstimator.m_rttAvg, 250, 0.1);
81 BOOST_CHECK_CLOSE(rttEstimator.m_rttMax, 400, 0.1);
82 BOOST_CHECK_EQUAL(rttEstimator.m_nRttSamples, 3);
83
84 // add another sample (new minimum)
85 rttEstimator.addMeasurement(4, Milliseconds(50), 2);
86 BOOST_CHECK_CLOSE(rttEstimator.m_rttMin, 50, 0.1);
87 BOOST_CHECK_CLOSE(rttEstimator.m_rttAvg, 200, 0.1);
88 BOOST_CHECK_CLOSE(rttEstimator.m_rttMax, 400, 0.1);
89 BOOST_CHECK_EQUAL(rttEstimator.m_nRttSamples, 4);
90
91 // add another sample (new maximum)
92 rttEstimator.addMeasurement(5, Milliseconds(700), 1);
93 BOOST_CHECK_CLOSE(rttEstimator.m_rttMin, 50, 0.1);
94 BOOST_CHECK_CLOSE(rttEstimator.m_rttAvg, 300, 0.1);
95 BOOST_CHECK_CLOSE(rttEstimator.m_rttMax, 700, 0.1);
96 BOOST_CHECK_EQUAL(rttEstimator.m_nRttSamples, 5);
97}
98
Weiwei Liu245d7912016-07-28 00:04:25 -070099BOOST_AUTO_TEST_CASE(MeasureRtt)
100{
101 BOOST_REQUIRE(std::isnan(rttEstimator.m_sRtt.count()));
102 BOOST_REQUIRE(std::isnan(rttEstimator.m_rttVar.count()));
103 BOOST_REQUIRE_CLOSE(rttEstimator.m_rto.count(), options.initialRto.count(), 1);
104
105 // first measurement
106 rttEstimator.addMeasurement(1, Milliseconds(100), 1);
107
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700108 BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 100, 0.1);
109 BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 50, 0.1);
110 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 300, 0.1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700111
112 rttEstimator.m_sRtt = Milliseconds(500.0);
113 rttEstimator.m_rttVar = Milliseconds(100.0);
114 rttEstimator.m_rto = Milliseconds(900.0);
115
116 size_t nExpectedSamples = 1;
117 rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples);
118
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700119 BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 450, 0.1);
120 BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 175, 0.1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700121 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1150, 0.1);
122
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700123 // expected samples larger than 1
Weiwei Liu245d7912016-07-28 00:04:25 -0700124 nExpectedSamples = 5;
125 rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples);
126
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700127 BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 441.25, 0.1);
128 BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 183.75, 0.1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700129 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1176.25, 0.1);
130
131 rttEstimator.m_sRtt = Milliseconds(100.0);
132 rttEstimator.m_rttVar = Milliseconds(30.0);
133 rttEstimator.m_rto = Milliseconds(220.0);
134
135 // check if minRto works
136 nExpectedSamples = 1;
137 rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples);
138
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -0700139 BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 100, 0.1);
140 BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 22.5, 0.1);
141 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 200, 0.1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700142
143 rttEstimator.m_sRtt = Milliseconds(2000.0);
144 rttEstimator.m_rttVar = Milliseconds(400.0);
145 rttEstimator.m_rto = Milliseconds(3600.0);
146
147 // check if maxRto works
148 nExpectedSamples = 1;
149 rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples);
150
151 BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 1762.5, 0.1);
152 BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 775, 0.1);
153 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 4000, 0.1);
154}
155
156BOOST_AUTO_TEST_CASE(RtoBackoff)
157{
158 rttEstimator.m_rto = Milliseconds(500.0);
159 rttEstimator.backoffRto();
160 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1000, 0.1);
161
162 // check if minRto works
163 rttEstimator.m_rto = Milliseconds(10.0);
164 rttEstimator.backoffRto();
165 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 200, 0.1);
166
167 // check if maxRto works
168 rttEstimator.m_rto = Milliseconds(3000.0);
169 rttEstimator.backoffRto();
170 BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 4000, 0.1);
171}
172
173BOOST_AUTO_TEST_SUITE_END() // TestAimdRttEstimator
174BOOST_AUTO_TEST_SUITE_END() // Chunks
175
176} // namespace tests
177} // namespace aimd
178} // namespace chunks
179} // namespace ndn