Junxiao Shi | 02e3224 | 2014-05-17 20:51:11 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Junxiao Shi | 02e3224 | 2014-05-17 20:51:11 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 24 | */ |
Junxiao Shi | 02e3224 | 2014-05-17 20:51:11 -0700 | [diff] [blame] | 25 | |
| 26 | #include "fw/rtt-estimator.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace tests { |
| 32 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(Fw) |
| 34 | BOOST_FIXTURE_TEST_SUITE(TestRttEstimator, BaseFixture) |
Junxiao Shi | 02e3224 | 2014-05-17 20:51:11 -0700 | [diff] [blame] | 35 | |
| 36 | static inline double |
| 37 | computeRtoAsFloatSeconds(RttEstimator& rtt) |
| 38 | { |
| 39 | typedef time::duration<double, time::seconds::period> FloatSeconds; |
| 40 | |
| 41 | RttEstimator::Duration rto = rtt.computeRto(); |
| 42 | return time::duration_cast<FloatSeconds>(rto).count(); |
| 43 | } |
| 44 | |
| 45 | BOOST_AUTO_TEST_CASE(Basic) |
| 46 | { |
| 47 | RttEstimator rtt; |
| 48 | |
| 49 | for (int i = 0; i < 100; ++i) { |
| 50 | rtt.addMeasurement(time::seconds(5)); |
| 51 | } |
| 52 | double rto1 = computeRtoAsFloatSeconds(rtt); |
| 53 | BOOST_CHECK_CLOSE(rto1, 5.0, 0.1); |
| 54 | |
| 55 | rtt.doubleMultiplier(); |
| 56 | double rto2 = computeRtoAsFloatSeconds(rtt); |
| 57 | BOOST_CHECK_CLOSE(rto2, 10.0, 0.1); |
| 58 | |
| 59 | rtt.doubleMultiplier(); |
| 60 | double rto3 = computeRtoAsFloatSeconds(rtt); |
| 61 | BOOST_CHECK_CLOSE(rto3, 20.0, 0.1); |
| 62 | |
| 63 | rtt.addMeasurement(time::seconds(5)); // reset multiplier |
| 64 | double rto4 = computeRtoAsFloatSeconds(rtt); |
| 65 | BOOST_CHECK_CLOSE(rto4, 5.0, 0.1); |
| 66 | |
| 67 | rtt.incrementMultiplier(); |
| 68 | double rto5 = computeRtoAsFloatSeconds(rtt); |
| 69 | BOOST_CHECK_CLOSE(rto5, 10.0, 0.1); |
| 70 | |
| 71 | for (int i = 0; i < 5; ++i) { |
| 72 | rtt.addMeasurement(time::seconds(6)); |
| 73 | } // increased variance |
| 74 | double rto6 = computeRtoAsFloatSeconds(rtt); |
| 75 | BOOST_CHECK_GT(rto6, rto1); |
| 76 | } |
| 77 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 78 | BOOST_AUTO_TEST_SUITE_END() // TestRttEstimator |
| 79 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 02e3224 | 2014-05-17 20:51:11 -0700 | [diff] [blame] | 80 | |
| 81 | } // namespace tests |
| 82 | } // namespace nfd |