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 | /* |
Ashlesh Gawande | c1d4837 | 2020-08-02 22:30:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, 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" |
Ashlesh Gawande | c1d4837 | 2020-08-02 22:30:11 -0700 | [diff] [blame^] | 32 | #include "topology-tester.hpp" |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace fw { |
| 36 | namespace tests { |
| 37 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 38 | using MulticastStrategyTester = StrategyTester<MulticastStrategy>; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 39 | NFD_REGISTER_STRATEGY(MulticastStrategyTester); |
| 40 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 41 | class MulticastStrategyFixture : public GlobalIoTimeFixture |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 42 | { |
| 43 | protected: |
| 44 | MulticastStrategyFixture() |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 45 | : face1(make_shared<DummyFace>()) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 46 | , face2(make_shared<DummyFace>()) |
| 47 | , face3(make_shared<DummyFace>()) |
| 48 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 49 | faceTable.add(face1); |
| 50 | faceTable.add(face2); |
| 51 | faceTable.add(face3); |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 55 | FaceTable faceTable; |
| 56 | Forwarder forwarder{faceTable}; |
| 57 | MulticastStrategyTester strategy{forwarder}; |
| 58 | Fib& fib{forwarder.getFib()}; |
| 59 | Pit& pit{forwarder.getPit()}; |
| 60 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 61 | shared_ptr<DummyFace> face1; |
| 62 | shared_ptr<DummyFace> face2; |
| 63 | shared_ptr<DummyFace> face3; |
| 64 | }; |
| 65 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 66 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 67 | BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture) |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 68 | |
Ashlesh Gawande | c1d4837 | 2020-08-02 22:30:11 -0700 | [diff] [blame^] | 69 | BOOST_AUTO_TEST_CASE(Bug5123) |
| 70 | { |
| 71 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 72 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 73 | |
| 74 | // Send an Interest from face 1 to face 2 |
| 75 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
| 76 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 77 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 78 | |
| 79 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
| 80 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 81 | |
| 82 | // Advance more than default suppression |
| 83 | this->advanceClocks(15_ms); |
| 84 | |
| 85 | // Get same interest from face 2 which does not have anywhere to go |
| 86 | pitEntry = pit.insert(*interest).first; |
| 87 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
| 88 | |
| 89 | strategy.afterReceiveInterest(FaceEndpoint(*face2, 0), *interest, pitEntry); |
| 90 | // Since the interest is same as the one sent out by face 1 pit should not be rejected |
| 91 | // as any data coming back should be able to satisfy original interest from face 1 |
| 92 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 93 | |
| 94 | /* |
| 95 | * +---------+ +---------+ +---------+ |
| 96 | * | nodeA |------------| nodeB |----------| nodeC | |
| 97 | * +---------+ 10ms +---------+ 100ms +---------+ |
| 98 | */ |
| 99 | |
| 100 | const Name PRODUCER_PREFIX = "/ndn/edu/nodeC/ping"; |
| 101 | |
| 102 | TopologyTester topo; |
| 103 | TopologyNode nodeA = topo.addForwarder("A"), |
| 104 | nodeB = topo.addForwarder("B"), |
| 105 | nodeC = topo.addForwarder("C"); |
| 106 | |
| 107 | for (TopologyNode node : {nodeA, nodeB, nodeC}) { |
| 108 | topo.setStrategy<MulticastStrategy>(node); |
| 109 | } |
| 110 | |
| 111 | shared_ptr<TopologyLink> linkAB = topo.addLink("AB", 10_ms, {nodeA, nodeB}), |
| 112 | linkBC = topo.addLink("BC", 100_ms, {nodeB, nodeC}); |
| 113 | |
| 114 | shared_ptr<TopologyAppLink> appA = topo.addAppFace("cA", nodeA), |
| 115 | appB = topo.addAppFace("cB", nodeB), |
| 116 | pingServer = topo.addAppFace("p", nodeC, PRODUCER_PREFIX); |
| 117 | topo.addEchoProducer(pingServer->getClientFace()); |
| 118 | topo.registerPrefix(nodeA, linkAB->getFace(nodeA), PRODUCER_PREFIX, 10); |
| 119 | topo.registerPrefix(nodeB, linkAB->getFace(nodeB), PRODUCER_PREFIX, 10); |
| 120 | topo.registerPrefix(nodeB, linkBC->getFace(nodeB), PRODUCER_PREFIX, 100); |
| 121 | |
| 122 | Name name(PRODUCER_PREFIX); |
| 123 | name.appendTimestamp(); |
| 124 | interest = makeInterest(name); |
| 125 | appA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr); |
| 126 | |
| 127 | this->advanceClocks(10_ms, 20_ms); |
| 128 | |
| 129 | // AppB expresses the same interest |
| 130 | interest->refreshNonce(); |
| 131 | appB->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr); |
| 132 | this->advanceClocks(10_ms, 200_ms); |
| 133 | |
| 134 | // Data should have made to appB |
| 135 | BOOST_CHECK_EQUAL(linkBC->getFace(nodeB).getCounters().nInData, 1); |
| 136 | BOOST_CHECK_EQUAL(linkAB->getFace(nodeA).getCounters().nInData, 0); |
| 137 | |
| 138 | this->advanceClocks(10_ms, 10_ms); |
| 139 | // nodeA should have gotten the data successfully |
| 140 | BOOST_CHECK_EQUAL(linkAB->getFace(nodeA).getCounters().nInData, 1); |
| 141 | BOOST_CHECK_EQUAL(topo.getForwarder(nodeA).getCounters().nUnsolicitedData, 0); |
| 142 | } |
| 143 | |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 144 | BOOST_AUTO_TEST_CASE(Forward2) |
| 145 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 146 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 147 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
| 148 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 149 | fib.addOrUpdateNextHop(fibEntry, *face3, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 150 | |
| 151 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 152 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 153 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 154 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 155 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 157 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 158 | std::set<FaceId> sentInterestFaceIds; |
| 159 | std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(), |
| 160 | std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()), |
| 161 | [] (const MulticastStrategyTester::SendInterestArgs& args) { |
| 162 | return args.outFaceId; |
| 163 | }); |
| 164 | std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()}; |
| 165 | BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(), |
| 166 | expectedInterestFaceIds.begin(), expectedInterestFaceIds.end()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 167 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 168 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
| 169 | MulticastStrategy::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 170 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 171 | // downstream retransmits frequently, but the strategy should not send Interests |
| 172 | // more often than DEFAULT_MIN_RETX_INTERVAL |
| 173 | scheduler::EventId retxFrom4Evt; |
| 174 | size_t nSentLast = strategy.sendInterestHistory.size(); |
| 175 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 176 | std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 177 | periodicalRetxFrom4 = [&] { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 178 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 179 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 180 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 181 | size_t nSent = strategy.sendInterestHistory.size(); |
| 182 | if (nSent > nSentLast) { |
| 183 | // Multicast strategy should multicast the interest to other two faces |
| 184 | BOOST_CHECK_EQUAL(nSent - nSentLast, 2); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 185 | auto timeSent = time::steady_clock::now(); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 186 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
| 187 | nSentLast = nSent; |
| 188 | timeSentLast = timeSent; |
| 189 | } |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 190 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 191 | retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 192 | }; |
| 193 | periodicalRetxFrom4(); |
| 194 | this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 195 | retxFrom4Evt.cancel(); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
| 199 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 200 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 201 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 202 | |
| 203 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 204 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 205 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 206 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 207 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
| 209 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 212 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy |
| 213 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 214 | |
| 215 | } // namespace tests |
| 216 | } // namespace fw |
| 217 | } // namespace nfd |