blob: 71491b7d4e6d9452dd8515a36babfa1da21f05bc [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
29#include "tests/daemon/face/dummy-face.hpp"
30#include "tests/test-common.hpp"
31
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
42BOOST_AUTO_TEST_SUITE(TestRttStats)
43
44BOOST_FIXTURE_TEST_CASE(Basic, BaseFixture)
45{
46 RttStats stats;
47
48 BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_NO_MEASUREMENT);
49 BOOST_CHECK_EQUAL(stats.getSrtt(), RttStats::RTT_NO_MEASUREMENT);
50
51 // Receive Data back in 50ms
52 RttEstimator::Duration rtt(time::milliseconds(50));
53 stats.addRttMeasurement(rtt);
54
55 BOOST_CHECK_EQUAL(stats.getRtt(), rtt);
56 BOOST_CHECK_EQUAL(stats.getSrtt(), rtt);
57
58 // Receive Data back in 50ms
59 stats.addRttMeasurement(rtt);
60
61 BOOST_CHECK_EQUAL(stats.getRtt(), rtt);
62 BOOST_CHECK_EQUAL(stats.getSrtt(), rtt);
63
64 // Receive Data back with a higher RTT
65 RttEstimator::Duration higherRtt(time::milliseconds(100));
66 stats.addRttMeasurement(higherRtt);
67
68 BOOST_CHECK_EQUAL(stats.getRtt(), higherRtt);
69 BOOST_CHECK_GT(stats.getSrtt(), rtt);
70 BOOST_CHECK_LT(stats.getSrtt(), higherRtt);
71
72 // Simulate timeout
73 RttStats::Rtt previousSrtt = stats.getSrtt();
74
75 stats.recordTimeout();
76
77 BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_TIMEOUT);
78 BOOST_CHECK_EQUAL(stats.getSrtt(), previousSrtt);
79}
80
81BOOST_AUTO_TEST_SUITE_END() // TestRttStats
82
83BOOST_AUTO_TEST_SUITE(TestFaceInfo)
84
85BOOST_FIXTURE_TEST_CASE(Basic, UnitTestTimeFixture)
86{
87 FaceInfo info;
88
Davide Pesavento3dade002019-03-19 11:29:56 -060089 auto id = getScheduler().schedule(1_s, []{});
Vince Lehman8a4c29e2016-07-11 08:49:35 +000090 ndn::Name interestName("/ndn/interest");
91
92 // Receive Interest and forward to next hop; should update RTO information
93 info.setTimeoutEvent(id, interestName);
94 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true);
95
96 // If the strategy tries to schedule an RTO when one is already scheduled, throw an exception
97 BOOST_CHECK_THROW(info.setTimeoutEvent(id, interestName), FaceInfo::Error);
98
99 // Receive Data
100 shared_ptr<Interest> interest = makeInterest(interestName);
101 shared_ptr<pit::Entry> pitEntry = make_shared<pit::Entry>(*interest);
102 std::shared_ptr<DummyFace> face = make_shared<DummyFace>();
103
ashiqopud3ae85d2019-02-17 02:29:55 +0000104 pitEntry->insertOrUpdateOutRecord(*face, 0, *interest);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000105
106 RttEstimator::Duration rtt(50);
107 this->advanceClocks(time::milliseconds(5), rtt);
108
109 info.recordRtt(pitEntry, *face);
110 info.cancelTimeoutEvent(interestName);
111
112 BOOST_CHECK_EQUAL(info.getRtt(), rtt);
113 BOOST_CHECK_EQUAL(info.getSrtt(), rtt);
114
115 // Send out another Interest which times out
116 info.setTimeoutEvent(id, interestName);
117
118 info.recordTimeout(interestName);
119 BOOST_CHECK_EQUAL(info.getRtt(), RttStats::RTT_TIMEOUT);
120 BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false);
121}
122
123BOOST_AUTO_TEST_SUITE_END() // TestFaceInfo
124
125BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy
126BOOST_AUTO_TEST_SUITE_END() // Fw
127
128} // namespace tests
129} // namespace asf
130} // namespace fw
131} // namespace nfd