blob: cec64c48c548fb3752485c9fab00a18217f878e5 [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
Davide Pesavento58091582021-03-05 19:02:48 -050027 * This test suite checks that a strategy returns Nack-NoRoute when there are
28 * no usable FIB nexthops.
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000029 */
30
Davide Pesavento58091582021-03-05 19:02:48 -050031// Strategies returning Nack-NoRoute when there are no usable FIB nexthops,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000032// sorted alphabetically.
33#include "fw/asf-strategy.hpp"
Davide Pesavento7922d122021-03-05 22:41:23 -050034#include "fw/best-route-strategy.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/vector.hpp>
43
44namespace nfd {
45namespace fw {
46namespace tests {
47
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000048template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040049class StrategyNoRouteFixture : public GlobalIoTimeFixture
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000050{
51public:
52 StrategyNoRouteFixture()
53 : limitedIo(this)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040054 , forwarder(faceTable)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000055 , strategy(choose<StrategyTester<S>>(forwarder))
56 , fib(forwarder.getFib())
57 , pit(forwarder.getPit())
58 , face1(make_shared<DummyFace>())
59 , face2(make_shared<DummyFace>())
60 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040061 faceTable.add(face1);
62 faceTable.add(face2);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000063 }
64
65public:
66 LimitedIo limitedIo;
67
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040068 FaceTable faceTable;
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000069 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)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040079BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000080
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 {
Ju Pand8315bf2019-07-31 06:59:07 +0000119 fib::Entry* entry = fixture->fib.insert(Name()).first;
120 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000121 }
122};
123
124template<typename S>
125class NextHopViolatesScope
126{
127public:
128 Name
129 getInterestName()
130 {
131 return "/localhop/P";
132 }
133
134 void
135 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
136 {
Ju Pand8315bf2019-07-31 06:59:07 +0000137 fib::Entry* entry = fixture->fib.insert("/localhop").first;
138 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000139 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
140 }
141};
142
143using Tests = boost::mpl::vector<
144 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
145 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
146 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
147
Davide Pesavento7922d122021-03-05 22:41:23 -0500148 Test<BestRouteStrategy, EmptyNextHopList<BestRouteStrategy>>,
149 Test<BestRouteStrategy, NextHopIsDownstream<BestRouteStrategy>>,
150 Test<BestRouteStrategy, NextHopViolatesScope<BestRouteStrategy>>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000151
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700152 Test<RandomStrategy, EmptyNextHopList<RandomStrategy>>,
153 Test<RandomStrategy, NextHopIsDownstream<RandomStrategy>>,
154 Test<RandomStrategy, NextHopViolatesScope<RandomStrategy>>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000155>;
156
Davide Pesavento58091582021-03-05 19:02:48 -0500157BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest,
158 T, Tests, StrategyNoRouteFixture<typename T::Strategy>)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000159{
160 typename T::Case scenario;
161 scenario.insertFibEntry(this);
162
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400163 auto interest = makeInterest(scenario.getInterestName());
164 auto pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000165 pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000166
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400167 auto f = [&] {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400168 this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->face1, 0), pitEntry);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400169 };
170 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000171
172 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400173 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
174 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000175
176 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400177 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
178 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000179 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
180 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
181}
182
183BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
184BOOST_AUTO_TEST_SUITE_END() // Fw
185
186} // namespace tests
187} // namespace fw
188} // namespace nfd