| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2022, Regents of the University of California, |
| * Arizona Board of Regents, |
| * Colorado State University, |
| * University Pierre & Marie Curie, Sorbonne University, |
| * Washington University in St. Louis, |
| * Beijing Institute of Technology, |
| * The University of Memphis. |
| * |
| * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| * See AUTHORS.md for complete list of NFD authors and contributors. |
| * |
| * NFD is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #include "fw/asf-measurements.hpp" |
| |
| #include "tests/test-common.hpp" |
| #include "tests/daemon/global-io-fixture.hpp" |
| #include "tests/daemon/face/dummy-face.hpp" |
| |
| namespace nfd::tests { |
| |
| BOOST_AUTO_TEST_SUITE(Fw) |
| BOOST_AUTO_TEST_SUITE(TestAsfMeasurements) |
| |
| BOOST_FIXTURE_TEST_CASE(FaceInfo, GlobalIoTimeFixture) |
| { |
| using fw::asf::FaceInfo; |
| FaceInfo info(nullptr); |
| |
| BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_NO_MEASUREMENT); |
| BOOST_CHECK_EQUAL(info.getSrtt(), FaceInfo::RTT_NO_MEASUREMENT); |
| |
| info.recordRtt(100_ms); |
| Name interestName("/ndn/interest"); |
| |
| // Receive Interest and forward to next hop; should update RTO information |
| BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false); |
| auto rto = info.scheduleTimeout(interestName, []{}); |
| BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), true); |
| BOOST_CHECK_EQUAL(rto, 300_ms); |
| |
| // Receive Data |
| time::nanoseconds rtt(5_ms); |
| this->advanceClocks(5_ms); |
| info.recordRtt(rtt); |
| info.cancelTimeout(interestName); |
| |
| BOOST_CHECK_EQUAL(info.getLastRtt(), rtt); |
| BOOST_CHECK_EQUAL(info.getSrtt(), 88125_us); |
| |
| // Send out another Interest which times out |
| rto = info.scheduleTimeout(interestName, []{}); |
| BOOST_CHECK_EQUAL(rto, 333125_us); |
| |
| auto previousSrtt = info.getSrtt(); |
| info.recordTimeout(interestName); |
| |
| BOOST_CHECK_EQUAL(info.getLastRtt(), FaceInfo::RTT_TIMEOUT); |
| BOOST_CHECK_EQUAL(info.getSrtt(), previousSrtt); |
| BOOST_CHECK_EQUAL(info.isTimeoutScheduled(), false); |
| } |
| |
| BOOST_FIXTURE_TEST_CASE(NamespaceInfo, GlobalIoTimeFixture) |
| { |
| using fw::asf::NamespaceInfo; |
| NamespaceInfo info(nullptr); |
| |
| BOOST_CHECK(info.getFaceInfo(1234) == nullptr); |
| |
| auto& faceInfo = info.getOrCreateFaceInfo(1234); |
| BOOST_CHECK(info.getFaceInfo(1234) == &faceInfo); |
| |
| this->advanceClocks(fw::asf::AsfMeasurements::MEASUREMENTS_LIFETIME + 1_s); |
| BOOST_CHECK(info.getFaceInfo(1234) == nullptr); // expired |
| } |
| |
| BOOST_AUTO_TEST_SUITE_END() // TestAsfStrategy |
| BOOST_AUTO_TEST_SUITE_END() // Fw |
| |
| } // namespace nfd::tests |