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 | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 28 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/daemon/global-io-fixture.hpp" |
| 31 | #include "tests/daemon/face/dummy-face.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace fw { |
| 35 | namespace asf { |
| 36 | namespace tests { |
| 37 | |
| 38 | using namespace nfd::tests; |
| 39 | |
| 40 | BOOST_AUTO_TEST_SUITE(Fw) |
| 41 | BOOST_AUTO_TEST_SUITE(TestAsfMeasurements) |
| 42 | |
| 43 | BOOST_AUTO_TEST_SUITE(TestRttStats) |
| 44 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 45 | BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoFixture) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 46 | { |
| 47 | RttStats stats; |
| 48 | |
| 49 | BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_NO_MEASUREMENT); |
| 50 | BOOST_CHECK_EQUAL(stats.getSrtt(), RttStats::RTT_NO_MEASUREMENT); |
| 51 | |
| 52 | // Receive Data back in 50ms |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 53 | time::nanoseconds rtt(50_ms); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 54 | stats.addRttMeasurement(rtt); |
| 55 | |
| 56 | BOOST_CHECK_EQUAL(stats.getRtt(), rtt); |
| 57 | BOOST_CHECK_EQUAL(stats.getSrtt(), rtt); |
| 58 | |
| 59 | // Receive Data back in 50ms |
| 60 | stats.addRttMeasurement(rtt); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(stats.getRtt(), rtt); |
| 63 | BOOST_CHECK_EQUAL(stats.getSrtt(), rtt); |
| 64 | |
| 65 | // Receive Data back with a higher RTT |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 66 | time::nanoseconds higherRtt(100_ms); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 67 | stats.addRttMeasurement(higherRtt); |
| 68 | |
| 69 | BOOST_CHECK_EQUAL(stats.getRtt(), higherRtt); |
| 70 | BOOST_CHECK_GT(stats.getSrtt(), rtt); |
| 71 | BOOST_CHECK_LT(stats.getSrtt(), higherRtt); |
| 72 | |
| 73 | // Simulate timeout |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 74 | auto previousSrtt = stats.getSrtt(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 75 | |
| 76 | stats.recordTimeout(); |
| 77 | |
| 78 | BOOST_CHECK_EQUAL(stats.getRtt(), RttStats::RTT_TIMEOUT); |
| 79 | BOOST_CHECK_EQUAL(stats.getSrtt(), previousSrtt); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_SUITE_END() // TestRttStats |
| 83 | |
| 84 | BOOST_AUTO_TEST_SUITE(TestFaceInfo) |
| 85 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 86 | BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoTimeFixture) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 87 | { |
| 88 | FaceInfo info; |
| 89 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 90 | auto id = getScheduler().schedule(1_s, []{}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 91 | ndn::Name interestName("/ndn/interest"); |
| 92 | |
| 93 | // Receive Interest and forward to next hop; should update RTO information |
| 94 | info.setTimeoutEvent(id, interestName); |
| 95 | BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true); |
| 96 | |
| 97 | // If the strategy tries to schedule an RTO when one is already scheduled, throw an exception |
| 98 | BOOST_CHECK_THROW(info.setTimeoutEvent(id, interestName), FaceInfo::Error); |
| 99 | |
| 100 | // Receive Data |
| 101 | shared_ptr<Interest> interest = makeInterest(interestName); |
| 102 | shared_ptr<pit::Entry> pitEntry = make_shared<pit::Entry>(*interest); |
| 103 | std::shared_ptr<DummyFace> face = make_shared<DummyFace>(); |
| 104 | |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 105 | pitEntry->insertOrUpdateOutRecord(*face, 0, *interest); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 106 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 107 | time::nanoseconds rtt(5_ms); |
| 108 | this->advanceClocks(5_ms); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 109 | |
| 110 | info.recordRtt(pitEntry, *face); |
| 111 | info.cancelTimeoutEvent(interestName); |
| 112 | |
| 113 | BOOST_CHECK_EQUAL(info.getRtt(), rtt); |
| 114 | BOOST_CHECK_EQUAL(info.getSrtt(), rtt); |
| 115 | |
| 116 | // Send out another Interest which times out |
| 117 | info.setTimeoutEvent(id, interestName); |
| 118 | |
| 119 | info.recordTimeout(interestName); |
| 120 | BOOST_CHECK_EQUAL(info.getRtt(), RttStats::RTT_TIMEOUT); |
| 121 | BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false); |
| 122 | } |
| 123 | |
| 124 | BOOST_AUTO_TEST_SUITE_END() // TestFaceInfo |
| 125 | |
| 126 | BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy |
| 127 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 128 | |
| 129 | } // namespace tests |
| 130 | } // namespace asf |
| 131 | } // namespace fw |
| 132 | } // namespace nfd |