blob: 43c57d0cc62f405e7f81735aebe8a464f9925eee [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
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)
55 , strategy(choose<StrategyTester<S>>(forwarder))
56 , fib(forwarder.getFib())
57 , pit(forwarder.getPit())
58 , face1(make_shared<DummyFace>())
59 , face2(make_shared<DummyFace>())
60 {
61 forwarder.addFace(face1);
62 forwarder.addFace(face2);
63 }
64
65public:
66 LimitedIo limitedIo;
67
68 Forwarder forwarder;
69 StrategyTester<S>& strategy;
70 Fib& fib;
71 Pit& pit;
72
73 shared_ptr<Face> face1;
74 shared_ptr<Face> face2;
75};
76
77BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040078BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000079
80template<typename S, typename C>
81class Test
82{
83public:
84 using Strategy = S;
85 using Case = C;
86};
87
88template<typename S>
89class EmptyNextHopList
90{
91public:
92 Name
93 getInterestName()
94 {
95 return "/P";
96 }
97
98 void
99 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
100 {
101 fixture->fib.insert(Name());
102 }
103};
104
105template<typename S>
106class NextHopIsDownstream
107{
108public:
109 Name
110 getInterestName()
111 {
112 return "/P";
113 }
114
115 void
116 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
117 {
ashiqopu3ad49db2018-10-20 22:38:47 +0000118 fixture->fib.insert(Name()).first->addOrUpdateNextHop(*fixture->face1, 0, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000119 }
120};
121
122template<typename S>
123class NextHopViolatesScope
124{
125public:
126 Name
127 getInterestName()
128 {
129 return "/localhop/P";
130 }
131
132 void
133 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
134 {
ashiqopu3ad49db2018-10-20 22:38:47 +0000135 fixture->fib.insert("/localhop").first->addOrUpdateNextHop(*fixture->face2, 0, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000136 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
137 }
138};
139
140using Tests = boost::mpl::vector<
141 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
142 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
143 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
144
145 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
146 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
147 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
148
149 Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
150 Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
151 Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>
152>;
153
154BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
155 StrategyNoRouteFixture<typename T::Strategy>)
156{
157 typename T::Case scenario;
158 scenario.insertFibEntry(this);
159
160 shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
161 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000162 pitEntry->insertOrUpdateInRecord(*this->face1, 0, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000163
164 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000165 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry); },
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000166 this->limitedIo, 2));
167
168 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
169 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest());
170
171 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
172 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
173 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
174 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
175}
176
177BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
178BOOST_AUTO_TEST_SUITE_END() // Fw
179
180} // namespace tests
181} // namespace fw
182} // namespace nfd