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 | { |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 118 | fixture->fib.insert(Name()).first->addOrUpdateNextHop(*fixture->face1, 0, 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 | { |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 135 | fixture->fib.insert("/localhop").first->addOrUpdateNextHop(*fixture->face2, 0, 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 | |
| 160 | shared_ptr<Interest> interest = makeInterest(scenario.getInterestName()); |
| 161 | shared_ptr<pit::Entry> 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 | |
| 164 | BOOST_REQUIRE(this->strategy.waitForAction( |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 165 | [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry); }, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 166 | this->limitedIo, 2)); |
| 167 | |
| 168 | BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
| 169 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest()); |
| 170 | |
| 171 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 172 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
| 173 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId()); |
| 174 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 175 | } |
| 176 | |
| 177 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute |
| 178 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 179 | |
| 180 | } // namespace tests |
| 181 | } // namespace fw |
| 182 | } // namespace nfd |