blob: 2c8dd626bc82dc04252a9b532e4e5a4c0e73751c [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/*
Davide Pesaventof56cf632024-01-27 22:22:06 -05003 * Copyright (c) 2014-2024, 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"
Davide Pesavento7922d122021-03-05 22:41:23 -050033#include "fw/best-route-strategy.hpp"
Junxiao Shie21b3f32016-11-24 14:13:46 +000034#include "fw/multicast-strategy.hpp"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070035#include "fw/random-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000036
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040037#include "tests/test-common.hpp"
38#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000039#include "choose-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000040#include "strategy-tester.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060041
Davide Pesaventof56cf632024-01-27 22:22:06 -050042#include <boost/mp11/list.hpp>
Junxiao Shia7f9a292016-11-22 16:31:38 +000043
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040044namespace nfd::tests {
45
46using namespace nfd::fw;
Junxiao Shia7f9a292016-11-22 16:31:38 +000047
Junxiao Shia7f9a292016-11-22 16:31:38 +000048template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040049class StrategyScopeControlFixture : public GlobalIoTimeFixture
Junxiao Shia7f9a292016-11-22 16:31:38 +000050{
51public:
52 StrategyScopeControlFixture()
53 : limitedIo(this)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040054 , forwarder(faceTable)
Junxiao Shie21b3f32016-11-24 14:13:46 +000055 , strategy(choose<StrategyTester<S>>(forwarder))
Junxiao Shia7f9a292016-11-22 16:31:38 +000056 , fib(forwarder.getFib())
57 , pit(forwarder.getPit())
58 , nonLocalFace1(make_shared<DummyFace>("dummy://1", "dummy://1", ndn::nfd::FACE_SCOPE_NON_LOCAL))
59 , nonLocalFace2(make_shared<DummyFace>("dummy://2", "dummy://2", ndn::nfd::FACE_SCOPE_NON_LOCAL))
60 , localFace3(make_shared<DummyFace>("dummy://3", "dummy://3", ndn::nfd::FACE_SCOPE_LOCAL))
61 , localFace4(make_shared<DummyFace>("dummy://4", "dummy://4", ndn::nfd::FACE_SCOPE_LOCAL))
62 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040063 faceTable.add(nonLocalFace1);
64 faceTable.add(nonLocalFace2);
65 faceTable.add(localFace3);
66 faceTable.add(localFace4);
Junxiao Shia7f9a292016-11-22 16:31:38 +000067 }
68
Junxiao Shia7f9a292016-11-22 16:31:38 +000069public:
70 LimitedIo limitedIo;
Junxiao Shia7f9a292016-11-22 16:31:38 +000071
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040072 FaceTable faceTable;
Junxiao Shia7f9a292016-11-22 16:31:38 +000073 Forwarder forwarder;
Junxiao Shie21b3f32016-11-24 14:13:46 +000074 StrategyTester<S>& strategy;
Junxiao Shia7f9a292016-11-22 16:31:38 +000075 Fib& fib;
76 Pit& pit;
77
78 shared_ptr<Face> nonLocalFace1;
79 shared_ptr<Face> nonLocalFace2;
80 shared_ptr<Face> localFace3;
81 shared_ptr<Face> localFace4;
82};
83
84BOOST_AUTO_TEST_SUITE(Fw)
85BOOST_AUTO_TEST_SUITE(TestStrategyScopeControl)
86
Davide Pesavento29abf4c2021-03-05 18:40:01 -050087template<typename S, bool WillSendNackNoRoute, bool CanProcessNack, bool WillRejectPitEntry>
Davide Pesaventof56cf632024-01-27 22:22:06 -050088struct Test
Junxiao Shia7f9a292016-11-22 16:31:38 +000089{
Junxiao Shie21b3f32016-11-24 14:13:46 +000090 using Strategy = S;
Davide Pesaventof56cf632024-01-27 22:22:06 -050091 static constexpr bool canProcessNack = CanProcessNack;
92 static constexpr bool willRejectPitEntry = WillRejectPitEntry;
93 static constexpr bool willSendNackNoRoute = WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +000094};
95
Davide Pesaventof56cf632024-01-27 22:22:06 -050096using Tests = boost::mp11::mp_list<
Davide Pesavento29abf4c2021-03-05 18:40:01 -050097 Test<AccessStrategy, false, false, true>,
awlane9acba9c2024-01-26 18:10:39 -060098 Test<AsfStrategy, true, true, true>,
Davide Pesavento7922d122021-03-05 22:41:23 -050099 Test<BestRouteStrategy, true, true, true>,
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500100 Test<MulticastStrategy, false, false, false>,
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500101 Test<RandomStrategy, true, true, true>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000102>;
103
104BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000105 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000106{
107 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000108 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000109
Junxiao Shi9d727852019-05-14 13:44:22 -0600110 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000111 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000112 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000113
Junxiao Shi99540072017-01-27 19:57:33 +0000114 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800115 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000116 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000117
118 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
119 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
120 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
121}
122
123BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000124 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000125{
126 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000127 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000128
Junxiao Shi9d727852019-05-14 13:44:22 -0600129 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000130 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000131 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000132
Junxiao Shi99540072017-01-27 19:57:33 +0000133 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800134 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3), pitEntry); },
Davide Pesaventof56cf632024-01-27 22:22:06 -0500135 this->limitedIo, T::willRejectPitEntry + T::willSendNackNoRoute));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000136
137 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Davide Pesaventof56cf632024-01-27 22:22:06 -0500138 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry);
139 if (T::willSendNackNoRoute) {
Junxiao Shia7f9a292016-11-22 16:31:38 +0000140 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
141 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
142 }
143}
144
145BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000146 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000147{
148 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000149 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
150 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000151
Junxiao Shi9d727852019-05-14 13:44:22 -0600152 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000153 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000154 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000155
Junxiao Shi99540072017-01-27 19:57:33 +0000156 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800157 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000158 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000159
160 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
161 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
162 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
163 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
164}
165
166BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
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("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000170 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000171
Junxiao Shi9d727852019-05-14 13:44:22 -0600172 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000173 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000174 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000175
Junxiao Shi99540072017-01-27 19:57:33 +0000176 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800177 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->nonLocalFace1), pitEntry); },
Davide Pesaventof56cf632024-01-27 22:22:06 -0500178 this->limitedIo, T::willRejectPitEntry + T::willSendNackNoRoute));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000179
180 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Davide Pesaventof56cf632024-01-27 22:22:06 -0500181 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry);
182 if (T::willSendNackNoRoute) {
Junxiao Shia7f9a292016-11-22 16:31:38 +0000183 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
184 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
185 }
186}
187
188BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000189 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000190{
191 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000192 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
193 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000194
Junxiao Shi9d727852019-05-14 13:44:22 -0600195 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000196 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000197 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000198
Junxiao Shi99540072017-01-27 19:57:33 +0000199 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800200 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->nonLocalFace1), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000201 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000202
203 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
204 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
205 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
206 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
207}
208
209BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
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("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000213 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
214 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000215
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400216 auto interest = makeInterest("/localhost/A/1", false, std::nullopt, 1460);
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->localFace3, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600219 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000220 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000221
Junxiao Shi99540072017-01-27 19:57:33 +0000222 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800223 [&] { this->strategy.afterReceiveNack(nack, FaceEndpoint(*this->localFace4), pitEntry); },
Davide Pesaventof56cf632024-01-27 22:22:06 -0500224 this->limitedIo, T::canProcessNack));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000225
226 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
227 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
Davide Pesaventof56cf632024-01-27 22:22:06 -0500228 if (T::canProcessNack) {
Junxiao Shia7f9a292016-11-22 16:31:38 +0000229 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
230 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
231 }
232}
233
234BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000235 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000236{
237 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000238 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
239 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000240
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400241 auto interest = makeInterest("/localhop/A/1", false, std::nullopt, 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000242 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000243 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600244 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000245 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000246
Junxiao Shi99540072017-01-27 19:57:33 +0000247 BOOST_REQUIRE(this->strategy.waitForAction(
Teng Liangd94b7b32022-07-10 21:29:37 +0800248 [&] { this->strategy.afterReceiveNack(nack, FaceEndpoint(*this->localFace4), pitEntry); },
Davide Pesaventof56cf632024-01-27 22:22:06 -0500249 this->limitedIo, T::canProcessNack));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000250
251 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
252 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
Davide Pesaventof56cf632024-01-27 22:22:06 -0500253 if (T::canProcessNack) {
Junxiao Shia7f9a292016-11-22 16:31:38 +0000254 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
255 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
256 }
257}
258
259BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
260BOOST_AUTO_TEST_SUITE_END() // Fw
261
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400262} // namespace nfd::tests