blob: a707a4634063e1df0a3ecd0e0b31b58c21f06b9e [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"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070036#include "fw/random-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000037
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038#include "tests/test-common.hpp"
39#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000040#include "choose-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000041#include "strategy-tester.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060042
Junxiao Shia7f9a292016-11-22 16:31:38 +000043#include <boost/mpl/vector.hpp>
44
45namespace nfd {
46namespace fw {
47namespace tests {
48
Junxiao Shia7f9a292016-11-22 16:31:38 +000049template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040050class StrategyScopeControlFixture : public GlobalIoTimeFixture
Junxiao Shia7f9a292016-11-22 16:31:38 +000051{
52public:
53 StrategyScopeControlFixture()
54 : limitedIo(this)
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040055 , forwarder(faceTable)
Junxiao Shie21b3f32016-11-24 14:13:46 +000056 , strategy(choose<StrategyTester<S>>(forwarder))
Junxiao Shia7f9a292016-11-22 16:31:38 +000057 , fib(forwarder.getFib())
58 , pit(forwarder.getPit())
59 , nonLocalFace1(make_shared<DummyFace>("dummy://1", "dummy://1", ndn::nfd::FACE_SCOPE_NON_LOCAL))
60 , nonLocalFace2(make_shared<DummyFace>("dummy://2", "dummy://2", ndn::nfd::FACE_SCOPE_NON_LOCAL))
61 , localFace3(make_shared<DummyFace>("dummy://3", "dummy://3", ndn::nfd::FACE_SCOPE_LOCAL))
62 , localFace4(make_shared<DummyFace>("dummy://4", "dummy://4", ndn::nfd::FACE_SCOPE_LOCAL))
63 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040064 faceTable.add(nonLocalFace1);
65 faceTable.add(nonLocalFace2);
66 faceTable.add(localFace3);
67 faceTable.add(localFace4);
Junxiao Shia7f9a292016-11-22 16:31:38 +000068 }
69
Junxiao Shia7f9a292016-11-22 16:31:38 +000070public:
71 LimitedIo limitedIo;
Junxiao Shia7f9a292016-11-22 16:31:38 +000072
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040073 FaceTable faceTable;
Junxiao Shia7f9a292016-11-22 16:31:38 +000074 Forwarder forwarder;
Junxiao Shie21b3f32016-11-24 14:13:46 +000075 StrategyTester<S>& strategy;
Junxiao Shia7f9a292016-11-22 16:31:38 +000076 Fib& fib;
77 Pit& pit;
78
79 shared_ptr<Face> nonLocalFace1;
80 shared_ptr<Face> nonLocalFace2;
81 shared_ptr<Face> localFace3;
82 shared_ptr<Face> localFace4;
83};
84
85BOOST_AUTO_TEST_SUITE(Fw)
86BOOST_AUTO_TEST_SUITE(TestStrategyScopeControl)
87
Davide Pesavento29abf4c2021-03-05 18:40:01 -050088template<typename S, bool WillSendNackNoRoute, bool CanProcessNack, bool WillRejectPitEntry>
Junxiao Shie21b3f32016-11-24 14:13:46 +000089class Test
Junxiao Shia7f9a292016-11-22 16:31:38 +000090{
91public:
Junxiao Shie21b3f32016-11-24 14:13:46 +000092 using Strategy = S;
Junxiao Shia7f9a292016-11-22 16:31:38 +000093
94 static bool
Alexander Afanasyev4400e422021-02-17 11:17:33 -050095 willRejectPitEntry()
96 {
97 return WillRejectPitEntry;
98 }
99
100 static bool
Junxiao Shia7f9a292016-11-22 16:31:38 +0000101 willSendNackNoRoute()
102 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000103 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000104 }
105
106 static bool
107 canProcessNack()
108 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000109 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000110 }
111};
112
113using Tests = boost::mpl::vector<
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500114 Test<AccessStrategy, false, false, true>,
115 Test<AsfStrategy, true, false, true>,
116 Test<BestRouteStrategy, false, false, true>,
117 Test<BestRouteStrategy2, true, true, true>,
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500118 Test<MulticastStrategy, false, false, false>,
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500119 Test<RandomStrategy, true, true, true>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000120>;
121
122BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000123 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000124{
125 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000126 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000127
Junxiao Shi9d727852019-05-14 13:44:22 -0600128 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000129 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000130 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000131
Junxiao Shi99540072017-01-27 19:57:33 +0000132 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000133 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000134 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000135
136 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
137 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
138 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
139}
140
141BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000142 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000143{
144 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000145 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000146
Junxiao Shi9d727852019-05-14 13:44:22 -0600147 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000148 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000149 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000150
Junxiao Shi99540072017-01-27 19:57:33 +0000151 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000152 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500153 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000154
155 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500156 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000157 if (T::willSendNackNoRoute()) {
158 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
159 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
160 }
161}
162
163BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000164 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000165{
166 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000167 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
168 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000169
Junxiao Shi9d727852019-05-14 13:44:22 -0600170 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000171 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000172 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000173
Junxiao Shi99540072017-01-27 19:57:33 +0000174 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000175 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000176 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000177
178 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
179 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
180 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
181 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
182}
183
184BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000185 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000186{
187 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000188 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000189
Junxiao Shi9d727852019-05-14 13:44:22 -0600190 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000191 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000192 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000193
Junxiao Shi99540072017-01-27 19:57:33 +0000194 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000195 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500196 this->limitedIo, T::willRejectPitEntry() + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000197
198 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
Alexander Afanasyev4400e422021-02-17 11:17:33 -0500199 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), T::willRejectPitEntry());
Junxiao Shia7f9a292016-11-22 16:31:38 +0000200 if (T::willSendNackNoRoute()) {
201 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
202 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
203 }
204}
205
206BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000207 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000208{
209 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000210 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
211 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000212
Junxiao Shi9d727852019-05-14 13:44:22 -0600213 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000214 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000215 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000216
Junxiao Shi99540072017-01-27 19:57:33 +0000217 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000218 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000219 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000220
221 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
222 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
223 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
224 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
225}
226
227BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000228 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000229{
230 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000231 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
232 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000233
Junxiao Shi9d727852019-05-14 13:44:22 -0600234 auto interest = makeInterest("/localhost/A/1", false, nullopt, 1460);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000235 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000236 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600237 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000238 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000239
Junxiao Shi99540072017-01-27 19:57:33 +0000240 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000241 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000242 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000243
244 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
245 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
246 if (T::canProcessNack()) {
247 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
248 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
249 }
250}
251
252BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000253 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000254{
255 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000256 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
257 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000258
Davide Pesavento29abf4c2021-03-05 18:40:01 -0500259 auto interest = makeInterest("/localhop/A/1", false, nullopt, 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000260 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000261 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600262 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000263 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000264
Junxiao Shi99540072017-01-27 19:57:33 +0000265 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000266 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000267 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000268
269 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
270 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
271 if (T::canProcessNack()) {
272 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
273 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
274 }
275}
276
277BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
278BOOST_AUTO_TEST_SUITE_END() // Fw
279
280} // namespace tests
281} // namespace fw
282} // namespace nfd