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" |
| 27 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/daemon/global-io-fixture.hpp" |
| 30 | #include "tests/daemon/face/dummy-face.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 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 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 42 | BOOST_FIXTURE_TEST_CASE(FaceInfo, GlobalIoTimeFixture) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 43 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 44 | using asf::FaceInfo; |
| 45 | FaceInfo info(nullptr); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 46 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_NO_MEASUREMENT); |
| 48 | BOOST_CHECK_EQUAL(info.getSrtt(), FaceInfo::RTT_NO_MEASUREMENT); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 49 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 50 | info.recordRtt(100_ms); |
| 51 | Name interestName("/ndn/interest"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 52 | |
| 53 | // Receive Interest and forward to next hop; should update RTO information |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false); |
| 55 | auto rto = info.scheduleTimeout(interestName, []{}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(rto, 300_ms); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 58 | |
| 59 | // Receive Data |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 60 | time::nanoseconds rtt(5_ms); |
| 61 | this->advanceClocks(5_ms); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 62 | info.recordRtt(rtt); |
| 63 | info.cancelTimeout(interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 64 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(info.getLastRtt(), rtt); |
| 66 | BOOST_CHECK_EQUAL(info.getSrtt(), 88125_us); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 67 | |
| 68 | // Send out another Interest which times out |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 69 | rto = info.scheduleTimeout(interestName, []{}); |
| 70 | BOOST_CHECK_EQUAL(rto, 333125_us); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 71 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 72 | auto previousSrtt = info.getSrtt(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 73 | info.recordTimeout(interestName); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 74 | |
| 75 | BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_TIMEOUT); |
| 76 | BOOST_CHECK_EQUAL(info.getSrtt(), previousSrtt); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false); |
| 78 | } |
| 79 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 80 | BOOST_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 Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 93 | |
| 94 | BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy |
| 95 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 96 | |
| 97 | } // namespace tests |
| 98 | } // namespace asf |
| 99 | } // namespace fw |
| 100 | } // namespace nfd |