Junxiao Shi | 67ba8d2 | 2015-08-21 21:21:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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 | |
| 38 | BOOST_FIXTURE_TEST_SUITE(FwMulticastStrategy, BaseFixture) |
| 39 | |
| 40 | BOOST_AUTO_TEST_CASE(Forward2) |
| 41 | { |
| 42 | Forwarder forwarder; |
| 43 | typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester; |
| 44 | MulticastStrategyTester strategy(forwarder); |
| 45 | |
| 46 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 47 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 48 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 49 | forwarder.addFace(face1); |
| 50 | forwarder.addFace(face2); |
| 51 | forwarder.addFace(face3); |
| 52 | |
| 53 | Fib& fib = forwarder.getFib(); |
| 54 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 55 | fibEntry->addNextHop(face1, 0); |
| 56 | fibEntry->addNextHop(face2, 0); |
| 57 | fibEntry->addNextHop(face3, 0); |
| 58 | |
| 59 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
| 60 | Pit& pit = forwarder.getPit(); |
| 61 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 62 | pitEntry->insertOrUpdateInRecord(face3, *interest); |
| 63 | |
| 64 | strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry); |
| 65 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0); |
| 66 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 67 | bool hasFace1 = false; |
| 68 | bool hasFace2 = false; |
| 69 | for (std::vector<MulticastStrategyTester::SendInterestArgs>::iterator it = |
| 70 | strategy.m_sendInterestHistory.begin(); |
| 71 | it != strategy.m_sendInterestHistory.end(); ++it) { |
| 72 | if (it->get<1>() == face1) { |
| 73 | hasFace1 = true; |
| 74 | } |
| 75 | if (it->get<1>() == face2) { |
| 76 | hasFace2 = true; |
| 77 | } |
| 78 | } |
| 79 | BOOST_CHECK(hasFace1 && hasFace2); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(RejectScope) |
| 83 | { |
| 84 | Forwarder forwarder; |
| 85 | typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester; |
| 86 | MulticastStrategyTester strategy(forwarder); |
| 87 | |
| 88 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 89 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 90 | forwarder.addFace(face1); |
| 91 | forwarder.addFace(face2); |
| 92 | |
| 93 | Fib& fib = forwarder.getFib(); |
| 94 | shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first; |
| 95 | fibEntry->addNextHop(face2, 0); |
| 96 | |
| 97 | shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z"); |
| 98 | Pit& pit = forwarder.getPit(); |
| 99 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 100 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 101 | |
| 102 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 103 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 104 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 105 | } |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
| 108 | { |
| 109 | Forwarder forwarder; |
| 110 | typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester; |
| 111 | MulticastStrategyTester strategy(forwarder); |
| 112 | |
| 113 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 114 | forwarder.addFace(face1); |
| 115 | |
| 116 | Fib& fib = forwarder.getFib(); |
| 117 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 118 | fibEntry->addNextHop(face1, 0); |
| 119 | |
| 120 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
| 121 | Pit& pit = forwarder.getPit(); |
| 122 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 123 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 124 | |
| 125 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 126 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 127 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 128 | } |
| 129 | |
| 130 | BOOST_AUTO_TEST_SUITE_END() |
| 131 | |
| 132 | } // namespace tests |
| 133 | } // namespace fw |
| 134 | } // namespace nfd |