blob: e44144bdece47e20df27b4004a6c2c4b0501bb1b [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/*
awlaneee97f532024-09-19 15:48:21 -05003 * Copyright (c) 2014-2024, 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"
27
Vince Lehman8a4c29e2016-07-11 08:49:35 +000028#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/daemon/global-io-fixture.hpp"
30#include "tests/daemon/face/dummy-face.hpp"
Vince Lehman8a4c29e2016-07-11 08:49:35 +000031
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::tests {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000033
34BOOST_AUTO_TEST_SUITE(Fw)
35BOOST_AUTO_TEST_SUITE(TestAsfMeasurements)
36
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040037BOOST_FIXTURE_TEST_CASE(FaceInfo, GlobalIoTimeFixture)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000038{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040039 using fw::asf::FaceInfo;
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040040 FaceInfo info(nullptr);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000041
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040042 BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_NO_MEASUREMENT);
43 BOOST_CHECK_EQUAL(info.getSrtt(), FaceInfo::RTT_NO_MEASUREMENT);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000044
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040045 info.recordRtt(100_ms);
46 Name interestName("/ndn/interest");
Vince Lehman8a4c29e2016-07-11 08:49:35 +000047
48 // Receive Interest and forward to next hop; should update RTO information
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040049 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
50 auto rto = info.scheduleTimeout(interestName, []{});
Vince Lehman8a4c29e2016-07-11 08:49:35 +000051 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040052 BOOST_CHECK_EQUAL(rto, 300_ms);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000053
54 // Receive Data
Ernest McCracken1402fa12019-06-09 00:36:28 -070055 time::nanoseconds rtt(5_ms);
56 this->advanceClocks(5_ms);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040057 info.recordRtt(rtt);
58 info.cancelTimeout(interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000059
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040060 BOOST_CHECK_EQUAL(info.getLastRtt(), rtt);
61 BOOST_CHECK_EQUAL(info.getSrtt(), 88125_us);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000062
63 // Send out another Interest which times out
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040064 rto = info.scheduleTimeout(interestName, []{});
65 BOOST_CHECK_EQUAL(rto, 333125_us);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000066
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040067 auto previousSrtt = info.getSrtt();
Vince Lehman8a4c29e2016-07-11 08:49:35 +000068 info.recordTimeout(interestName);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040069
70 BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_TIMEOUT);
71 BOOST_CHECK_EQUAL(info.getSrtt(), previousSrtt);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000072 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
73}
74
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040075BOOST_FIXTURE_TEST_CASE(NamespaceInfo, GlobalIoTimeFixture)
76{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040077 using fw::asf::NamespaceInfo;
awlaneee97f532024-09-19 15:48:21 -050078 NamespaceInfo info(nullptr, fw::asf::AsfMeasurements::DEFAULT_MEASUREMENTS_LIFETIME);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040079
80 BOOST_CHECK(info.getFaceInfo(1234) == nullptr);
81
82 auto& faceInfo = info.getOrCreateFaceInfo(1234);
83 BOOST_CHECK(info.getFaceInfo(1234) == &faceInfo);
84
awlaneee97f532024-09-19 15:48:21 -050085 this->advanceClocks(fw::asf::AsfMeasurements::DEFAULT_MEASUREMENTS_LIFETIME + 1_s);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040086 BOOST_CHECK(info.getFaceInfo(1234) == nullptr); // expired
87}
Vince Lehman8a4c29e2016-07-11 08:49:35 +000088
89BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy
90BOOST_AUTO_TEST_SUITE_END() // Fw
91
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040092} // namespace nfd::tests