blob: 4ebd5cf680327c27c35f8bbfeeccbd5b60b7f62b [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"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070036#include "fw/random-strategy.hpp"
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000037
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038#include "tests/test-common.hpp"
39#include "tests/daemon/face/dummy-face.hpp"
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000040#include "choose-strategy.hpp"
41#include "strategy-tester.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060042
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000043#include <boost/mpl/copy_if.hpp>
44#include <boost/mpl/vector.hpp>
45
46namespace nfd {
47namespace fw {
48namespace tests {
49
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000050template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040051class StrategyNoRouteFixture : public GlobalIoTimeFixture
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000052{
53public:
54 StrategyNoRouteFixture()
55 : limitedIo(this)
56 , strategy(choose<StrategyTester<S>>(forwarder))
57 , fib(forwarder.getFib())
58 , pit(forwarder.getPit())
59 , face1(make_shared<DummyFace>())
60 , face2(make_shared<DummyFace>())
61 {
62 forwarder.addFace(face1);
63 forwarder.addFace(face2);
64 }
65
66public:
67 LimitedIo limitedIo;
68
69 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
148 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
149 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
150 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
151
152 Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
153 Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700154 Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>,
155
156 Test<RandomStrategy, EmptyNextHopList<RandomStrategy>>,
157 Test<RandomStrategy, NextHopIsDownstream<RandomStrategy>>,
158 Test<RandomStrategy, NextHopViolatesScope<RandomStrategy>>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000159>;
160
161BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
162 StrategyNoRouteFixture<typename T::Strategy>)
163{
164 typename T::Case scenario;
165 scenario.insertFibEntry(this);
166
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400167 auto interest = makeInterest(scenario.getInterestName());
168 auto pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000169 pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000170
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400171 auto f = [&] {
172 this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry);
173 };
174 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000175
176 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400177 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
178 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000179
180 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400181 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
182 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000183 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
184 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
185}
186
187BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
188BOOST_AUTO_TEST_SUITE_END() // Fw
189
190} // namespace tests
191} // namespace fw
192} // namespace nfd