Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 4 | * 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 Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 32 | #include "fw/asf-strategy.hpp" |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 33 | #include "fw/best-route-strategy.hpp" |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 34 | #include "fw/best-route-strategy2.hpp" |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 35 | #include "fw/multicast-strategy.hpp" |
| 36 | #include "fw/ncc-strategy.hpp" |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 37 | |
| 38 | #include "tests/test-common.hpp" |
| 39 | #include "tests/limited-io.hpp" |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 40 | #include "choose-strategy.hpp" |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 41 | #include "strategy-tester.hpp" |
| 42 | #include "tests/daemon/face/dummy-face.hpp" |
| 43 | #include <boost/mpl/copy_if.hpp> |
| 44 | #include <boost/mpl/vector.hpp> |
| 45 | |
| 46 | namespace nfd { |
| 47 | namespace fw { |
| 48 | namespace tests { |
| 49 | |
| 50 | using namespace nfd::tests; |
| 51 | |
| 52 | template<typename S> |
| 53 | class StrategyScopeControlFixture : public UnitTestTimeFixture |
| 54 | { |
| 55 | public: |
| 56 | StrategyScopeControlFixture() |
| 57 | : limitedIo(this) |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 58 | , strategy(choose<StrategyTester<S>>(forwarder)) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 59 | , 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 | { |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 66 | forwarder.addFace(nonLocalFace1); |
| 67 | forwarder.addFace(nonLocalFace2); |
| 68 | forwarder.addFace(localFace3); |
| 69 | forwarder.addFace(localFace4); |
| 70 | } |
| 71 | |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 72 | public: |
| 73 | LimitedIo limitedIo; |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 74 | |
| 75 | Forwarder forwarder; |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 76 | StrategyTester<S>& strategy; |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 77 | Fib& fib; |
| 78 | Pit& pit; |
| 79 | |
| 80 | shared_ptr<Face> nonLocalFace1; |
| 81 | shared_ptr<Face> nonLocalFace2; |
| 82 | shared_ptr<Face> localFace3; |
| 83 | shared_ptr<Face> localFace4; |
| 84 | }; |
| 85 | |
| 86 | BOOST_AUTO_TEST_SUITE(Fw) |
| 87 | BOOST_AUTO_TEST_SUITE(TestStrategyScopeControl) |
| 88 | |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 89 | template<typename S, bool WillSendNackNoRoute, bool CanProcessNack> |
| 90 | class Test |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 91 | { |
| 92 | public: |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 93 | using Strategy = S; |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 94 | |
| 95 | static bool |
| 96 | willSendNackNoRoute() |
| 97 | { |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 98 | return WillSendNackNoRoute; |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static bool |
| 102 | canProcessNack() |
| 103 | { |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 104 | return CanProcessNack; |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 105 | } |
| 106 | }; |
| 107 | |
| 108 | using Tests = boost::mpl::vector< |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 109 | Test<AccessStrategy, false, false>, |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 110 | Test<AsfStrategy, true, false>, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 111 | Test<BestRouteStrategy, false, false>, |
| 112 | Test<BestRouteStrategy2, true, true>, |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 113 | Test<MulticastStrategy, true, true>, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 114 | Test<NccStrategy, false, false> |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 115 | >; |
| 116 | |
| 117 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 118 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 119 | { |
| 120 | fib::Entry* fibEntry = this->fib.insert("/localhost/A").first; |
| 121 | fibEntry->addNextHop(*this->localFace4, 10); |
| 122 | |
| 123 | shared_ptr<Interest> interest = makeInterest("/localhost/A/1"); |
| 124 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 125 | pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest); |
| 126 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 127 | BOOST_REQUIRE(this->strategy.waitForAction( |
| 128 | [&] { this->strategy.afterReceiveInterest(*this->localFace3, *interest, pitEntry); }, |
| 129 | this->limitedIo)); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 130 | |
| 131 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 1); |
| 132 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0); |
| 133 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0); |
| 134 | } |
| 135 | |
| 136 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToNonLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 137 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 138 | { |
| 139 | fib::Entry* fibEntry = this->fib.insert("/localhost/A").first; |
| 140 | fibEntry->addNextHop(*this->nonLocalFace2, 10); |
| 141 | |
| 142 | shared_ptr<Interest> interest = makeInterest("/localhost/A/1"); |
| 143 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 144 | pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest); |
| 145 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 146 | BOOST_REQUIRE(this->strategy.waitForAction( |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 147 | [&] { this->strategy.afterReceiveInterest(*this->localFace3, *interest, pitEntry); }, |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 148 | this->limitedIo, 1 + T::willSendNackNoRoute())); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 149 | |
| 150 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0); |
| 151 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
| 152 | if (T::willSendNackNoRoute()) { |
| 153 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 154 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostInterestToLocalAndNonLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 159 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 160 | { |
| 161 | fib::Entry* fibEntry = this->fib.insert("/localhost/A").first; |
| 162 | fibEntry->addNextHop(*this->nonLocalFace2, 10); |
| 163 | fibEntry->addNextHop(*this->localFace4, 20); |
| 164 | |
| 165 | shared_ptr<Interest> interest = makeInterest("/localhost/A/1"); |
| 166 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 167 | pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest); |
| 168 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 169 | BOOST_REQUIRE(this->strategy.waitForAction( |
| 170 | [&] { this->strategy.afterReceiveInterest(*this->localFace3, *interest, pitEntry); }, |
| 171 | this->limitedIo)); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 172 | |
| 173 | BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1); |
| 174 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId()); |
| 175 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0); |
| 176 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0); |
| 177 | } |
| 178 | |
| 179 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 180 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 181 | { |
| 182 | fib::Entry* fibEntry = this->fib.insert("/localhop/A").first; |
| 183 | fibEntry->addNextHop(*this->nonLocalFace2, 10); |
| 184 | |
| 185 | shared_ptr<Interest> interest = makeInterest("/localhop/A/1"); |
| 186 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 187 | pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest); |
| 188 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 189 | BOOST_REQUIRE(this->strategy.waitForAction( |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 190 | [&] { this->strategy.afterReceiveInterest(*this->nonLocalFace1, *interest, pitEntry); }, |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 191 | this->limitedIo, 1 + T::willSendNackNoRoute())); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 192 | |
| 193 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0); |
| 194 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1); |
| 195 | if (T::willSendNackNoRoute()) { |
| 196 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 197 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopInterestToNonLocalAndLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 202 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 203 | { |
| 204 | fib::Entry* fibEntry = this->fib.insert("/localhop/A").first; |
| 205 | fibEntry->addNextHop(*this->nonLocalFace2, 10); |
| 206 | fibEntry->addNextHop(*this->localFace4, 20); |
| 207 | |
| 208 | shared_ptr<Interest> interest = makeInterest("/localhop/A/1"); |
| 209 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 210 | pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest); |
| 211 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 212 | BOOST_REQUIRE(this->strategy.waitForAction( |
| 213 | [&] { this->strategy.afterReceiveInterest(*this->nonLocalFace1, *interest, pitEntry); }, |
| 214 | this->limitedIo)); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 215 | |
| 216 | BOOST_REQUIRE_EQUAL(this->strategy.sendInterestHistory.size(), 1); |
| 217 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.back().outFaceId, this->localFace4->getId()); |
| 218 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0); |
| 219 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.size(), 0); |
| 220 | } |
| 221 | |
| 222 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhostNackToNonLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 223 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 224 | { |
| 225 | fib::Entry* fibEntry = this->fib.insert("/localhost/A").first; |
| 226 | fibEntry->addNextHop(*this->localFace4, 10); |
| 227 | fibEntry->addNextHop(*this->nonLocalFace2, 20); |
| 228 | |
| 229 | shared_ptr<Interest> interest = makeInterest("/localhost/A/1", 1460); |
| 230 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 231 | pitEntry->insertOrUpdateInRecord(*this->localFace3, *interest); |
| 232 | lp::Nack nack = makeNack("/localhost/A/1", 1460, lp::NackReason::NO_ROUTE); |
| 233 | pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack); |
| 234 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 235 | BOOST_REQUIRE(this->strategy.waitForAction( |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 236 | [&] { this->strategy.afterReceiveNack(*this->localFace4, nack, pitEntry); }, |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 237 | this->limitedIo, T::canProcessNack())); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 238 | |
| 239 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0); |
| 240 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0); |
| 241 | if (T::canProcessNack()) { |
| 242 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 243 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalhopNackToNonLocal, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 248 | T, Tests, StrategyScopeControlFixture<typename T::Strategy>) |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 249 | { |
| 250 | fib::Entry* fibEntry = this->fib.insert("/localhop/A").first; |
| 251 | fibEntry->addNextHop(*this->localFace4, 10); |
| 252 | fibEntry->addNextHop(*this->nonLocalFace2, 20); |
| 253 | |
| 254 | shared_ptr<Interest> interest = makeInterest("/localhop/A/1", 1377); |
| 255 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 256 | pitEntry->insertOrUpdateInRecord(*this->nonLocalFace1, *interest); |
| 257 | lp::Nack nack = makeNack("/localhop/A/1", 1377, lp::NackReason::NO_ROUTE); |
| 258 | pitEntry->insertOrUpdateOutRecord(*this->localFace4, *interest)->setIncomingNack(nack); |
| 259 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 260 | BOOST_REQUIRE(this->strategy.waitForAction( |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 261 | [&] { this->strategy.afterReceiveNack(*this->localFace4, nack, pitEntry); }, |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 262 | this->limitedIo, T::canProcessNack())); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 263 | |
| 264 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), 0); |
| 265 | BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 0); |
| 266 | if (T::canProcessNack()) { |
| 267 | BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1); |
| 268 | BOOST_CHECK_EQUAL(this->strategy.sendNackHistory.back().header.getReason(), lp::NackReason::NO_ROUTE); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyScopeControl |
| 273 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 274 | |
| 275 | } // namespace tests |
| 276 | } // namespace fw |
| 277 | } // namespace nfd |