blob: 6673ecdd08fd1a0482cfd1c7681ccbdf1adba0ab [file] [log] [blame]
Junxiao Shi02e32242014-05-17 20:51:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 Shi02e32242014-05-17 20:51:11 -070010 *
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 Mastorakisd0381c02015-02-19 10:29:41 -080024 */
Junxiao Shi02e32242014-05-17 20:51:11 -070025
Eric Newberry185ab292017-03-28 06:45:39 +000026#include "core/rtt-estimator.hpp"
Junxiao Shi02e32242014-05-17 20:51:11 -070027
28#include "tests/test-common.hpp"
29
30namespace nfd {
31namespace tests {
32
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040033BOOST_AUTO_TEST_SUITE(TestRttEstimator)
Junxiao Shi02e32242014-05-17 20:51:11 -070034
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040035static double
Junxiao Shi02e32242014-05-17 20:51:11 -070036computeRtoAsFloatSeconds(RttEstimator& rtt)
37{
38 typedef time::duration<double, time::seconds::period> FloatSeconds;
39
40 RttEstimator::Duration rto = rtt.computeRto();
41 return time::duration_cast<FloatSeconds>(rto).count();
42}
43
44BOOST_AUTO_TEST_CASE(Basic)
45{
46 RttEstimator rtt;
47
48 for (int i = 0; i < 100; ++i) {
Davide Pesavento14e71f02019-03-28 17:35:25 -040049 rtt.addMeasurement(5_s);
Junxiao Shi02e32242014-05-17 20:51:11 -070050 }
51 double rto1 = computeRtoAsFloatSeconds(rtt);
52 BOOST_CHECK_CLOSE(rto1, 5.0, 0.1);
53
54 rtt.doubleMultiplier();
55 double rto2 = computeRtoAsFloatSeconds(rtt);
56 BOOST_CHECK_CLOSE(rto2, 10.0, 0.1);
57
58 rtt.doubleMultiplier();
59 double rto3 = computeRtoAsFloatSeconds(rtt);
60 BOOST_CHECK_CLOSE(rto3, 20.0, 0.1);
61
Davide Pesavento14e71f02019-03-28 17:35:25 -040062 rtt.addMeasurement(5_s); // reset multiplier
Junxiao Shi02e32242014-05-17 20:51:11 -070063 double rto4 = computeRtoAsFloatSeconds(rtt);
64 BOOST_CHECK_CLOSE(rto4, 5.0, 0.1);
65
66 rtt.incrementMultiplier();
67 double rto5 = computeRtoAsFloatSeconds(rtt);
68 BOOST_CHECK_CLOSE(rto5, 10.0, 0.1);
69
70 for (int i = 0; i < 5; ++i) {
Davide Pesavento14e71f02019-03-28 17:35:25 -040071 rtt.addMeasurement(6_s);
Junxiao Shi02e32242014-05-17 20:51:11 -070072 } // increased variance
73 double rto6 = computeRtoAsFloatSeconds(rtt);
74 BOOST_CHECK_GT(rto6, rto1);
75}
76
Davide Pesavento97210d52016-10-14 15:45:48 +020077BOOST_AUTO_TEST_SUITE_END() // TestRttEstimator
Junxiao Shi02e32242014-05-17 20:51:11 -070078
79} // namespace tests
80} // namespace nfd