Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, 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 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 41 | class MulticastStrategyFixture : public UnitTestTimeFixture |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 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 | |
| 70 | BOOST_AUTO_TEST_CASE(Forward2) |
| 71 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 72 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 73 | fibEntry.addNextHop(*face1, 0); |
| 74 | fibEntry.addNextHop(*face2, 0); |
| 75 | fibEntry.addNextHop(*face3, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 76 | |
| 77 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 78 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 79 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 81 | strategy.afterReceiveInterest(*face3, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 83 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 84 | std::set<FaceId> sentInterestFaceIds; |
| 85 | std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(), |
| 86 | std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()), |
| 87 | [] (const MulticastStrategyTester::SendInterestArgs& args) { |
| 88 | return args.outFaceId; |
| 89 | }); |
| 90 | std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()}; |
| 91 | BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(), |
| 92 | expectedInterestFaceIds.begin(), expectedInterestFaceIds.end()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 93 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 94 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
| 95 | MulticastStrategy::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 96 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 97 | // downstream retransmits frequently, but the strategy should not send Interests |
| 98 | // more often than DEFAULT_MIN_RETX_INTERVAL |
| 99 | scheduler::EventId retxFrom4Evt; |
| 100 | size_t nSentLast = strategy.sendInterestHistory.size(); |
| 101 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 102 | std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 103 | periodicalRetxFrom4 = [&] { |
| 104 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
| 105 | strategy.afterReceiveInterest(*face3, *interest, pitEntry); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 106 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 107 | size_t nSent = strategy.sendInterestHistory.size(); |
| 108 | if (nSent > nSentLast) { |
| 109 | // Multicast strategy should multicast the interest to other two faces |
| 110 | BOOST_CHECK_EQUAL(nSent - nSentLast, 2); |
| 111 | time::steady_clock::TimePoint timeSent = time::steady_clock::now(); |
| 112 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
| 113 | nSentLast = nSent; |
| 114 | timeSentLast = timeSent; |
| 115 | } |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 116 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 117 | retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4); |
| 118 | }; |
| 119 | periodicalRetxFrom4(); |
| 120 | this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16); |
| 121 | scheduler::cancel(retxFrom4Evt); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
| 125 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 126 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 127 | fibEntry.addNextHop(*face1, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 128 | |
| 129 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 130 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 131 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 132 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 133 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 134 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
| 135 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 138 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy |
| 139 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 140 | |
| 141 | } // namespace tests |
| 142 | } // namespace fw |
| 143 | } // namespace nfd |