blob: 2e70e0e6f6d93652379ada306311b928fddd16df [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/*
Davide Pesaventof56cf632024-01-27 22:22:06 -05003 * Copyright (c) 2014-2024, 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
Davide Pesaventof56cf632024-01-27 22:22:06 -050042#include <boost/mp11/list.hpp>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000043
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040044namespace nfd::tests {
45
46using namespace nfd::fw;
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000047
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
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000081template<typename S>
Davide Pesaventof56cf632024-01-27 22:22:06 -050082struct EmptyNextHopList
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000083{
Davide Pesaventof56cf632024-01-27 22:22:06 -050084 static Name
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000085 getInterestName()
86 {
87 return "/P";
88 }
89
Davide Pesaventof56cf632024-01-27 22:22:06 -050090 static void
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000091 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
92 {
93 fixture->fib.insert(Name());
94 }
95};
96
97template<typename S>
Davide Pesaventof56cf632024-01-27 22:22:06 -050098struct NextHopIsDownstream
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000099{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500100 static Name
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000101 getInterestName()
102 {
103 return "/P";
104 }
105
Davide Pesaventof56cf632024-01-27 22:22:06 -0500106 static void
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000107 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
108 {
Ju Pand8315bf2019-07-31 06:59:07 +0000109 fib::Entry* entry = fixture->fib.insert(Name()).first;
110 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000111 }
112};
113
114template<typename S>
Davide Pesaventof56cf632024-01-27 22:22:06 -0500115struct NextHopViolatesScope
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000116{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500117 static Name
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000118 getInterestName()
119 {
120 return "/localhop/P";
121 }
122
Davide Pesaventof56cf632024-01-27 22:22:06 -0500123 static void
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000124 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
125 {
Ju Pand8315bf2019-07-31 06:59:07 +0000126 fib::Entry* entry = fixture->fib.insert("/localhop").first;
127 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000128 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
129 }
130};
131
Davide Pesaventof56cf632024-01-27 22:22:06 -0500132using Tests = boost::mp11::mp_list<
133 boost::mp11::mp_list<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
134 boost::mp11::mp_list<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
135 boost::mp11::mp_list<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000136
Davide Pesaventof56cf632024-01-27 22:22:06 -0500137 boost::mp11::mp_list<BestRouteStrategy, EmptyNextHopList<BestRouteStrategy>>,
138 boost::mp11::mp_list<BestRouteStrategy, NextHopIsDownstream<BestRouteStrategy>>,
139 boost::mp11::mp_list<BestRouteStrategy, NextHopViolatesScope<BestRouteStrategy>>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000140
Davide Pesaventof56cf632024-01-27 22:22:06 -0500141 boost::mp11::mp_list<RandomStrategy, EmptyNextHopList<RandomStrategy>>,
142 boost::mp11::mp_list<RandomStrategy, NextHopIsDownstream<RandomStrategy>>,
143 boost::mp11::mp_list<RandomStrategy, NextHopViolatesScope<RandomStrategy>>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000144>;
145
Davide Pesavento58091582021-03-05 19:02:48 -0500146BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest,
Davide Pesaventof56cf632024-01-27 22:22:06 -0500147 T, Tests, StrategyNoRouteFixture<boost::mp11::mp_first<T>>)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000148{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500149 using Scenario = boost::mp11::mp_second<T>;
150 Scenario::insertFibEntry(this);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000151
Davide Pesaventof56cf632024-01-27 22:22:06 -0500152 auto interest = makeInterest(Scenario::getInterestName());
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400153 auto pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000154 pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000155
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400156 auto f = [&] {
Teng Liangd94b7b32022-07-10 21:29:37 +0800157 this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->face1), pitEntry);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400158 };
159 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000160
161 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400162 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
163 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000164
165 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400166 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
167 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000168 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
169 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
170}
171
172BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
173BOOST_AUTO_TEST_SUITE_END() // Fw
174
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400175} // namespace nfd::tests