blob: 021415252689beb4cbbd53c112daa598e71b4d2f [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"
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/copy_if.hpp>
44#include <boost/mpl/vector.hpp>
45
46namespace nfd {
47namespace fw {
48namespace tests {
49
Junxiao Shia7f9a292016-11-22 16:31:38 +000050template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040051class StrategyScopeControlFixture : public GlobalIoTimeFixture
Junxiao Shia7f9a292016-11-22 16:31:38 +000052{
53public:
54 StrategyScopeControlFixture()
55 : limitedIo(this)
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 {
Junxiao Shia7f9a292016-11-22 16:31:38 +000064 forwarder.addFace(nonLocalFace1);
65 forwarder.addFace(nonLocalFace2);
66 forwarder.addFace(localFace3);
67 forwarder.addFace(localFace4);
68 }
69
Junxiao Shia7f9a292016-11-22 16:31:38 +000070public:
71 LimitedIo limitedIo;
Junxiao Shia7f9a292016-11-22 16:31:38 +000072
73 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
Junxiao Shie21b3f32016-11-24 14:13:46 +000087template<typename S, bool WillSendNackNoRoute, bool CanProcessNack>
88class 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
94 willSendNackNoRoute()
95 {
Junxiao Shie21b3f32016-11-24 14:13:46 +000096 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +000097 }
98
99 static bool
100 canProcessNack()
101 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000102 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000103 }
104};
105
106using Tests = boost::mpl::vector<
Junxiao Shie21b3f32016-11-24 14:13:46 +0000107 Test<AccessStrategy, false, false>,
Ashlesh Gawande2a73f352016-12-01 15:37:03 +0000108 Test<AsfStrategy, true, false>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000109 Test<BestRouteStrategy, false, false>,
110 Test<BestRouteStrategy2, true, true>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000111 Test<MulticastStrategy, true, true>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000112 Test<NccStrategy, false, false>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000113>;
114
115BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000116 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000117{
118 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000119 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000120
Junxiao Shi9d727852019-05-14 13:44:22 -0600121 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000122 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000123 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000124
Junxiao Shi99540072017-01-27 19:57:33 +0000125 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000126 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000127 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000128
129 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
130 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
131 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
132}
133
134BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000135 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000136{
137 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000138 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000139
Junxiao Shi9d727852019-05-14 13:44:22 -0600140 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000141 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000142 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000143
Junxiao Shi99540072017-01-27 19:57:33 +0000144 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000145 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000146 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000147
148 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
149 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
150 if (T::willSendNackNoRoute()) {
151 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
152 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
153 }
154}
155
156BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000157 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000158{
159 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000160 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
161 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000162
Junxiao Shi9d727852019-05-14 13:44:22 -0600163 auto interest = makeInterest("/localhost/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000164 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000165 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000166
Junxiao Shi99540072017-01-27 19:57:33 +0000167 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000168 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000169 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000170
171 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
172 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
173 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
174 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
175}
176
177BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000178 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000179{
180 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000181 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000182
Junxiao Shi9d727852019-05-14 13:44:22 -0600183 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000184 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000185 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000186
Junxiao Shi99540072017-01-27 19:57:33 +0000187 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000188 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000189 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000190
191 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
192 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
193 if (T::willSendNackNoRoute()) {
194 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
195 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
196 }
197}
198
199BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000200 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000201{
202 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000203 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
204 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000205
Junxiao Shi9d727852019-05-14 13:44:22 -0600206 auto interest = makeInterest("/localhop/A/1");
Junxiao Shia7f9a292016-11-22 16:31:38 +0000207 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000208 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000209
Junxiao Shi99540072017-01-27 19:57:33 +0000210 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000211 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000212 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000213
214 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
215 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
216 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
217 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
218}
219
220BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000221 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000222{
223 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000224 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
225 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000226
Junxiao Shi9d727852019-05-14 13:44:22 -0600227 auto interest = makeInterest("/localhost/A/1", false, nullopt, 1460);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000228 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000229 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600230 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
ashiqopud3ae85d2019-02-17 02:29:55 +0000231 pitEntry->insertOrUpdateOutRecord(*this->localFace4, 0, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000232
Junxiao Shi99540072017-01-27 19:57:33 +0000233 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000234 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000235 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000236
237 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
238 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
239 if (T::canProcessNack()) {
240 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
241 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
242 }
243}
244
245BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000246 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000247{
248 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000249 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
250 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000251
Junxiao Shi9d727852019-05-14 13:44:22 -0600252 auto interest = makeInterest("/localhop/A/1", 1377);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000253 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000254 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shi9d727852019-05-14 13:44:22 -0600255 lp::Nack nack = makeNack(*interest, lp::NackReason::NO_ROUTE);
ashiqopud3ae85d2019-02-17 02:29:55 +0000256 pitEntry->insertOrUpdateOutRecord(*this->localFace4, 0, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000257
Junxiao Shi99540072017-01-27 19:57:33 +0000258 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000259 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000260 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000261
262 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
263 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
264 if (T::canProcessNack()) {
265 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
266 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
267 }
268}
269
270BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
271BOOST_AUTO_TEST_SUITE_END() // Fw
272
273} // namespace tests
274} // namespace fw
275} // namespace nfd