blob: d08f7614b8b563cf60a1acb2f6e916e2aa088c69 [file] [log] [blame]
Vince Lehman8a4c29e2016-07-11 08:49:35 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopud3ae85d2019-02-17 02:29:55 +00002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Vince Lehman8a4c29e2016-07-11 08:49:35 +00004 * 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.
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/>.
24 */
25
26#include "fw/asf-measurements.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060027#include "daemon/global.hpp"
Vince Lehman8a4c29e2016-07-11 08:49:35 +000028
Vince Lehman8a4c29e2016-07-11 08:49:35 +000029#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/daemon/global-io-fixture.hpp"
31#include "tests/daemon/face/dummy-face.hpp"
Vince Lehman8a4c29e2016-07-11 08:49:35 +000032
33namespace nfd {
34namespace fw {
35namespace asf {
36namespace tests {
37
38using namespace nfd::tests;
39
40BOOST_AUTO_TEST_SUITE(Fw)
41BOOST_AUTO_TEST_SUITE(TestAsfMeasurements)
42
43BOOST_AUTO_TEST_SUITE(TestRttStats)
44
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040045BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoFixture)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000046{
47 RttStats stats;
48
49 BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_NO_MEASUREMENT);
50 BOOST_CHECK_EQUAL(stats.getSrtt(), RttStats::RTT_NO_MEASUREMENT);
51
52 // Receive Data back in 50ms
Davide Pesavento14e71f02019-03-28 17:35:25 -040053 RttEstimator::Duration rtt(50_ms);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000054 stats.addRttMeasurement(rtt);
55
56 BOOST_CHECK_EQUAL(stats.getRtt(), rtt);
57 BOOST_CHECK_EQUAL(stats.getSrtt(), rtt);
58
59 // Receive Data back in 50ms
60 stats.addRttMeasurement(rtt);
61
62 BOOST_CHECK_EQUAL(stats.getRtt(), rtt);
63 BOOST_CHECK_EQUAL(stats.getSrtt(), rtt);
64
65 // Receive Data back with a higher RTT
Davide Pesavento14e71f02019-03-28 17:35:25 -040066 RttEstimator::Duration higherRtt(100_ms);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000067 stats.addRttMeasurement(higherRtt);
68
69 BOOST_CHECK_EQUAL(stats.getRtt(), higherRtt);
70 BOOST_CHECK_GT(stats.getSrtt(), rtt);
71 BOOST_CHECK_LT(stats.getSrtt(), higherRtt);
72
73 // Simulate timeout
74 RttStats::Rtt previousSrtt = stats.getSrtt();
75
76 stats.recordTimeout();
77
78 BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_TIMEOUT);
79 BOOST_CHECK_EQUAL(stats.getSrtt(), previousSrtt);
80}
81
82BOOST_AUTO_TEST_SUITE_END() // TestRttStats
83
84BOOST_AUTO_TEST_SUITE(TestFaceInfo)
85
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040086BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoTimeFixture)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000087{
88 FaceInfo info;
89
Davide Pesavento3dade002019-03-19 11:29:56 -060090 auto id = getScheduler().schedule(1_s, []{});
Vince Lehman8a4c29e2016-07-11 08:49:35 +000091 ndn::Name interestName("/ndn/interest");
92
93 // Receive Interest and forward to next hop; should update RTO information
94 info.setTimeoutEvent(id, interestName);
95 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true);
96
97 // If the strategy tries to schedule an RTO when one is already scheduled, throw an exception
98 BOOST_CHECK_THROW(info.setTimeoutEvent(id, interestName), FaceInfo::Error);
99
100 // Receive Data
101 shared_ptr<Interest> interest = makeInterest(interestName);
102 shared_ptr<pit::Entry> pitEntry = make_shared<pit::Entry>(*interest);
103 std::shared_ptr<DummyFace> face = make_shared<DummyFace>();
104
ashiqopud3ae85d2019-02-17 02:29:55 +0000105 pitEntry->insertOrUpdateOutRecord(*face, 0, *interest);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000106
107 RttEstimator::Duration rtt(50);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400108 this->advanceClocks(5_ms, rtt);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000109
110 info.recordRtt(pitEntry, *face);
111 info.cancelTimeoutEvent(interestName);
112
113 BOOST_CHECK_EQUAL(info.getRtt(), rtt);
114 BOOST_CHECK_EQUAL(info.getSrtt(), rtt);
115
116 // Send out another Interest which times out
117 info.setTimeoutEvent(id, interestName);
118
119 info.recordTimeout(interestName);
120 BOOST_CHECK_EQUAL(info.getRtt(), RttStats::RTT_TIMEOUT);
121 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
122}
123
124BOOST_AUTO_TEST_SUITE_END() // TestFaceInfo
125
126BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy
127BOOST_AUTO_TEST_SUITE_END() // Fw
128
129} // namespace tests
130} // namespace asf
131} // namespace fw
132} // namespace nfd