Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [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 | #include "fw/multicast-strategy.hpp" |
| 27 | #include "strategy-tester.hpp" |
| 28 | #include "tests/daemon/face/dummy-face.hpp" |
| 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace fw { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
| 37 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 38 | typedef StrategyTester<MulticastStrategy> MulticastStrategyTester; |
| 39 | NFD_REGISTER_STRATEGY(MulticastStrategyTester); |
| 40 | |
| 41 | class MulticastStrategyFixture : public BaseFixture |
| 42 | { |
| 43 | protected: |
| 44 | MulticastStrategyFixture() |
| 45 | : strategy(forwarder) |
| 46 | , fib(forwarder.getFib()) |
| 47 | , pit(forwarder.getPit()) |
| 48 | , face1(make_shared<DummyFace>()) |
| 49 | , face2(make_shared<DummyFace>()) |
| 50 | , face3(make_shared<DummyFace>()) |
| 51 | { |
| 52 | forwarder.addFace(face1); |
| 53 | forwarder.addFace(face2); |
| 54 | forwarder.addFace(face3); |
| 55 | } |
| 56 | |
| 57 | protected: |
| 58 | Forwarder forwarder; |
| 59 | MulticastStrategyTester strategy; |
| 60 | Fib& fib; |
| 61 | Pit& pit; |
| 62 | shared_ptr<DummyFace> face1; |
| 63 | shared_ptr<DummyFace> face2; |
| 64 | shared_ptr<DummyFace> face3; |
| 65 | }; |
| 66 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 67 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 68 | BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture) |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 70 | BOOST_AUTO_TEST_CASE(Registration) |
| 71 | { |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(Strategy::listRegistered().count(MulticastStrategy::getStrategyName()), 1); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 75 | BOOST_AUTO_TEST_CASE(InstanceName) |
| 76 | { |
| 77 | Forwarder forwarder; |
| 78 | BOOST_REQUIRE(MulticastStrategy::getStrategyName().at(-1).isVersion()); |
| 79 | BOOST_CHECK_EQUAL( |
| 80 | MulticastStrategy(forwarder, MulticastStrategy::getStrategyName().getPrefix(-1)).getInstanceName(), |
| 81 | MulticastStrategy::getStrategyName()); |
| 82 | BOOST_CHECK_THROW( |
| 83 | MulticastStrategy(forwarder, Name(MulticastStrategy::getStrategyName()).append("param")), |
| 84 | std::invalid_argument); |
| 85 | } |
| 86 | |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 87 | BOOST_AUTO_TEST_CASE(Forward2) |
| 88 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 89 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 90 | fibEntry.addNextHop(*face1, 0); |
| 91 | fibEntry.addNextHop(*face2, 0); |
| 92 | fibEntry.addNextHop(*face3, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 93 | |
| 94 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 95 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 96 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 98 | strategy.afterReceiveInterest(*face3, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 100 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 101 | std::set<FaceId> sentInterestFaceIds; |
| 102 | std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(), |
| 103 | std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()), |
| 104 | [] (const MulticastStrategyTester::SendInterestArgs& args) { |
| 105 | return args.outFaceId; |
| 106 | }); |
| 107 | std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()}; |
| 108 | BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(), |
| 109 | expectedInterestFaceIds.begin(), expectedInterestFaceIds.end()); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | BOOST_AUTO_TEST_CASE(RejectScope) |
| 113 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 114 | fib::Entry& fibEntry = *fib.insert("ndn:/localhop/uS09bub6tm").first; |
| 115 | fibEntry.addNextHop(*face2, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 116 | |
| 117 | shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 118 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 119 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 120 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 121 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
| 123 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
| 127 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 128 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 129 | fibEntry.addNextHop(*face1, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 130 | |
| 131 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 132 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 133 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 134 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 135 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 136 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
| 137 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 140 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy |
| 141 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 142 | |
| 143 | } // namespace tests |
| 144 | } // namespace fw |
| 145 | } // namespace nfd |