blob: c97e8abd8b46edaaa5ca7f06d784c2c4f85cb287 [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
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000038#include "choose-strategy.hpp"
Junxiao Shia7f9a292016-11-22 16:31:38 +000039#include "strategy-tester.hpp"
40#include "tests/daemon/face/dummy-face.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060041
Junxiao Shia7f9a292016-11-22 16:31:38 +000042#include <boost/mpl/copy_if.hpp>
43#include <boost/mpl/vector.hpp>
44
45namespace nfd {
46namespace fw {
47namespace tests {
48
49using namespace nfd::tests;
50
51template<typename S>
52class StrategyScopeControlFixture : public UnitTestTimeFixture
53{
54public:
55 StrategyScopeControlFixture()
56 : limitedIo(this)
Junxiao Shie21b3f32016-11-24 14:13:46 +000057 , strategy(choose<StrategyTester<S>>(forwarder))
Junxiao Shia7f9a292016-11-22 16:31:38 +000058 , fib(forwarder.getFib())
59 , pit(forwarder.getPit())
60 , nonLocalFace1(make_shared<DummyFace>("dummy://1", "dummy://1", ndn::nfd::FACE_SCOPE_NON_LOCAL))
61 , nonLocalFace2(make_shared<DummyFace>("dummy://2", "dummy://2", ndn::nfd::FACE_SCOPE_NON_LOCAL))
62 , localFace3(make_shared<DummyFace>("dummy://3", "dummy://3", ndn::nfd::FACE_SCOPE_LOCAL))
63 , localFace4(make_shared<DummyFace>("dummy://4", "dummy://4", ndn::nfd::FACE_SCOPE_LOCAL))
64 {
Junxiao Shia7f9a292016-11-22 16:31:38 +000065 forwarder.addFace(nonLocalFace1);
66 forwarder.addFace(nonLocalFace2);
67 forwarder.addFace(localFace3);
68 forwarder.addFace(localFace4);
69 }
70
Junxiao Shia7f9a292016-11-22 16:31:38 +000071public:
72 LimitedIo limitedIo;
Junxiao Shia7f9a292016-11-22 16:31:38 +000073
74 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
Junxiao Shie21b3f32016-11-24 14:13:46 +000088template<typename S, bool WillSendNackNoRoute, bool CanProcessNack>
89class 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
95 willSendNackNoRoute()
96 {
Junxiao Shie21b3f32016-11-24 14:13:46 +000097 return WillSendNackNoRoute;
Junxiao Shia7f9a292016-11-22 16:31:38 +000098 }
99
100 static bool
101 canProcessNack()
102 {
Junxiao Shie21b3f32016-11-24 14:13:46 +0000103 return CanProcessNack;
Junxiao Shia7f9a292016-11-22 16:31:38 +0000104 }
105};
106
107using Tests = boost::mpl::vector<
Junxiao Shie21b3f32016-11-24 14:13:46 +0000108 Test<AccessStrategy, false, false>,
Ashlesh Gawande2a73f352016-12-01 15:37:03 +0000109 Test<AsfStrategy, true, false>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000110 Test<BestRouteStrategy, false, false>,
111 Test<BestRouteStrategy2, true, true>,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000112 Test<MulticastStrategy, true, true>,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000113 Test<NccStrategy, false, false>
Junxiao Shia7f9a292016-11-22 16:31:38 +0000114>;
115
116BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000117 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000118{
119 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000120 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000121
122 shared_ptr<Interest> interest = makeInterest("/localhost/A/1");
123 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000124 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000125
Junxiao Shi99540072017-01-27 19:57:33 +0000126 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000127 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000128 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000129
130 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1);
131 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
132 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
133}
134
135BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000136 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000137{
138 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000139 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000140
141 shared_ptr<Interest> interest = makeInterest("/localhost/A/1");
142 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000143 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000144
Junxiao Shi99540072017-01-27 19:57:33 +0000145 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000146 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000147 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000148
149 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
150 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
151 if (T::willSendNackNoRoute()) {
152 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
153 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
154 }
155}
156
157BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000158 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000159{
160 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000161 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
162 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000163
164 shared_ptr<Interest> interest = makeInterest("/localhost/A/1");
165 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000166 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000167
Junxiao Shi99540072017-01-27 19:57:33 +0000168 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000169 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->localFace3, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000170 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000171
172 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
173 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
174 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
175 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
176}
177
178BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000179 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000180{
181 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000182 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000183
184 shared_ptr<Interest> interest = makeInterest("/localhop/A/1");
185 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000186 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000187
Junxiao Shi99540072017-01-27 19:57:33 +0000188 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000189 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000190 this->limitedIo, 1 + T::willSendNackNoRoute()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000191
192 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
193 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
194 if (T::willSendNackNoRoute()) {
195 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
196 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
197 }
198}
199
200BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000201 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000202{
203 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000204 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 10);
205 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000206
207 shared_ptr<Interest> interest = makeInterest("/localhop/A/1");
208 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000209 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000210
Junxiao Shi99540072017-01-27 19:57:33 +0000211 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000212 [&] { this->strategy.afterReceiveInterest(FaceEndpoint(*this->nonLocalFace1, 0), *interest, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000213 this->limitedIo));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000214
215 BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1);
216 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId());
217 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
218 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0);
219}
220
221BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000222 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000223{
224 fib::Entry* fibEntry = this->fib.insert("/localhost/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000225 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
226 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000227
228 shared_ptr<Interest> interest = makeInterest("/localhost/A/1", 1460);
229 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000230 pitEntry->insertOrUpdateInRecord(*this->localFace3, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000231 lp::Nack nack = makeNack("/localhost/A/1", 1460, lp::NackReason::NO_ROUTE);
ashiqopud3ae85d2019-02-17 02:29:55 +0000232 pitEntry->insertOrUpdateOutRecord(*this->localFace4, 0, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000233
Junxiao Shi99540072017-01-27 19:57:33 +0000234 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000235 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000236 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000237
238 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
239 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
240 if (T::canProcessNack()) {
241 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
242 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
243 }
244}
245
246BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal,
Junxiao Shie21b3f32016-11-24 14:13:46 +0000247 T, Tests, StrategyScopeControlFixture<typename T::Strategy>)
Junxiao Shia7f9a292016-11-22 16:31:38 +0000248{
249 fib::Entry* fibEntry = this->fib.insert("/localhop/A").first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000250 fibEntry->addOrUpdateNextHop(*this->localFace4, 0, 10);
251 fibEntry->addOrUpdateNextHop(*this->nonLocalFace2, 0, 20);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000252
253 shared_ptr<Interest> interest = makeInterest("/localhop/A/1", 1377);
254 shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000255 pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, 0, *interest);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000256 lp::Nack nack = makeNack("/localhop/A/1", 1377, lp::NackReason::NO_ROUTE);
ashiqopud3ae85d2019-02-17 02:29:55 +0000257 pitEntry->insertOrUpdateOutRecord(*this->localFace4, 0, *interest)->setIncomingNack(nack);
Junxiao Shia7f9a292016-11-22 16:31:38 +0000258
Junxiao Shi99540072017-01-27 19:57:33 +0000259 BOOST_REQUIRE(this->strategy.waitForAction(
ashiqopuc7079482019-02-20 05:34:37 +0000260 [&] { this->strategy.afterReceiveNack(FaceEndpoint(*this->localFace4, 0), nack, pitEntry); },
Junxiao Shi99540072017-01-27 19:57:33 +0000261 this->limitedIo, T::canProcessNack()));
Junxiao Shia7f9a292016-11-22 16:31:38 +0000262
263 BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0);
264 BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0);
265 if (T::canProcessNack()) {
266 BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
267 BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE);
268 }
269}
270
271BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl
272BOOST_AUTO_TEST_SUITE_END() // Fw
273
274} // namespace tests
275} // namespace fw
276} // namespace nfd