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 | |
| 37 | #include "tests/test-common.hpp" |
| 38 | #include "tests/limited-io.hpp" |
| 39 | #include "choose-strategy.hpp" |
| 40 | #include "strategy-tester.hpp" |
| 41 | #include "tests/daemon/face/dummy-face.hpp" |
| 42 | #include <boost/mpl/copy_if.hpp> |
| 43 | #include <boost/mpl/vector.hpp> |
| 44 | |
| 45 | namespace nfd { |
| 46 | namespace fw { |
| 47 | namespace tests { |
| 48 | |
| 49 | using namespace nfd::tests; |
| 50 | |
| 51 | template<typename S> |
| 52 | class StrategyNoRouteFixture : public UnitTestTimeFixture |
| 53 | { |
| 54 | public: |
| 55 | StrategyNoRouteFixture() |
| 56 | : limitedIo(this) |
| 57 | , strategy(choose<StrategyTester<S>>(forwarder)) |
| 58 | , fib(forwarder.getFib()) |
| 59 | , pit(forwarder.getPit()) |
| 60 | , face1(make_shared<DummyFace>()) |
| 61 | , face2(make_shared<DummyFace>()) |
| 62 | { |
| 63 | forwarder.addFace(face1); |
| 64 | forwarder.addFace(face2); |
| 65 | } |
| 66 | |
| 67 | public: |
| 68 | LimitedIo limitedIo; |
| 69 | |
| 70 | Forwarder forwarder; |
| 71 | StrategyTester<S>& strategy; |
| 72 | Fib& fib; |
| 73 | Pit& pit; |
| 74 | |
| 75 | shared_ptr<Face> face1; |
| 76 | shared_ptr<Face> face2; |
| 77 | }; |
| 78 | |
| 79 | BOOST_AUTO_TEST_SUITE(Fw) |
| 80 | BOOST_FIXTURE_TEST_SUITE(TestStrategyNoRoute, BaseFixture) |
| 81 | |
| 82 | template<typename S, typename C> |
| 83 | class Test |
| 84 | { |
| 85 | public: |
| 86 | using Strategy = S; |
| 87 | using Case = C; |
| 88 | }; |
| 89 | |
| 90 | template<typename S> |
| 91 | class EmptyNextHopList |
| 92 | { |
| 93 | public: |
| 94 | Name |
| 95 | getInterestName() |
| 96 | { |
| 97 | return "/P"; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 102 | { |
| 103 | fixture->fib.insert(Name()); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | template<typename S> |
| 108 | class NextHopIsDownstream |
| 109 | { |
| 110 | public: |
| 111 | Name |
| 112 | getInterestName() |
| 113 | { |
| 114 | return "/P"; |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | insertFibEntry(StrategyNoRouteFixture<S>* fixture) |
| 119 | { |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 120 | fixture->fib.insert(Name()).first->addOrUpdateNextHop(*fixture->face1, 0, 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 | { |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 137 | fixture->fib.insert("/localhop").first->addOrUpdateNextHop(*fixture->face2, 0, 10); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 138 | // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2 |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | using Tests = boost::mpl::vector< |
| 143 | Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>, |
| 144 | Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>, |
| 145 | Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>, |
| 146 | |
| 147 | Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>, |
| 148 | Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>, |
| 149 | Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>, |
| 150 | |
| 151 | Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>, |
| 152 | Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>, |
| 153 | Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>> |
| 154 | >; |
| 155 | |
| 156 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests, |
| 157 | StrategyNoRouteFixture<typename T::Strategy>) |
| 158 | { |
| 159 | typename T::Case scenario; |
| 160 | scenario.insertFibEntry(this); |
| 161 | |
| 162 | shared_ptr<Interest> interest = makeInterest(scenario.getInterestName()); |
| 163 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame^] | 164 | pitEntry->insertOrUpdateInRecord(*this->face1, 0, *interest); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 165 | |
| 166 | BOOST_REQUIRE(this->strategy.waitForAction( |
| 167 | [&] { this->strategy.afterReceiveInterest(*this->face1, *interest, pitEntry); }, |
| 168 | this->limitedIo, 2)); |
| 169 | |
| 170 | BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
| 171 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest()); |
| 172 | |
| 173 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 174 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
| 175 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId()); |
| 176 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute |
| 180 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 181 | |
| 182 | } // namespace tests |
| 183 | } // namespace fw |
| 184 | } // namespace nfd |