blob: 6e8aa8a7eebd5437c4ce59615e31b2266f01d7c1 [file] [log] [blame]
Ashlesh Gawandee38e2612017-02-25 07:23:41 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopu3ad49db2018-10-20 22:38:47 +00002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +00004 * 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
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000037#include "choose-strategy.hpp"
38#include "strategy-tester.hpp"
39#include "tests/daemon/face/dummy-face.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060040
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000041#include <boost/mpl/copy_if.hpp>
42#include <boost/mpl/vector.hpp>
43
44namespace nfd {
45namespace fw {
46namespace tests {
47
48using namespace nfd::tests;
49
50template<typename S>
51class StrategyNoRouteFixture : public UnitTestTimeFixture
52{
53public:
54 StrategyNoRouteFixture()
55 : limitedIo(this)
56 , strategy(choose<StrategyTester<S>>(forwarder))
57 , fib(forwarder.getFib())
58 , pit(forwarder.getPit())
59 , face1(make_shared<DummyFace>())
60 , face2(make_shared<DummyFace>())
61 {
62 forwarder.addFace(face1);
63 forwarder.addFace(face2);
64 }
65
66public:
67 LimitedIo limitedIo;
68
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
78BOOST_AUTO_TEST_SUITE(Fw)
79BOOST_FIXTURE_TEST_SUITE(TestStrategyNoRoute, BaseFixture)
80
81template<typename S, typename C>
82class Test
83{
84public:
85 using Strategy = S;
86 using Case = C;
87};
88
89template<typename S>
90class EmptyNextHopList
91{
92public:
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
106template<typename S>
107class NextHopIsDownstream
108{
109public:
110 Name
111 getInterestName()
112 {
113 return "/P";
114 }
115
116 void
117 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
118 {
ashiqopu3ad49db2018-10-20 22:38:47 +0000119 fixture->fib.insert(Name()).first->addOrUpdateNextHop(*fixture->face1, 0, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000120 }
121};
122
123template<typename S>
124class NextHopViolatesScope
125{
126public:
127 Name
128 getInterestName()
129 {
130 return "/localhop/P";
131 }
132
133 void
134 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
135 {
ashiqopu3ad49db2018-10-20 22:38:47 +0000136 fixture->fib.insert("/localhop").first->addOrUpdateNextHop(*fixture->face2, 0, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000137 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
138 }
139};
140
141using Tests = boost::mpl::vector<
142 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
143 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
144 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
145
146 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
147 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
148 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
149
150 Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
151 Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
152 Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>
153>;
154
155BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
156 StrategyNoRouteFixture<typename T::Strategy>)
157{
158 typename T::Case scenario;
159 scenario.insertFibEntry(this);
160
161 shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
162 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000163 pitEntry->insertOrUpdateInRecord(*this->face1, 0, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000164
165 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000166 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry); },
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000167 this->limitedIo, 2));
168
169 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
170 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest());
171
172 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
173 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
174 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
175 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
176}
177
178BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
179BOOST_AUTO_TEST_SUITE_END() // Fw
180
181} // namespace tests
182} // namespace fw
183} // namespace nfd