Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 4 | * 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 Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame^] | 27 | #include "daemon/global.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 28 | |
| 29 | #include "tests/daemon/face/dummy-face.hpp" |
| 30 | #include "tests/test-common.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace fw { |
| 34 | namespace asf { |
| 35 | namespace tests { |
| 36 | |
| 37 | using namespace nfd::tests; |
| 38 | |
| 39 | BOOST_AUTO_TEST_SUITE(Fw) |
| 40 | BOOST_AUTO_TEST_SUITE(TestAsfMeasurements) |
| 41 | |
| 42 | BOOST_AUTO_TEST_SUITE(TestRttStats) |
| 43 | |
| 44 | BOOST_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 | |
| 81 | BOOST_AUTO_TEST_SUITE_END() // TestRttStats |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE(TestFaceInfo) |
| 84 | |
| 85 | BOOST_FIXTURE_TEST_CASE(Basic, UnitTestTimeFixture) |
| 86 | { |
| 87 | FaceInfo info; |
| 88 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame^] | 89 | auto id = getScheduler().schedule(1_s, []{}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 90 | 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 | |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 104 | pitEntry->insertOrUpdateOutRecord(*face, 0, *interest); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 105 | |
| 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 | |
| 123 | BOOST_AUTO_TEST_SUITE_END() // TestFaceInfo |
| 124 | |
| 125 | BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy |
| 126 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 127 | |
| 128 | } // namespace tests |
| 129 | } // namespace asf |
| 130 | } // namespace fw |
| 131 | } // namespace nfd |