blob: 2952259e3911cdccc21a74cbed2ad749bfa9130a [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/*
Alexander Afanasyev4400e422021-02-17 11:17:33 -05003 * Copyright (c) 2014-2021, 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"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070035#include "fw/random-strategy.hpp"
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000036
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040037#include "tests/test-common.hpp"
38#include "tests/daemon/face/dummy-face.hpp"
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000039#include "choose-strategy.hpp"
40#include "strategy-tester.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060041
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000042#include <boost/mpl/copy_if.hpp>
43#include <boost/mpl/vector.hpp>
44
45namespace nfd {
46namespace fw {
47namespace tests {
48
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000049template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040050class StrategyNoRouteFixture : public GlobalIoTimeFixture
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000051{
52public:
53 StrategyNoRouteFixture()
54 : limitedIo(this)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040055 , forwarder(faceTable)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000056 , strategy(choose<StrategyTester<S>>(forwarder))
57 , fib(forwarder.getFib())
58 , pit(forwarder.getPit())
59 , face1(make_shared<DummyFace>())
60 , face2(make_shared<DummyFace>())
61 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040062 faceTable.add(face1);
63 faceTable.add(face2);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000064 }
65
66public:
67 LimitedIo limitedIo;
68
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040069 FaceTable faceTable;
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000070 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
79BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040080BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000081
82template<typename S, typename C>
83class Test
84{
85public:
86 using Strategy = S;
87 using Case = C;
88};
89
90template<typename S>
91class EmptyNextHopList
92{
93public:
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
107template<typename S>
108class NextHopIsDownstream
109{
110public:
111 Name
112 getInterestName()
113 {
114 return "/P";
115 }
116
117 void
118 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
119 {
Ju Pand8315bf2019-07-31 06:59:07 +0000120 fib::Entry* entry = fixture->fib.insert(Name()).first;
121 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000122 }
123};
124
125template<typename S>
126class NextHopViolatesScope
127{
128public:
129 Name
130 getInterestName()
131 {
132 return "/localhop/P";
133 }
134
135 void
136 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
137 {
Ju Pand8315bf2019-07-31 06:59:07 +0000138 fib::Entry* entry = fixture->fib.insert("/localhop").first;
139 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000140 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
141 }
142};
143
144using Tests = boost::mpl::vector<
145 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
146 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
147 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
148
149 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
150 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
151 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
152
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700153 Test<RandomStrategy, EmptyNextHopList<RandomStrategy>>,
154 Test<RandomStrategy, NextHopIsDownstream<RandomStrategy>>,
155 Test<RandomStrategy, NextHopViolatesScope<RandomStrategy>>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000156>;
157
158BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
159 StrategyNoRouteFixture<typename T::Strategy>)
160{
161 typename T::Case scenario;
162 scenario.insertFibEntry(this);
163
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400164 auto interest = makeInterest(scenario.getInterestName());
165 auto pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000166 pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000167
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400168 auto f = [&] {
169 this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry);
170 };
171 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000172
173 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400174 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
175 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000176
177 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400178 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
179 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000180 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
181 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
182}
183
184BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
185BOOST_AUTO_TEST_SUITE_END() // Fw
186
187} // namespace tests
188} // namespace fw
189} // namespace nfd