blob: 26b7874917dd5ce9525681e1abe0427942330f8c [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)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040056 , forwarder(faceTable)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000057 , strategy(choose<StrategyTester<S>>(forwarder))
58 , fib(forwarder.getFib())
59 , pit(forwarder.getPit())
60 , face1(make_shared<DummyFace>())
61 , face2(make_shared<DummyFace>())
62 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040063 faceTable.add(face1);
64 faceTable.add(face2);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000065 }
66
67public:
68 LimitedIo limitedIo;
69
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040070 FaceTable faceTable;
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000071 Forwarder forwarder;
72 StrategyTester<S>& strategy;
73 Fib& fib;
74 Pit& pit;
75
76 shared_ptr<Face> face1;
77 shared_ptr<Face> face2;
78};
79
80BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040081BOOST_AUTO_TEST_SUITE(TestStrategyNoRoute)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000082
83template<typename S, typename C>
84class Test
85{
86public:
87 using Strategy = S;
88 using Case = C;
89};
90
91template<typename S>
92class EmptyNextHopList
93{
94public:
95 Name
96 getInterestName()
97 {
98 return "/P";
99 }
100
101 void
102 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
103 {
104 fixture->fib.insert(Name());
105 }
106};
107
108template<typename S>
109class NextHopIsDownstream
110{
111public:
112 Name
113 getInterestName()
114 {
115 return "/P";
116 }
117
118 void
119 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
120 {
Ju Pand8315bf2019-07-31 06:59:07 +0000121 fib::Entry* entry = fixture->fib.insert(Name()).first;
122 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face1, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000123 }
124};
125
126template<typename S>
127class NextHopViolatesScope
128{
129public:
130 Name
131 getInterestName()
132 {
133 return "/localhop/P";
134 }
135
136 void
137 insertFibEntry(StrategyNoRouteFixture<S>* fixture)
138 {
Ju Pand8315bf2019-07-31 06:59:07 +0000139 fib::Entry* entry = fixture->fib.insert("/localhop").first;
140 fixture->fib.addOrUpdateNextHop(*entry, *fixture->face2, 10);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000141 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
142 }
143};
144
145using Tests = boost::mpl::vector<
146 Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
147 Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
148 Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
149
150 Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
151 Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
152 Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
153
154 Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
155 Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700156 Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>,
157
158 Test<RandomStrategy, EmptyNextHopList<RandomStrategy>>,
159 Test<RandomStrategy, NextHopIsDownstream<RandomStrategy>>,
160 Test<RandomStrategy, NextHopViolatesScope<RandomStrategy>>
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000161>;
162
163BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
164 StrategyNoRouteFixture<typename T::Strategy>)
165{
166 typename T::Case scenario;
167 scenario.insertFibEntry(this);
168
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400169 auto interest = makeInterest(scenario.getInterestName());
170 auto pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000171 pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000172
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400173 auto f = [&] {
174 this->strategy.afterReceiveInterest(FaceEndpoint(*this->face1, 0), *interest, pitEntry);
175 };
176 BOOST_REQUIRE(this->strategy.waitForAction(f, this->limitedIo, 2));
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000177
178 BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400179 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest.wireEncode(),
180 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000181
182 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400183 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest.wireEncode(),
184 pitEntry->getInterest().wireEncode());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000185 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
186 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
187}
188
189BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
190BOOST_AUTO_TEST_SUITE_END() // Fw
191
192} // namespace tests
193} // namespace fw
194} // namespace nfd