blob: 92f1884b54808eb30bbd76ce16a96685393dbb79 [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"
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
32namespace nfd {
33namespace fw {
34namespace asf {
35namespace tests {
36
37using namespace nfd::tests;
38
39BOOST_AUTO_TEST_SUITE(Fw)
40BOOST_AUTO_TEST_SUITE(TestAsfMeasurements)
41
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040042BOOST_FIXTURE_TEST_CASE(FaceInfo, GlobalIoTimeFixture)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000043{
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040044 using asf::FaceInfo;
45 FaceInfo info(nullptr);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000046
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040047 BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_NO_MEASUREMENT);
48 BOOST_CHECK_EQUAL(info.getSrtt(), FaceInfo::RTT_NO_MEASUREMENT);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000049
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040050 info.recordRtt(100_ms);
51 Name interestName("/ndn/interest");
Vince Lehman8a4c29e2016-07-11 08:49:35 +000052
53 // Receive Interest and forward to next hop; should update RTO information
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040054 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
55 auto rto = info.scheduleTimeout(interestName, []{});
Vince Lehman8a4c29e2016-07-11 08:49:35 +000056 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040057 BOOST_CHECK_EQUAL(rto, 300_ms);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000058
59 // Receive Data
Ernest McCracken1402fa12019-06-09 00:36:28 -070060 time::nanoseconds rtt(5_ms);
61 this->advanceClocks(5_ms);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040062 info.recordRtt(rtt);
63 info.cancelTimeout(interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000064
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040065 BOOST_CHECK_EQUAL(info.getLastRtt(), rtt);
66 BOOST_CHECK_EQUAL(info.getSrtt(), 88125_us);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000067
68 // Send out another Interest which times out
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040069 rto = info.scheduleTimeout(interestName, []{});
70 BOOST_CHECK_EQUAL(rto, 333125_us);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000071
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040072 auto previousSrtt = info.getSrtt();
Vince Lehman8a4c29e2016-07-11 08:49:35 +000073 info.recordTimeout(interestName);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040074
75 BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_TIMEOUT);
76 BOOST_CHECK_EQUAL(info.getSrtt(), previousSrtt);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000077 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
78}
79
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040080BOOST_FIXTURE_TEST_CASE(NamespaceInfo, GlobalIoTimeFixture)
81{
82 using asf::NamespaceInfo;
83 NamespaceInfo info(nullptr);
84
85 BOOST_CHECK(info.getFaceInfo(1234) == nullptr);
86
87 auto& faceInfo = info.getOrCreateFaceInfo(1234);
88 BOOST_CHECK(info.getFaceInfo(1234) == &faceInfo);
89
90 this->advanceClocks(AsfMeasurements::MEASUREMENTS_LIFETIME + 1_s);
91 BOOST_CHECK(info.getFaceInfo(1234) == nullptr); // expired
92}
Vince Lehman8a4c29e2016-07-11 08:49:35 +000093
94BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy
95BOOST_AUTO_TEST_SUITE_END() // Fw
96
97} // namespace tests
98} // namespace asf
99} // namespace fw
100} // namespace nfd