blob: 268ae67e122ba4f2d0692f2e62845622ccf2f3b5 [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/*
3 * Copyright (c) 2014-2019, 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
Junxiao Shie21b3f32016-11-24 14:13:46 +000090template<typename S, bool WillSendNackNoRoute, bool CanProcessNack>
91class 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
97 willSendNackNoRoute()
98 {
Junxiao Shie21b3f32016-11-24 14:13:46 +000099 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000100 }
101
102 static bool
103 canProcessNack()
104 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000105 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000106 }
107};
108
109using Tests = boost::mpl::vector<
Junxiao Shie21b3f32016-11-24 14:13:46 +0000110 Test<AccessStrategy, false, false>,
Ashlesh Gawande2a73f352016-12-01 15:37:03 +0000111 Test<AsfStrategy, true, false>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000112 Test<BestRouteStrategy, false, false>,
113 Test<BestRouteStrategy2, true, true>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000114 Test<MulticastStrategy, true, true>,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -0700115 Test<NccStrategy, false, false>,
116 Test<RandomStrategy, true, true>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000117>;
118
119BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000120 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000121{
122 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000123 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000124
Junxiao Shi9d727852019-05-14 13:44:22 -0600125 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000126 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000127 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000128
Junxiao Shi99540072017-01-27 19:57:33 +0000129 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000130 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000131 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000132
133 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
134 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
135 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
136}
137
138BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000139 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000140{
141 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000142 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000143
Junxiao Shi9d727852019-05-14 13:44:22 -0600144 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000145 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000146 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000147
Junxiao Shi99540072017-01-27 19:57:33 +0000148 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000149 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000150 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000151
152 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
153 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
154 if (T::willSendNackNoRoute()) {
155 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
156 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
157 }
158}
159
160BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000161 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000162{
163 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000164 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
165 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000166
Junxiao Shi9d727852019-05-14 13:44:22 -0600167 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000168 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000169 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000170
Junxiao Shi99540072017-01-27 19:57:33 +0000171 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000172 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000173 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000174
175 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
176 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
177 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
178 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
179}
180
181BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000182 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000183{
184 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000185 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000186
Junxiao Shi9d727852019-05-14 13:44:22 -0600187 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000188 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000189 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000190
Junxiao Shi99540072017-01-27 19:57:33 +0000191 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000192 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000193 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000194
195 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
196 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
197 if (T::willSendNackNoRoute()) {
198 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
199 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
200 }
201}
202
203BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000204 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000205{
206 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000207 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 10);
208 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000209
Junxiao Shi9d727852019-05-14 13:44:22 -0600210 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000211 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000212 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000213
Junxiao Shi99540072017-01-27 19:57:33 +0000214 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000215 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000216 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000217
218 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
219 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
220 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
221 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
222}
223
224BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000225 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000226{
227 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000228 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
229 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000230
Junxiao Shi9d727852019-05-14 13:44:22 -0600231 auto interest = makeInterest("/localhost/A/1", false, nullopt, 1460);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000232 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000233 pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600234 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000235 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000236
Junxiao Shi99540072017-01-27 19:57:33 +0000237 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000238 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000239 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000240
241 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
242 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
243 if (T::canProcessNack()) {
244 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
245 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
246 }
247}
248
249BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000250 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000251{
252 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
Ju Pand8315bf2019-07-31 06:59:07 +0000253 this->fib.addOrUpdateNextHop(*fibEntry, *this->localFace4, 10);
254 this->fib.addOrUpdateNextHop(*fibEntry, *this->nonLocalFace2, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000255
Junxiao Shi9d727852019-05-14 13:44:22 -0600256 auto interest = makeInterest("/localhop/A/1", 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000257 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000258 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600259 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000260 pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000261
Junxiao Shi99540072017-01-27 19:57:33 +0000262 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000263 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000264 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000265
266 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
267 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
268 if (T::canProcessNack()) {
269 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
270 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
271 }
272}
273
274BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
275BOOST_AUTO_TEST_SUITE_END() // Fw
276
277} // namespace tests
278} // namespace fw
279} // namespace nfd