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