Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame^] | 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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame^] | 24 | */ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 25 | |
| 26 | #include "fw/broadcast-strategy.hpp" |
| 27 | #include "strategy-tester.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 28 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 30 | #include "tests/test-common.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame^] | 33 | namespace fw { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | namespace tests { |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 35 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame^] | 36 | using namespace nfd::tests; |
| 37 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE(Forward2) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 41 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 42 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 43 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 44 | BroadcastStrategyTester 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(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 54 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 55 | fibEntry->addNextHop(face1, 0); |
| 56 | fibEntry->addNextHop(face2, 0); |
| 57 | fibEntry->addNextHop(face3, 0); |
| 58 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 59 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 60 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 61 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 62 | pitEntry->insertOrUpdateInRecord(face3, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 64 | strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 67 | bool hasFace1 = false; |
| 68 | bool hasFace2 = false; |
| 69 | for (std::vector<BroadcastStrategyTester::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 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 82 | BOOST_AUTO_TEST_CASE(RejectScope) |
| 83 | { |
| 84 | Forwarder forwarder; |
| 85 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 86 | BroadcastStrategyTester 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) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 108 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 109 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 110 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 111 | BroadcastStrategyTester strategy(forwarder); |
| 112 | |
| 113 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 114 | forwarder.addFace(face1); |
| 115 | |
| 116 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 117 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 118 | fibEntry->addNextHop(face1, 0); |
| 119 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 120 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 121 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 122 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 123 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 124 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 125 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 126 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 128 | } |
| 129 | |
| 130 | BOOST_AUTO_TEST_SUITE_END() |
| 131 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 132 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame^] | 133 | } // namespace fw |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 134 | } // namespace nfd |