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 | /* |
ashiqopu | 3ad49db | 2018-10-20 22:38:47 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/daemon/face/dummy-face.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 31 | #include "strategy-tester.hpp" |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace fw { |
| 35 | namespace tests { |
| 36 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 37 | using MulticastStrategyTester = StrategyTester<MulticastStrategy>; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 38 | NFD_REGISTER_STRATEGY(MulticastStrategyTester); |
| 39 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 40 | class MulticastStrategyFixture : public GlobalIoTimeFixture |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 41 | { |
| 42 | protected: |
| 43 | MulticastStrategyFixture() |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 44 | : face1(make_shared<DummyFace>()) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 45 | , face2(make_shared<DummyFace>()) |
| 46 | , face3(make_shared<DummyFace>()) |
| 47 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 48 | faceTable.add(face1); |
| 49 | faceTable.add(face2); |
| 50 | faceTable.add(face3); |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 54 | FaceTable faceTable; |
| 55 | Forwarder forwarder{faceTable}; |
| 56 | MulticastStrategyTester strategy{forwarder}; |
| 57 | Fib& fib{forwarder.getFib()}; |
| 58 | Pit& pit{forwarder.getPit()}; |
| 59 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 60 | shared_ptr<DummyFace> face1; |
| 61 | shared_ptr<DummyFace> face2; |
| 62 | shared_ptr<DummyFace> face3; |
| 63 | }; |
| 64 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 65 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 66 | BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture) |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 67 | |
| 68 | BOOST_AUTO_TEST_CASE(Forward2) |
| 69 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 70 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 71 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
| 72 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 73 | fib.addOrUpdateNextHop(fibEntry, *face3, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 74 | |
| 75 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 76 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 77 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 78 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 79 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 81 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 82 | std::set<FaceId> sentInterestFaceIds; |
| 83 | std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(), |
| 84 | std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()), |
| 85 | [] (const MulticastStrategyTester::SendInterestArgs& args) { |
| 86 | return args.outFaceId; |
| 87 | }); |
| 88 | std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()}; |
| 89 | BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(), |
| 90 | expectedInterestFaceIds.begin(), expectedInterestFaceIds.end()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 91 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 92 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
| 93 | MulticastStrategy::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 94 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 95 | // downstream retransmits frequently, but the strategy should not send Interests |
| 96 | // more often than DEFAULT_MIN_RETX_INTERVAL |
| 97 | scheduler::EventId retxFrom4Evt; |
| 98 | size_t nSentLast = strategy.sendInterestHistory.size(); |
| 99 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 100 | std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 101 | periodicalRetxFrom4 = [&] { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 102 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 103 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 104 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 105 | size_t nSent = strategy.sendInterestHistory.size(); |
| 106 | if (nSent > nSentLast) { |
| 107 | // Multicast strategy should multicast the interest to other two faces |
| 108 | BOOST_CHECK_EQUAL(nSent - nSentLast, 2); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 109 | auto timeSent = time::steady_clock::now(); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 110 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
| 111 | nSentLast = nSent; |
| 112 | timeSentLast = timeSent; |
| 113 | } |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 114 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 115 | retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 116 | }; |
| 117 | periodicalRetxFrom4(); |
| 118 | this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 119 | retxFrom4Evt.cancel(); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
| 123 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 124 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 125 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 126 | |
| 127 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 128 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 129 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 130 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 131 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 132 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
| 133 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 136 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy |
| 137 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 138 | |
| 139 | } // namespace tests |
| 140 | } // namespace fw |
| 141 | } // namespace nfd |