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 | /* |
Alexander Afanasyev | 4400e42 | 2021-02-17 11:17:33 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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 | |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 42 | #include <boost/mpl/vector.hpp> |
| 43 | |
| 44 | namespace nfd { |
| 45 | namespace fw { |
| 46 | namespace tests { |
| 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 | |
| 81 | template<typename S, typename C> |
| 82 | class Test |
| 83 | { |
| 84 | public: |
| 85 | using Strategy = S; |
| 86 | using Case = C; |
| 87 | }; |
| 88 | |
| 89 | template<typename S> |
| 90 | class EmptyNextHopList |
| 91 | { |
| 92 | public: |
| 93 | Name |
| 94 | getInterestName() |
| 95 | { |
| 96 | return "/P"; |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 101 | { |
| 102 | fixture->fib.insert(Name()); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | template<typename S> |
| 107 | class NextHopIsDownstream |
| 108 | { |
| 109 | public: |
| 110 | Name |
| 111 | getInterestName() |
| 112 | { |
| 113 | return "/P"; |
| 114 | } |
| 115 | |
| 116 | void |
| 117 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 118 | { |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 119 | fib::Entry* entry = fixture->fib.insert(Name()).first; |
| 120 | fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 121 | } |
| 122 | }; |
| 123 | |
| 124 | template<typename S> |
| 125 | class NextHopViolatesScope |
| 126 | { |
| 127 | public: |
| 128 | Name |
| 129 | getInterestName() |
| 130 | { |
| 131 | return "/localhop/P"; |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 136 | { |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 137 | fib::Entry* entry = fixture->fib.insert("/localhop").first; |
| 138 | fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 139 | // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2 |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | using Tests = boost::mpl::vector< |
| 144 | Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>, |
| 145 | Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>, |
| 146 | Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>, |
| 147 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 148 | Test<BestRouteStrategy, EmptyNextHopList<BestRouteStrategy>>, |
| 149 | Test<BestRouteStrategy, NextHopIsDownstream<BestRouteStrategy>>, |
| 150 | Test<BestRouteStrategy, NextHopViolatesScope<BestRouteStrategy>>, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 151 | |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 152 | Test<RandomStrategy, EmptyNextHopList<RandomStrategy>>, |
| 153 | Test<RandomStrategy, NextHopIsDownstream<RandomStrategy>>, |
| 154 | Test<RandomStrategy, NextHopViolatesScope<RandomStrategy>> |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 155 | >; |
| 156 | |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 157 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, |
| 158 | T, Tests, StrategyNoRouteFixture<typename T::Strategy>) |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 159 | { |
| 160 | typename T::Case scenario; |
| 161 | scenario.insertFibEntry(this); |
| 162 | |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 163 | auto interest = makeInterest(scenario.getInterestName()); |
| 164 | auto pitEntry = this->pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 165 | pitEntry->insertOrUpdateInRecord(*this->face1, *interest); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 166 | |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 167 | auto f = [&] { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 168 | this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->face1, 0), pitEntry); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 169 | }; |
| 170 | BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2)); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 171 | |
| 172 | BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(), |
| 174 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 175 | |
| 176 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(), |
| 178 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId()); |
| 180 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 181 | } |
| 182 | |
| 183 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute |
| 184 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 185 | |
| 186 | } // namespace tests |
| 187 | } // namespace fw |
| 188 | } // namespace nfd |