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 | /* |
| 3 | * Copyright (c) 2014-2019, 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 |
| 27 | * This test suite checks that a strategy returns Nack-NoRoute |
| 28 | * when there is no usable FIB nexthop. |
| 29 | */ |
| 30 | |
| 31 | // Strategies returning Nack-NoRoute when there is no usable FIB nexthop, |
| 32 | // sorted alphabetically. |
| 33 | #include "fw/asf-strategy.hpp" |
| 34 | #include "fw/best-route-strategy2.hpp" |
| 35 | #include "fw/multicast-strategy.hpp" |
| 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/copy_if.hpp> |
| 43 | #include <boost/mpl/vector.hpp> |
| 44 | |
| 45 | namespace nfd { |
| 46 | namespace fw { |
| 47 | namespace tests { |
| 48 | |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 49 | template<typename S> |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 50 | class StrategyNoRouteFixture : public GlobalIoTimeFixture |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | StrategyNoRouteFixture() |
| 54 | : limitedIo(this) |
| 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 | { |
| 61 | forwarder.addFace(face1); |
| 62 | forwarder.addFace(face2); |
| 63 | } |
| 64 | |
| 65 | public: |
| 66 | LimitedIo limitedIo; |
| 67 | |
| 68 | Forwarder forwarder; |
| 69 | StrategyTester<S>& strategy; |
| 70 | Fib& fib; |
| 71 | Pit& pit; |
| 72 | |
| 73 | shared_ptr<Face> face1; |
| 74 | shared_ptr<Face> face2; |
| 75 | }; |
| 76 | |
| 77 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 78 | BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute) |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 79 | |
| 80 | template<typename S, typename C> |
| 81 | class Test |
| 82 | { |
| 83 | public: |
| 84 | using Strategy = S; |
| 85 | using Case = C; |
| 86 | }; |
| 87 | |
| 88 | template<typename S> |
| 89 | class EmptyNextHopList |
| 90 | { |
| 91 | public: |
| 92 | Name |
| 93 | getInterestName() |
| 94 | { |
| 95 | return "/P"; |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 100 | { |
| 101 | fixture->fib.insert(Name()); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | template<typename S> |
| 106 | class NextHopIsDownstream |
| 107 | { |
| 108 | public: |
| 109 | Name |
| 110 | getInterestName() |
| 111 | { |
| 112 | return "/P"; |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 117 | { |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 118 | fixture->fib.insert(Name()).first->addOrUpdateNextHop(*fixture->face1, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 119 | } |
| 120 | }; |
| 121 | |
| 122 | template<typename S> |
| 123 | class NextHopViolatesScope |
| 124 | { |
| 125 | public: |
| 126 | Name |
| 127 | getInterestName() |
| 128 | { |
| 129 | return "/localhop/P"; |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 134 | { |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 135 | fixture->fib.insert("/localhop").first->addOrUpdateNextHop(*fixture->face2, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 136 | // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2 |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | using Tests = boost::mpl::vector< |
| 141 | Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>, |
| 142 | Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>, |
| 143 | Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>, |
| 144 | |
| 145 | Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>, |
| 146 | Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>, |
| 147 | Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>, |
| 148 | |
| 149 | Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>, |
| 150 | Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>, |
| 151 | Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>> |
| 152 | >; |
| 153 | |
| 154 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests, |
| 155 | StrategyNoRouteFixture<typename T::Strategy>) |
| 156 | { |
| 157 | typename T::Case scenario; |
| 158 | scenario.insertFibEntry(this); |
| 159 | |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame^] | 160 | auto interest = makeInterest(scenario.getInterestName()); |
| 161 | auto pitEntry = this->pit.insert(*interest).first; |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 162 | pitEntry->insertOrUpdateInRecord(*this->face1, 0, *interest); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 163 | |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame^] | 164 | auto f = [&] { |
| 165 | this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry); |
| 166 | }; |
| 167 | BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2)); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 168 | |
| 169 | BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame^] | 170 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(), |
| 171 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 172 | |
| 173 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame^] | 174 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(), |
| 175 | pitEntry->getInterest().wireEncode()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 176 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId()); |
| 177 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 178 | } |
| 179 | |
| 180 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute |
| 181 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 182 | |
| 183 | } // namespace tests |
| 184 | } // namespace fw |
| 185 | } // namespace nfd |