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 | /* |
Alexander Afanasyev | 4400e42 | 2021-02-17 11:17:33 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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" |
Alexander Afanasyev | 40604e3 | 2021-02-17 12:06:26 -0500 | [diff] [blame] | 31 | #include "choose-strategy.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 32 | #include "strategy-tester.hpp" |
Ashlesh Gawande | c1d4837 | 2020-08-02 22:30:11 -0700 | [diff] [blame] | 33 | #include "topology-tester.hpp" |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
| 36 | namespace fw { |
| 37 | namespace tests { |
| 38 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 39 | using MulticastStrategyTester = StrategyTester<MulticastStrategy>; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 40 | NFD_REGISTER_STRATEGY(MulticastStrategyTester); |
| 41 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 42 | class MulticastStrategyFixture : public GlobalIoTimeFixture |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 43 | { |
| 44 | protected: |
| 45 | MulticastStrategyFixture() |
Alexander Afanasyev | 40604e3 | 2021-02-17 12:06:26 -0500 | [diff] [blame] | 46 | : strategy(choose<MulticastStrategyTester>(forwarder)) |
| 47 | , face1(make_shared<DummyFace>()) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 48 | , face2(make_shared<DummyFace>()) |
| 49 | , face3(make_shared<DummyFace>()) |
| 50 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 51 | faceTable.add(face1); |
| 52 | faceTable.add(face2); |
| 53 | faceTable.add(face3); |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 57 | FaceTable faceTable; |
| 58 | Forwarder forwarder{faceTable}; |
Alexander Afanasyev | 40604e3 | 2021-02-17 12:06:26 -0500 | [diff] [blame] | 59 | MulticastStrategyTester& strategy; |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 60 | Fib& fib{forwarder.getFib()}; |
| 61 | Pit& pit{forwarder.getPit()}; |
| 62 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 63 | shared_ptr<DummyFace> face1; |
| 64 | shared_ptr<DummyFace> face2; |
| 65 | shared_ptr<DummyFace> face3; |
| 66 | }; |
| 67 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 68 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 69 | BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture) |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 70 | |
Ashlesh Gawande | c1d4837 | 2020-08-02 22:30:11 -0700 | [diff] [blame] | 71 | BOOST_AUTO_TEST_CASE(Bug5123) |
| 72 | { |
| 73 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 74 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 75 | |
| 76 | // Send an Interest from face 1 to face 2 |
| 77 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
| 78 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 79 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 80 | |
| 81 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
| 82 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 83 | |
| 84 | // Advance more than default suppression |
| 85 | this->advanceClocks(15_ms); |
| 86 | |
| 87 | // Get same interest from face 2 which does not have anywhere to go |
| 88 | pitEntry = pit.insert(*interest).first; |
| 89 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
| 90 | |
| 91 | strategy.afterReceiveInterest(FaceEndpoint(*face2, 0), *interest, pitEntry); |
| 92 | // Since the interest is same as the one sent out by face 1 pit should not be rejected |
| 93 | // as any data coming back should be able to satisfy original interest from face 1 |
| 94 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 95 | |
| 96 | /* |
| 97 | * +---------+ +---------+ +---------+ |
| 98 | * | nodeA |------------| nodeB |----------| nodeC | |
| 99 | * +---------+ 10ms +---------+ 100ms +---------+ |
| 100 | */ |
| 101 | |
| 102 | const Name PRODUCER_PREFIX = "/ndn/edu/nodeC/ping"; |
| 103 | |
| 104 | TopologyTester topo; |
| 105 | TopologyNode nodeA = topo.addForwarder("A"), |
| 106 | nodeB = topo.addForwarder("B"), |
| 107 | nodeC = topo.addForwarder("C"); |
| 108 | |
| 109 | for (TopologyNode node : {nodeA, nodeB, nodeC}) { |
| 110 | topo.setStrategy<MulticastStrategy>(node); |
| 111 | } |
| 112 | |
| 113 | shared_ptr<TopologyLink> linkAB = topo.addLink("AB", 10_ms, {nodeA, nodeB}), |
| 114 | linkBC = topo.addLink("BC", 100_ms, {nodeB, nodeC}); |
| 115 | |
| 116 | shared_ptr<TopologyAppLink> appA = topo.addAppFace("cA", nodeA), |
| 117 | appB = topo.addAppFace("cB", nodeB), |
| 118 | pingServer = topo.addAppFace("p", nodeC, PRODUCER_PREFIX); |
| 119 | topo.addEchoProducer(pingServer->getClientFace()); |
| 120 | topo.registerPrefix(nodeA, linkAB->getFace(nodeA), PRODUCER_PREFIX, 10); |
| 121 | topo.registerPrefix(nodeB, linkAB->getFace(nodeB), PRODUCER_PREFIX, 10); |
| 122 | topo.registerPrefix(nodeB, linkBC->getFace(nodeB), PRODUCER_PREFIX, 100); |
| 123 | |
| 124 | Name name(PRODUCER_PREFIX); |
| 125 | name.appendTimestamp(); |
| 126 | interest = makeInterest(name); |
| 127 | appA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr); |
| 128 | |
| 129 | this->advanceClocks(10_ms, 20_ms); |
| 130 | |
| 131 | // AppB expresses the same interest |
| 132 | interest->refreshNonce(); |
| 133 | appB->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr); |
| 134 | this->advanceClocks(10_ms, 200_ms); |
| 135 | |
| 136 | // Data should have made to appB |
| 137 | BOOST_CHECK_EQUAL(linkBC->getFace(nodeB).getCounters().nInData, 1); |
| 138 | BOOST_CHECK_EQUAL(linkAB->getFace(nodeA).getCounters().nInData, 0); |
| 139 | |
| 140 | this->advanceClocks(10_ms, 10_ms); |
| 141 | // nodeA should have gotten the data successfully |
| 142 | BOOST_CHECK_EQUAL(linkAB->getFace(nodeA).getCounters().nInData, 1); |
| 143 | BOOST_CHECK_EQUAL(topo.getForwarder(nodeA).getCounters().nUnsolicitedData, 0); |
| 144 | } |
| 145 | |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 146 | BOOST_AUTO_TEST_CASE(Forward2) |
| 147 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 148 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 149 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
| 150 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 151 | fib.addOrUpdateNextHop(fibEntry, *face3, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 152 | |
| 153 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 154 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 155 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 156 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 157 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 158 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 159 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 160 | std::set<FaceId> sentInterestFaceIds; |
| 161 | std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(), |
| 162 | std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()), |
| 163 | [] (const MulticastStrategyTester::SendInterestArgs& args) { |
| 164 | return args.outFaceId; |
| 165 | }); |
| 166 | std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()}; |
| 167 | BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(), |
| 168 | expectedInterestFaceIds.begin(), expectedInterestFaceIds.end()); |
Ashlesh Gawande | e38e261 | 2017-02-25 07:23:41 +0000 | [diff] [blame] | 169 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 170 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
| 171 | MulticastStrategy::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 172 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 173 | // downstream retransmits frequently, but the strategy should not send Interests |
| 174 | // more often than DEFAULT_MIN_RETX_INTERVAL |
| 175 | scheduler::EventId retxFrom4Evt; |
| 176 | size_t nSentLast = strategy.sendInterestHistory.size(); |
| 177 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 178 | std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 179 | periodicalRetxFrom4 = [&] { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 180 | pitEntry->insertOrUpdateInRecord(*face3, *interest); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 181 | strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 182 | |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 183 | size_t nSent = strategy.sendInterestHistory.size(); |
| 184 | if (nSent > nSentLast) { |
| 185 | // Multicast strategy should multicast the interest to other two faces |
| 186 | BOOST_CHECK_EQUAL(nSent - nSentLast, 2); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 187 | auto timeSent = time::steady_clock::now(); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 188 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
| 189 | nSentLast = nSent; |
| 190 | timeSentLast = timeSent; |
| 191 | } |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 192 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 193 | retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4); |
Ashlesh Gawande | ecdbe5f | 2017-03-04 03:08:24 +0000 | [diff] [blame] | 194 | }; |
| 195 | periodicalRetxFrom4(); |
| 196 | this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16); |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 197 | retxFrom4Evt.cancel(); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Afanasyev | 4400e42 | 2021-02-17 11:17:33 -0500 | [diff] [blame] | 200 | BOOST_AUTO_TEST_CASE(LoopingInterest) |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 201 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 202 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 203 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 204 | |
| 205 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 206 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 207 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 208 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 209 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
Alexander Afanasyev | 4400e42 | 2021-02-17 11:17:33 -0500 | [diff] [blame] | 210 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0); |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Alexander Afanasyev | 40604e3 | 2021-02-17 12:06:26 -0500 | [diff] [blame] | 214 | BOOST_AUTO_TEST_CASE(ForwardAsync) |
| 215 | { |
| 216 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 217 | fib.addOrUpdateNextHop(fibEntry, *face1, 0); |
| 218 | fib.addOrUpdateNextHop(fibEntry, *face2, 0); |
| 219 | |
| 220 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
| 221 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 222 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 223 | |
| 224 | strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry); |
| 225 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 226 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 227 | |
| 228 | fib.addOrUpdateNextHop(fibEntry, *face3, 0); |
| 229 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0); |
| 230 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 231 | } |
| 232 | |
| 233 | BOOST_AUTO_TEST_SUITE(LocalhopScope) |
| 234 | |
| 235 | class ForwardAsyncFixture : public MulticastStrategyFixture |
| 236 | { |
| 237 | protected: |
| 238 | shared_ptr<Face> inFace1; |
| 239 | shared_ptr<Face> inFace2; |
| 240 | shared_ptr<Face> fibFace1; |
| 241 | shared_ptr<Face> fibFace2; |
| 242 | shared_ptr<Face> newFibFace; |
| 243 | |
| 244 | size_t expectedInterests = 0; |
| 245 | }; |
| 246 | |
| 247 | class BasicNonLocal : public ForwardAsyncFixture |
| 248 | { |
| 249 | protected: |
| 250 | BasicNonLocal() |
| 251 | { |
| 252 | inFace1 = face1; |
| 253 | // inFace2 = nullptr; |
| 254 | fibFace1 = face1; |
| 255 | fibFace2 = face2; |
| 256 | newFibFace = face3; |
| 257 | expectedInterests = 0; // anything received on non-local face can only be sent to local face |
| 258 | } |
| 259 | }; |
| 260 | |
| 261 | class NewFibLocal : public ForwardAsyncFixture |
| 262 | { |
| 263 | protected: |
| 264 | NewFibLocal() |
| 265 | { |
| 266 | inFace1 = face1; |
| 267 | // inFace2 = nullptr; |
| 268 | fibFace1 = face1; |
| 269 | fibFace2 = face2; |
| 270 | newFibFace = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 271 | expectedInterests = 1; |
| 272 | |
| 273 | faceTable.add(newFibFace); |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | class InFaceLocal : public ForwardAsyncFixture |
| 278 | { |
| 279 | protected: |
| 280 | InFaceLocal() |
| 281 | { |
| 282 | inFace1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 283 | // inFace2 = nullptr; |
| 284 | fibFace1 = face1; |
| 285 | fibFace2 = face2; |
| 286 | newFibFace = face3; |
| 287 | expectedInterests = 1; |
| 288 | |
| 289 | faceTable.add(inFace1); |
| 290 | } |
| 291 | }; |
| 292 | |
| 293 | class InFaceLocalSameNewFace : public ForwardAsyncFixture |
| 294 | { |
| 295 | protected: |
| 296 | InFaceLocalSameNewFace() |
| 297 | { |
| 298 | inFace1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 299 | // inFace2 = nullptr; |
| 300 | fibFace1 = face1; |
| 301 | fibFace2 = face2; |
| 302 | newFibFace = inFace1; |
| 303 | expectedInterests = 0; |
| 304 | |
| 305 | faceTable.add(inFace1); |
| 306 | } |
| 307 | }; |
| 308 | |
| 309 | class InFaceLocalAdHocSameNewFace : public ForwardAsyncFixture |
| 310 | { |
| 311 | protected: |
| 312 | InFaceLocalAdHocSameNewFace() |
| 313 | { |
| 314 | inFace1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL, |
| 315 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 316 | ndn::nfd::LINK_TYPE_AD_HOC); |
| 317 | // inFace2 = nullptr; |
| 318 | fibFace1 = face1; |
| 319 | fibFace2 = face2; |
| 320 | newFibFace = inFace1; |
| 321 | expectedInterests = 1; |
| 322 | |
| 323 | faceTable.add(inFace1); |
| 324 | } |
| 325 | }; |
| 326 | |
| 327 | class InFaceLocalAndNonLocal1 : public ForwardAsyncFixture |
| 328 | { |
| 329 | protected: |
| 330 | InFaceLocalAndNonLocal1() |
| 331 | { |
| 332 | inFace1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 333 | inFace2 = face1; |
| 334 | fibFace1 = face1; |
| 335 | fibFace2 = face2; |
| 336 | newFibFace = face3; |
| 337 | expectedInterests = 1; |
| 338 | |
| 339 | faceTable.add(inFace1); |
| 340 | } |
| 341 | }; |
| 342 | |
| 343 | class InFaceLocalAndNonLocal2 : public ForwardAsyncFixture |
| 344 | { |
| 345 | protected: |
| 346 | InFaceLocalAndNonLocal2() |
| 347 | { |
| 348 | inFace1 = face1; |
| 349 | inFace2 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 350 | fibFace1 = face1; |
| 351 | fibFace2 = face2; |
| 352 | newFibFace = face3; |
| 353 | expectedInterests = 1; |
| 354 | |
| 355 | faceTable.add(inFace2); |
| 356 | } |
| 357 | }; |
| 358 | |
| 359 | class InFaceSelection1 : public ForwardAsyncFixture |
| 360 | { |
| 361 | protected: |
| 362 | InFaceSelection1() |
| 363 | { |
| 364 | inFace1 = face1; |
| 365 | // inFace2 = nullptr; |
| 366 | fibFace1 = face3; |
| 367 | fibFace2 = face2; |
| 368 | newFibFace = face1; |
| 369 | |
| 370 | expectedInterests = 0; |
| 371 | } |
| 372 | }; |
| 373 | |
| 374 | class InFaceSelection2 : public ForwardAsyncFixture |
| 375 | { |
| 376 | protected: |
| 377 | InFaceSelection2() |
| 378 | { |
| 379 | inFace1 = face2; |
| 380 | inFace2 = face1; |
| 381 | fibFace1 = face2; |
| 382 | fibFace2 = face3; |
| 383 | newFibFace = face1; |
| 384 | |
| 385 | // this test will trigger the check for additional branch, but it |
| 386 | // still is not going to pass the localhop check |
| 387 | expectedInterests = 0; |
| 388 | } |
| 389 | }; |
| 390 | |
| 391 | using Tests = boost::mpl::vector< |
| 392 | BasicNonLocal, |
| 393 | NewFibLocal, |
| 394 | InFaceLocal, |
| 395 | InFaceLocalSameNewFace, |
| 396 | InFaceLocalAdHocSameNewFace, |
| 397 | InFaceLocalAndNonLocal1, |
| 398 | InFaceLocalAndNonLocal2, |
| 399 | InFaceSelection1, |
| 400 | InFaceSelection2 |
| 401 | >; |
| 402 | |
| 403 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ForwardAsync, T, Tests, T) |
| 404 | { |
| 405 | fib::Entry& fibEntry = *this->fib.insert(Name("/localhop")).first; |
| 406 | this->fib.addOrUpdateNextHop(fibEntry, *this->fibFace1, 0); |
| 407 | this->fib.addOrUpdateNextHop(fibEntry, *this->fibFace2, 0); |
| 408 | |
| 409 | shared_ptr<Interest> interest = makeInterest("ndn:/localhop/H0D6i5fc"); |
| 410 | shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first; |
| 411 | pitEntry->insertOrUpdateInRecord(*this->inFace1, *interest); |
| 412 | this->strategy.afterReceiveInterest(FaceEndpoint(*this->inFace1, 0), *interest, pitEntry); |
| 413 | |
| 414 | if (this->inFace2 != nullptr) { |
| 415 | shared_ptr<Interest> interest2 = makeInterest("ndn:/localhop/H0D6i5fc"); |
| 416 | pitEntry->insertOrUpdateInRecord(*this->inFace2, *interest2); |
| 417 | this->strategy.afterReceiveInterest(FaceEndpoint(*this->inFace2, 0), *interest2, pitEntry); |
| 418 | } |
| 419 | |
| 420 | this->strategy.sendInterestHistory.clear(); |
| 421 | this->fib.addOrUpdateNextHop(fibEntry, *this->newFibFace, 0); |
| 422 | BOOST_CHECK_EQUAL(this->strategy.sendInterestHistory.size(), this->expectedInterests); |
| 423 | } |
| 424 | |
| 425 | BOOST_AUTO_TEST_SUITE_END() // LocalhopScope |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 426 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy |
| 427 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 428 | |
| 429 | } // namespace tests |
| 430 | } // namespace fw |
| 431 | } // namespace nfd |