Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 24 | |
| 25 | #include "fw/broadcast-strategy.hpp" |
| 26 | #include "strategy-tester.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 27 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 32 | namespace tests { |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 33 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 36 | BOOST_AUTO_TEST_CASE(Forward2) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 37 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 38 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 39 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 40 | BroadcastStrategyTester strategy(forwarder); |
| 41 | |
| 42 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 43 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 44 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 45 | forwarder.addFace(face1); |
| 46 | forwarder.addFace(face2); |
| 47 | forwarder.addFace(face3); |
| 48 | |
| 49 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 50 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 51 | fibEntry->addNextHop(face1, 0); |
| 52 | fibEntry->addNextHop(face2, 0); |
| 53 | fibEntry->addNextHop(face3, 0); |
| 54 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 55 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 56 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 57 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 58 | pitEntry->insertOrUpdateInRecord(face3, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 59 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 60 | strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 63 | bool hasFace1 = false; |
| 64 | bool hasFace2 = false; |
| 65 | for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it = |
| 66 | strategy.m_sendInterestHistory.begin(); |
| 67 | it != strategy.m_sendInterestHistory.end(); ++it) { |
| 68 | if (it->get<1>() == face1) { |
| 69 | hasFace1 = true; |
| 70 | } |
| 71 | if (it->get<1>() == face2) { |
| 72 | hasFace2 = true; |
| 73 | } |
| 74 | } |
| 75 | BOOST_CHECK(hasFace1 && hasFace2); |
| 76 | } |
| 77 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(RejectScope) |
| 79 | { |
| 80 | Forwarder forwarder; |
| 81 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 82 | BroadcastStrategyTester strategy(forwarder); |
| 83 | |
| 84 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 85 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 86 | forwarder.addFace(face1); |
| 87 | forwarder.addFace(face2); |
| 88 | |
| 89 | Fib& fib = forwarder.getFib(); |
| 90 | shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first; |
| 91 | fibEntry->addNextHop(face2, 0); |
| 92 | |
| 93 | shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z"); |
| 94 | Pit& pit = forwarder.getPit(); |
| 95 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 96 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 97 | |
| 98 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 99 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 100 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 104 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 105 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 106 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 107 | BroadcastStrategyTester strategy(forwarder); |
| 108 | |
| 109 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 110 | forwarder.addFace(face1); |
| 111 | |
| 112 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 113 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 114 | fibEntry->addNextHop(face1, 0); |
| 115 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 116 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 117 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 118 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 119 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 120 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 121 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_SUITE_END() |
| 127 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 128 | } // namespace tests |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 129 | } // namespace nfd |