blob: 123a4f8bdc5bc78b50543e5df0a8e462cfd34f51 [file] [log] [blame]
Junxiao Shia7f9a292016-11-22 16:31:38 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopu3ad49db2018-10-20 22:38:47 +00002/*
Alexander Afanasyev4400e422021-02-17 11:17:33 -05003 * Copyright (c) 2014-2021, Regents of the University of California,
Junxiao Shia7f9a292016-11-22 16:31:38 +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 tests localhost and localhop scope control in strategies.
28 */
29
30// Strategies implementing namespace-based scope control, sorted alphabetically.
31#include "fw/access-strategy.hpp"
Ashlesh Gawande2a73f352016-12-01 15:37:03 +000032#include "fw/asf-strategy.hpp"
Junxiao Shie21b3f32016-11-24 14:13:46 +000033#include "fw/best-route-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000034#include "fw/best-route-strategy2.hpp"
Junxiao Shie21b3f32016-11-24 14:13:46 +000035#include "fw/multicast-strategy.hpp"
36#include "fw/ncc-strategy.hpp"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070037#include "fw/random-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000038
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040039#include "tests/test-common.hpp"
40#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000041#include "choose-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000042#include "strategy-tester.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060043
Junxiao Shia7f9a292016-11-22 16:31:38 +000044#include <boost/mpl/copy_if.hpp>
45#include <boost/mpl/vector.hpp>
46
47namespace nfd {
48namespace fw {
49namespace tests {
50
Junxiao Shia7f9a292016-11-22 16:31:38 +000051template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040052class StrategyScopeControlFixture : public GlobalIoTimeFixture
Junxiao Shia7f9a292016-11-22 16:31:38 +000053{
54public:
55 StrategyScopeControlFixture()
56 : limitedIo(this)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040057 , forwarder(faceTable)
Junxiao Shie21b3f32016-11-24 14:13:46 +000058 , strategy(choose<StrategyTester<S>>(forwarder))
Junxiao Shia7f9a292016-11-22 16:31:38 +000059 , fib(forwarder.getFib())
60 , pit(forwarder.getPit())
61 , nonLocalFace1(make_shared<DummyFace>("dummy://1", "dummy://1", ndn::nfd::FACE_SCOPE_NON_LOCAL))
62 , nonLocalFace2(make_shared<DummyFace>("dummy://2", "dummy://2", ndn::nfd::FACE_SCOPE_NON_LOCAL))
63 , localFace3(make_shared<DummyFace>("dummy://3", "dummy://3", ndn::nfd::FACE_SCOPE_LOCAL))
64 , localFace4(make_shared<DummyFace>("dummy://4", "dummy://4", ndn::nfd::FACE_SCOPE_LOCAL))
65 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040066 faceTable.add(nonLocalFace1);
67 faceTable.add(nonLocalFace2);
68 faceTable.add(localFace3);
69 faceTable.add(localFace4);
Junxiao Shia7f9a292016-11-22 16:31:38 +000070 }
71
Junxiao Shia7f9a292016-11-22 16:31:38 +000072public:
73 LimitedIo limitedIo;
Junxiao Shia7f9a292016-11-22 16:31:38 +000074
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040075 FaceTable faceTable;
Junxiao Shia7f9a292016-11-22 16:31:38 +000076 Forwarder forwarder;
Junxiao Shie21b3f32016-11-24 14:13:46 +000077 StrategyTester<S>& strategy;
Junxiao Shia7f9a292016-11-22 16:31:38 +000078 Fib& fib;
79 Pit& pit;
80
81 shared_ptr<Face> nonLocalFace1;
82 shared_ptr<Face> nonLocalFace2;
83 shared_ptr<Face> localFace3;
84 shared_ptr<Face> localFace4;
85};
86
87BOOST_AUTO_TEST_SUITE(Fw)
88BOOST_AUTO_TEST_SUITE(TestStrategyScopeControl)
89
Alexander Afanasyev4400e422021-02-17 11:17:33 -050090template<typename S, bool WillSendNackNoRoute, bool CanProcessNack, bool WillRejectPitEntry = true>
Junxiao Shie21b3f32016-11-24 14:13:46 +000091class Test
Junxiao Shia7f9a292016-11-22 16:31:38 +000092{
93public:
Junxiao Shie21b3f32016-11-24 14:13:46 +000094 using Strategy = S;
Junxiao Shia7f9a292016-11-22 16:31:38 +000095
96 static bool
Alexander Afanasyev4400e422021-02-17 11:17:33 -050097 willRejectPitEntry()
98 {
99 return WillRejectPitEntry;
100 }
101
102 static bool
Junxiao Shia7f9a292016-11-22 16:31:38 +0000103 willSendNackNoRoute()
104 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000105 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000106 }
107
108 static bool
109 canProcessNack()
110 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000111 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000112 }
113};
114
115using Tests = boost::mpl::vector<
Junxiao Shie21b3f32016-11-24 14:13:46 +0000116 Test<AccessStrategy, false, false>,
Ashlesh Gawande2a73f352016-12-01 15:37:03 +0000117 Test<AsfStrategy, true, false>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000118 Test<BestRouteStrategy, false, false>,
119 Test<BestRouteStrategy2, true, true>,
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500120 Test<MulticastStrategy, false, false, false>,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700121 Test<NccStrategy, false, false>,
122 Test<RandomStrategy, true, true>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000123>;
124
125BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000126 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000127{
128 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000129 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000130
Junxiao Shi9d727852019-05-14 13:44:22 -0600131 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000132 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000133 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000134
Junxiao Shi99540072017-01-27 19:57:33 +0000135 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000136 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000137 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000138
139 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
140 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
141 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
142}
143
144BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000145 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000146{
147 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000148 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000149
Junxiao Shi9d727852019-05-14 13:44:22 -0600150 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000151 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000152 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000153
Junxiao Shi99540072017-01-27 19:57:33 +0000154 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000155 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500156 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000157
158 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500159 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000160 if (T::willSendNackNoRoute()) {
161 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
162 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
163 }
164}
165
166BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000167 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000168{
169 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000170 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
171 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000172
Junxiao Shi9d727852019-05-14 13:44:22 -0600173 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000174 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000175 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000176
Junxiao Shi99540072017-01-27 19:57:33 +0000177 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000178 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000179 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000180
181 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
182 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
183 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
184 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
185}
186
187BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000188 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000189{
190 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000191 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000192
Junxiao Shi9d727852019-05-14 13:44:22 -0600193 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000194 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000195 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000196
Junxiao Shi99540072017-01-27 19:57:33 +0000197 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000198 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500199 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000200
201 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500202 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000203 if (T::willSendNackNoRoute()) {
204 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
205 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
206 }
207}
208
209BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000210 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000211{
212 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000213 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
214 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000215
Junxiao Shi9d727852019-05-14 13:44:22 -0600216 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000217 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000218 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000219
Junxiao Shi99540072017-01-27 19:57:33 +0000220 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000221 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000222 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000223
224 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
225 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
226 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
227 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
228}
229
230BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000231 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000232{
233 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000234 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
235 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000236
Junxiao Shi9d727852019-05-14 13:44:22 -0600237 auto interest = makeInterest("/localhost/A/1", false, nullopt, 1460);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000238 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000239 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600240 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000241 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000242
Junxiao Shi99540072017-01-27 19:57:33 +0000243 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000244 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000245 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000246
247 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
248 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
249 if (T::canProcessNack()) {
250 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
251 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
252 }
253}
254
255BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000256 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000257{
258 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000259 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
260 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000261
Junxiao Shi9d727852019-05-14 13:44:22 -0600262 auto interest = makeInterest("/localhop/A/1", 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000263 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000264 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600265 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000266 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000267
Junxiao Shi99540072017-01-27 19:57:33 +0000268 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000269 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000270 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000271
272 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
273 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
274 if (T::canProcessNack()) {
275 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
276 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
277 }
278}
279
280BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
281BOOST_AUTO_TEST_SUITE_END() // Fw
282
283} // namespace tests
284} // namespace fw
285} // namespace nfd