Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "fw/broadcast-strategy.hpp" |
| 8 | #include "strategy-tester.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 9 | #include "tests/face/dummy-face.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 10 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 11 | #include "tests/test-common.hpp" |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 14 | namespace tests { |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 15 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 16 | BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 17 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 18 | BOOST_AUTO_TEST_CASE(Forward2) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 19 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 20 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 21 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 22 | BroadcastStrategyTester strategy(forwarder); |
| 23 | |
| 24 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 25 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 26 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 27 | forwarder.addFace(face1); |
| 28 | forwarder.addFace(face2); |
| 29 | forwarder.addFace(face3); |
| 30 | |
| 31 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 32 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 33 | fibEntry->addNextHop(face1, 0); |
| 34 | fibEntry->addNextHop(face2, 0); |
| 35 | fibEntry->addNextHop(face3, 0); |
| 36 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 37 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 38 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 39 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 40 | pitEntry->insertOrUpdateInRecord(face3, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 42 | strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 43 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 45 | bool hasFace1 = false; |
| 46 | bool hasFace2 = false; |
| 47 | for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it = |
| 48 | strategy.m_sendInterestHistory.begin(); |
| 49 | it != strategy.m_sendInterestHistory.end(); ++it) { |
| 50 | if (it->get<1>() == face1) { |
| 51 | hasFace1 = true; |
| 52 | } |
| 53 | if (it->get<1>() == face2) { |
| 54 | hasFace2 = true; |
| 55 | } |
| 56 | } |
| 57 | BOOST_CHECK(hasFace1 && hasFace2); |
| 58 | } |
| 59 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 60 | BOOST_AUTO_TEST_CASE(RejectScope) |
| 61 | { |
| 62 | Forwarder forwarder; |
| 63 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 64 | BroadcastStrategyTester strategy(forwarder); |
| 65 | |
| 66 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 67 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 68 | forwarder.addFace(face1); |
| 69 | forwarder.addFace(face2); |
| 70 | |
| 71 | Fib& fib = forwarder.getFib(); |
| 72 | shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first; |
| 73 | fibEntry->addNextHop(face2, 0); |
| 74 | |
| 75 | shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z"); |
| 76 | Pit& pit = forwarder.getPit(); |
| 77 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 78 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 79 | |
| 80 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 81 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 82 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE(RejectLoopback) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 86 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 87 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 88 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 89 | BroadcastStrategyTester strategy(forwarder); |
| 90 | |
| 91 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 92 | forwarder.addFace(face1); |
| 93 | |
| 94 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 95 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 96 | fibEntry->addNextHop(face1, 0); |
| 97 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 98 | shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc"); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 99 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 100 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 101 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 103 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 105 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 106 | } |
| 107 | |
| 108 | BOOST_AUTO_TEST_SUITE_END() |
| 109 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 110 | } // namespace tests |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 111 | } // namespace nfd |