Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +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 | /** \file |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 27 | * This test suite checks that a strategy returns Nack-NoRoute when there are |
| 28 | * no usable FIB nexthops. |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 31 | // Strategies returning Nack-NoRoute when there are no usable FIB nexthops, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 32 | // sorted alphabetically. |
| 33 | #include "fw/asf-strategy.hpp" |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 34 | #include "fw/best-route-strategy.hpp" |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 35 | #include "fw/random-strategy.hpp" |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 36 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 37 | #include "tests/test-common.hpp" |
| 38 | #include "tests/daemon/face/dummy-face.hpp" |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 39 | #include "choose-strategy.hpp" |
| 40 | #include "strategy-tester.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 41 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 42 | #include <boost/mp11/list.hpp> |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 43 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 44 | namespace nfd::tests { |
| 45 | |
| 46 | using namespace nfd::fw; |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 47 | |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 48 | template<typename S> |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 49 | class StrategyNoRouteFixture : public GlobalIoTimeFixture |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | StrategyNoRouteFixture() |
| 53 | : limitedIo(this) |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 54 | , forwarder(faceTable) |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 55 | , strategy(choose<StrategyTester<S>>(forwarder)) |
| 56 | , fib(forwarder.getFib()) |
| 57 | , pit(forwarder.getPit()) |
| 58 | , face1(make_shared<DummyFace>()) |
| 59 | , face2(make_shared<DummyFace>()) |
| 60 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 61 | faceTable.add(face1); |
| 62 | faceTable.add(face2); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | public: |
| 66 | LimitedIo limitedIo; |
| 67 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 68 | FaceTable faceTable; |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 69 | Forwarder forwarder; |
| 70 | StrategyTester<S>& strategy; |
| 71 | Fib& fib; |
| 72 | Pit& pit; |
| 73 | |
| 74 | shared_ptr<Face> face1; |
| 75 | shared_ptr<Face> face2; |
| 76 | }; |
| 77 | |
| 78 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 79 | BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute) |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 80 | |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 81 | template<typename S> |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 82 | struct EmptyNextHopList |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 83 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 84 | static Name |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 85 | getInterestName() |
| 86 | { |
| 87 | return "/P"; |
| 88 | } |
| 89 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 90 | static void |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 91 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 92 | { |
| 93 | fixture->fib.insert(Name()); |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | template<typename S> |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 98 | struct NextHopIsDownstream |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 99 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 100 | static Name |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 101 | getInterestName() |
| 102 | { |
| 103 | return "/P"; |
| 104 | } |
| 105 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 106 | static void |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 107 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 108 | { |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 109 | fib::Entry* entry = fixture->fib.insert(Name()).first; |
| 110 | fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 111 | } |
| 112 | }; |
| 113 | |
| 114 | template<typename S> |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 115 | struct NextHopViolatesScope |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 116 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 117 | static Name |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 118 | getInterestName() |
| 119 | { |
| 120 | return "/localhop/P"; |
| 121 | } |
| 122 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 123 | static void |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 124 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 125 | { |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 126 | fib::Entry* entry = fixture->fib.insert("/localhop").first; |
| 127 | fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 128 | // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2 |
| 129 | } |
| 130 | }; |
| 131 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 132 | using Tests = boost::mp11::mp_list< |
| 133 | boost::mp11::mp_list<AsfStrategy, EmptyNextHopList<AsfStrategy>>, |
| 134 | boost::mp11::mp_list<AsfStrategy, NextHopIsDownstream<AsfStrategy>>, |
| 135 | boost::mp11::mp_list<AsfStrategy, NextHopViolatesScope<AsfStrategy>>, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 136 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 137 | boost::mp11::mp_list<BestRouteStrategy, EmptyNextHopList<BestRouteStrategy>>, |
| 138 | boost::mp11::mp_list<BestRouteStrategy, NextHopIsDownstream<BestRouteStrategy>>, |
| 139 | boost::mp11::mp_list<BestRouteStrategy, NextHopViolatesScope<BestRouteStrategy>>, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 140 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 141 | boost::mp11::mp_list<RandomStrategy, EmptyNextHopList<RandomStrategy>>, |
| 142 | boost::mp11::mp_list<RandomStrategy, NextHopIsDownstream<RandomStrategy>>, |
| 143 | boost::mp11::mp_list<RandomStrategy, NextHopViolatesScope<RandomStrategy>> |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 144 | >; |
| 145 | |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 146 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 147 | T, Tests, StrategyNoRouteFixture<boost::mp11::mp_first<T>>) |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 148 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 149 | using Scenario = boost::mp11::mp_second<T>; |
| 150 | Scenario::insertFibEntry(this); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 151 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 152 | auto interest = makeInterest(Scenario::getInterestName()); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 153 | auto pitEntry = this->pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 154 | pitEntry->insertOrUpdateInRecord(*this->face1, *interest); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 155 | |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 156 | auto f = [&] { |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 157 | this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->face1), pitEntry); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 158 | }; |
| 159 | BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2)); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 160 | |
| 161 | BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 162 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(), |
| 163 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 164 | |
| 165 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(), |
| 167 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 168 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId()); |
| 169 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 170 | } |
| 171 | |
| 172 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute |
| 173 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 174 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 175 | } // namespace nfd::tests |