Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
| 6 | * |
| 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 |
| 24 | */ |
| 25 | |
| 26 | #include "tools/chunks/catchunks/aimd-rtt-estimator.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace chunks { |
| 32 | namespace aimd { |
| 33 | namespace tests { |
| 34 | |
| 35 | class RttEstimatorFixture |
| 36 | { |
| 37 | protected: |
| 38 | RttEstimatorFixture() |
| 39 | : options(makeRttEstimatorOptions()) |
| 40 | , rttEstimator(options) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | static RttEstimator::Options |
| 46 | makeRttEstimatorOptions() |
| 47 | { |
| 48 | RttEstimator::Options rttOptions; |
| 49 | rttOptions.alpha = 0.125; |
| 50 | rttOptions.beta = 0.25; |
| 51 | rttOptions.k = 4; |
| 52 | rttOptions.minRto = Milliseconds(200.0); |
| 53 | rttOptions.maxRto = Milliseconds(4000.0); |
| 54 | return rttOptions; |
| 55 | } |
| 56 | |
| 57 | protected: |
| 58 | RttEstimator::Options options; |
| 59 | RttEstimator rttEstimator; |
| 60 | }; |
| 61 | |
| 62 | BOOST_AUTO_TEST_SUITE(Chunks) |
| 63 | BOOST_FIXTURE_TEST_SUITE(TestAimdRttEstimator, RttEstimatorFixture) |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(MeasureRtt) |
| 66 | { |
| 67 | BOOST_REQUIRE(std::isnan(rttEstimator.m_sRtt.count())); |
| 68 | BOOST_REQUIRE(std::isnan(rttEstimator.m_rttVar.count())); |
| 69 | BOOST_REQUIRE_CLOSE(rttEstimator.m_rto.count(), options.initialRto.count(), 1); |
| 70 | |
| 71 | // first measurement |
| 72 | rttEstimator.addMeasurement(1, Milliseconds(100), 1); |
| 73 | |
| 74 | BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 100, 1); |
| 75 | BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 50, 1); |
| 76 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 300, 1); |
| 77 | |
| 78 | rttEstimator.m_sRtt = Milliseconds(500.0); |
| 79 | rttEstimator.m_rttVar = Milliseconds(100.0); |
| 80 | rttEstimator.m_rto = Milliseconds(900.0); |
| 81 | |
| 82 | size_t nExpectedSamples = 1; |
| 83 | rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples); |
| 84 | |
| 85 | BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 450, 1); |
| 86 | BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 175, 1); |
| 87 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1150, 0.1); |
| 88 | |
| 89 | // expected Samples larger than 1 |
| 90 | nExpectedSamples = 5; |
| 91 | rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples); |
| 92 | |
| 93 | BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 441.25, 1); |
| 94 | BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 183.75, 1); |
| 95 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1176.25, 0.1); |
| 96 | |
| 97 | rttEstimator.m_sRtt = Milliseconds(100.0); |
| 98 | rttEstimator.m_rttVar = Milliseconds(30.0); |
| 99 | rttEstimator.m_rto = Milliseconds(220.0); |
| 100 | |
| 101 | // check if minRto works |
| 102 | nExpectedSamples = 1; |
| 103 | rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples); |
| 104 | |
| 105 | BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 100, 1); |
| 106 | BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 22.5, 1); |
| 107 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 200, 1); |
| 108 | |
| 109 | rttEstimator.m_sRtt = Milliseconds(2000.0); |
| 110 | rttEstimator.m_rttVar = Milliseconds(400.0); |
| 111 | rttEstimator.m_rto = Milliseconds(3600.0); |
| 112 | |
| 113 | // check if maxRto works |
| 114 | nExpectedSamples = 1; |
| 115 | rttEstimator.addMeasurement(1, Milliseconds(100), nExpectedSamples); |
| 116 | |
| 117 | BOOST_CHECK_CLOSE(rttEstimator.m_sRtt.count(), 1762.5, 0.1); |
| 118 | BOOST_CHECK_CLOSE(rttEstimator.m_rttVar.count(), 775, 0.1); |
| 119 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 4000, 0.1); |
| 120 | } |
| 121 | |
| 122 | BOOST_AUTO_TEST_CASE(RtoBackoff) |
| 123 | { |
| 124 | rttEstimator.m_rto = Milliseconds(500.0); |
| 125 | rttEstimator.backoffRto(); |
| 126 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 1000, 0.1); |
| 127 | |
| 128 | // check if minRto works |
| 129 | rttEstimator.m_rto = Milliseconds(10.0); |
| 130 | rttEstimator.backoffRto(); |
| 131 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 200, 0.1); |
| 132 | |
| 133 | // check if maxRto works |
| 134 | rttEstimator.m_rto = Milliseconds(3000.0); |
| 135 | rttEstimator.backoffRto(); |
| 136 | BOOST_CHECK_CLOSE(rttEstimator.m_rto.count(), 4000, 0.1); |
| 137 | } |
| 138 | |
| 139 | BOOST_AUTO_TEST_SUITE_END() // TestAimdRttEstimator |
| 140 | BOOST_AUTO_TEST_SUITE_END() // Chunks |
| 141 | |
| 142 | } // namespace tests |
| 143 | } // namespace aimd |
| 144 | } // namespace chunks |
| 145 | } // namespace ndn |