blob: 86e95402019b927e48beeefc965e596444382e82 [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 Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, 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
Junxiao Shia7f9a292016-11-22 16:31:38 +000042#include <boost/mpl/vector.hpp>
43
44namespace nfd {
45namespace fw {
46namespace tests {
47
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>
Junxiao Shie21b3f32016-11-24 14:13:46 +000088class Test
Junxiao Shia7f9a292016-11-22 16:31:38 +000089{
90public:
Junxiao Shie21b3f32016-11-24 14:13:46 +000091 using Strategy = S;
Junxiao Shia7f9a292016-11-22 16:31:38 +000092
93 static bool
Alexander Afanasyev4400e422021-02-17 11:17:33 -050094 willRejectPitEntry()
95 {
96 return WillRejectPitEntry;
97 }
98
99 static bool
Junxiao Shia7f9a292016-11-22 16:31:38 +0000100 willSendNackNoRoute()
101 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000102 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000103 }
104
105 static bool
106 canProcessNack()
107 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000108 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000109 }
110};
111
112using Tests = boost::mpl::vector<
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500113 Test<AccessStrategy, false, false, true>,
114 Test<AsfStrategy, true, false, true>,
Davide Pesavento7922d122021-03-05 22:41:23 -0500115 Test<BestRouteStrategy, true, true, true>,
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500116 Test<MulticastStrategy, false, false, false>,
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500117 Test<RandomStrategy, true, true, true>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000118>;
119
120BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000121 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000122{
123 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000124 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000125
Junxiao Shi9d727852019-05-14 13:44:22 -0600126 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000127 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000128 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000129
Junxiao Shi99540072017-01-27 19:57:33 +0000130 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400131 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3, 0), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000132 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000133
134 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
135 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
136 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
137}
138
139BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000140 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000141{
142 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000143 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000144
Junxiao Shi9d727852019-05-14 13:44:22 -0600145 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000146 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000147 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000148
Junxiao Shi99540072017-01-27 19:57:33 +0000149 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400150 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3, 0), pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500151 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000152
153 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500154 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000155 if (T::willSendNackNoRoute()) {
156 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
157 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
158 }
159}
160
161BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000162 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000163{
164 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000165 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
166 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000167
Junxiao Shi9d727852019-05-14 13:44:22 -0600168 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000169 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000170 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000171
Junxiao Shi99540072017-01-27 19:57:33 +0000172 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400173 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->localFace3, 0), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000174 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000175
176 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
177 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
178 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
179 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
180}
181
182BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000183 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000184{
185 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000186 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000187
Junxiao Shi9d727852019-05-14 13:44:22 -0600188 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000189 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000190 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000191
Junxiao Shi99540072017-01-27 19:57:33 +0000192 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400193 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->nonLocalFace1, 0), pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500194 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000195
196 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500197 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000198 if (T::willSendNackNoRoute()) {
199 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
200 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
201 }
202}
203
204BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000205 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000206{
207 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000208 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
209 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000210
Junxiao Shi9d727852019-05-14 13:44:22 -0600211 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000212 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000213 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000214
Junxiao Shi99540072017-01-27 19:57:33 +0000215 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400216 [&] { this->strategy.afterReceiveInterest(*interest, FaceEndpoint(*this->nonLocalFace1, 0), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000217 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000218
219 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
220 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
221 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
222 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
223}
224
225BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000226 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000227{
228 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000229 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
230 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000231
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400232 auto interest = makeInterest("/localhost/A/1", false, std::nullopt, 1460);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000233 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000234 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600235 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000236 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000237
Junxiao Shi99540072017-01-27 19:57:33 +0000238 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400239 [&] { this->strategy.afterReceiveNack(nack, FaceEndpoint(*this->localFace4, 0), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000240 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000241
242 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
243 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
244 if (T::canProcessNack()) {
245 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
246 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
247 }
248}
249
250BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000251 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000252{
253 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000254 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
255 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000256
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400257 auto interest = makeInterest("/localhop/A/1", false, std::nullopt, 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000258 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000259 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600260 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000261 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000262
Junxiao Shi99540072017-01-27 19:57:33 +0000263 BOOST_REQUIRE(this->strategy.waitForAction(
Davide Pesavento0498ce82021-06-14 02:02:21 -0400264 [&] { this->strategy.afterReceiveNack(nack, FaceEndpoint(*this->localFace4, 0), pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000265 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000266
267 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
268 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
269 if (T::canProcessNack()) {
270 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
271 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
272 }
273}
274
275BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
276BOOST_AUTO_TEST_SUITE_END() // Fw
277
278} // namespace tests
279} // namespace fw
280} // namespace nfd