Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [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. |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 26 | #include "fw/best-route-strategy.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 30 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 31 | #include "strategy-tester.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 35 | using BestRouteStrategyTester = StrategyTester<fw::BestRouteStrategy>; |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 36 | NFD_REGISTER_STRATEGY(BestRouteStrategyTester); |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 37 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 38 | BOOST_AUTO_TEST_SUITE(Fw) |
| 39 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 40 | class BestRouteStrategyFixture : public GlobalIoTimeFixture |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 41 | { |
| 42 | protected: |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 43 | BestRouteStrategyFixture() |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 44 | : face1(make_shared<DummyFace>()) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 45 | , face2(make_shared<DummyFace>()) |
| 46 | , face3(make_shared<DummyFace>()) |
| 47 | , face4(make_shared<DummyFace>()) |
| 48 | , face5(make_shared<DummyFace>()) |
| 49 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 50 | faceTable.add(face1); |
| 51 | faceTable.add(face2); |
| 52 | faceTable.add(face3); |
| 53 | faceTable.add(face4); |
| 54 | faceTable.add(face5); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 57 | protected: |
| 58 | FaceTable faceTable; |
| 59 | Forwarder forwarder{faceTable}; |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 60 | BestRouteStrategyTester strategy{forwarder}; |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 61 | Fib& fib{forwarder.getFib()}; |
| 62 | Pit& pit{forwarder.getPit()}; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 63 | |
| 64 | shared_ptr<DummyFace> face1; |
| 65 | shared_ptr<DummyFace> face2; |
| 66 | shared_ptr<DummyFace> face3; |
| 67 | shared_ptr<DummyFace> face4; |
| 68 | shared_ptr<DummyFace> face5; |
| 69 | }; |
| 70 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 71 | BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy, BestRouteStrategyFixture) |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 72 | |
| 73 | BOOST_AUTO_TEST_CASE(Forward) |
| 74 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 75 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 76 | fib.addOrUpdateNextHop(fibEntry, *face1, 10); |
| 77 | fib.addOrUpdateNextHop(fibEntry, *face2, 20); |
| 78 | fib.addOrUpdateNextHop(fibEntry, *face3, 30); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 79 | |
| 80 | shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA"); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 81 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 82 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 83 | const auto TICK = time::duration_cast<time::nanoseconds>( |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 84 | fw::RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL * 0.1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 85 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 86 | // first Interest goes to nexthop with lowest FIB cost, |
| 87 | // however face1 is downstream so it cannot be used |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 88 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 89 | strategy.afterReceiveInterest(*interest, FaceEndpoint(*face1), pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 90 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 91 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 92 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 93 | // downstream retransmits frequently, but the strategy should not send Interests |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 94 | // more often than DEFAULT_MIN_RETX_INTERVAL |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 95 | ndn::scheduler::EventId retxFrom4Evt; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 96 | size_t nSentLast = strategy.sendInterestHistory.size(); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 97 | auto timeSentLast = time::steady_clock::now(); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 98 | std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
Junxiao Shi | 913806d | 2014-11-14 11:43:52 -0700 | [diff] [blame] | 99 | periodicalRetxFrom4 = [&] { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 100 | pitEntry->insertOrUpdateInRecord(*face4, *interest); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 101 | strategy.afterReceiveInterest(*interest, FaceEndpoint(*face4), pitEntry); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 103 | size_t nSent = strategy.sendInterestHistory.size(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 104 | if (nSent > nSentLast) { |
| 105 | BOOST_CHECK_EQUAL(nSent - nSentLast, 1); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 106 | auto timeSent = time::steady_clock::now(); |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 107 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 108 | nSentLast = nSent; |
| 109 | timeSentLast = timeSent; |
| 110 | } |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 111 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 112 | retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 113 | }; |
| 114 | periodicalRetxFrom4(); |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 115 | this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 16); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 116 | retxFrom4Evt.cancel(); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 118 | // nexthops for accepted retransmissions: follow FIB cost, |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 119 | // later forward to an eligible upstream with earliest out-record |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 120 | BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6); |
| 121 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 122 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId()); |
| 123 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId()); |
| 124 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId()); |
| 125 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 126 | |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 127 | fib.removeNextHop(fibEntry, *face1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 128 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 129 | strategy.sendInterestHistory.clear(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 130 | for (int i = 0; i < 3; ++i) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 131 | this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 2); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 132 | pitEntry->insertOrUpdateInRecord(*face5, *interest); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 133 | strategy.afterReceiveInterest(*interest, FaceEndpoint(*face5), pitEntry); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 134 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 135 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3); |
| 136 | BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
| 137 | BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 138 | BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 139 | // face1 cannot be used because it's gone from FIB entry |
| 140 | } |
| 141 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 142 | BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 143 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 144 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 145 | } // namespace nfd::tests |