blob: a8fed80da3b1bed89237090a7782118502d34e9b [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 {
Ju Pand8315bf2019-07-31 06:59:07 +0000118 fib::Entry* entry = fixture->fib.insert(Name()).first;
119 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 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 {
Ju Pand8315bf2019-07-31 06:59:07 +0000136 fib::Entry* entry = fixture->fib.insert("/localhop").first;
137 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000138 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
139 }
140};
141
142using Tests = boost::mpl::vector<
143 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
144 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
145 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
146
147 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
148 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
149 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
150
151 Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
152 Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
153 Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>
154>;
155
156BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
157 StrategyNoRouteFixture<typename T::Strategy>)
158{
159 typename T::Case scenario;
160 scenario.insertFibEntry(this);
161
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400162 auto interest = makeInterest(scenario.getInterestName());
163 auto pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000164 pitEntry->insertOrUpdateInRecord(*this->face1, 0, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000165
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400166 auto f = [&] {
167 this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry);
168 };
169 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000170
171 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400172 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
173 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000174
175 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400176 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
177 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000178 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
179 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
180}
181
182BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
183BOOST_AUTO_TEST_SUITE_END() // Fw
184
185} // namespace tests
186} // namespace fw
187} // namespace nfd