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 | |
| 18 | BOOST_AUTO_TEST_CASE(ForwardTwo) |
| 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(); |
| 32 | std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name()); |
| 33 | shared_ptr<fib::Entry> fibEntry = fibInsertResult.first; |
| 34 | fibEntry->addNextHop(face1, 0); |
| 35 | fibEntry->addNextHop(face2, 0); |
| 36 | fibEntry->addNextHop(face3, 0); |
| 37 | |
| 38 | Interest interest(Name("ndn:/H0D6i5fc")); |
| 39 | Pit& pit = forwarder.getPit(); |
| 40 | std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest); |
| 41 | shared_ptr<pit::Entry> pitEntry = pitInsertResult.first; |
| 42 | |
| 43 | strategy.afterReceiveInterest(*face3, interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 46 | bool hasFace1 = false; |
| 47 | bool hasFace2 = false; |
| 48 | for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it = |
| 49 | strategy.m_sendInterestHistory.begin(); |
| 50 | it != strategy.m_sendInterestHistory.end(); ++it) { |
| 51 | if (it->get<1>() == face1) { |
| 52 | hasFace1 = true; |
| 53 | } |
| 54 | if (it->get<1>() == face2) { |
| 55 | hasFace2 = true; |
| 56 | } |
| 57 | } |
| 58 | BOOST_CHECK(hasFace1 && hasFace2); |
| 59 | } |
| 60 | |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 61 | BOOST_AUTO_TEST_CASE(Reject) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 62 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 63 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 64 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 65 | BroadcastStrategyTester strategy(forwarder); |
| 66 | |
| 67 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 68 | forwarder.addFace(face1); |
| 69 | |
| 70 | Fib& fib = forwarder.getFib(); |
| 71 | std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name()); |
| 72 | shared_ptr<fib::Entry> fibEntry = fibInsertResult.first; |
| 73 | fibEntry->addNextHop(face1, 0); |
| 74 | |
| 75 | Interest interest(Name("ndn:/H0D6i5fc")); |
| 76 | Pit& pit = forwarder.getPit(); |
| 77 | std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest); |
| 78 | shared_ptr<pit::Entry> pitEntry = pitInsertResult.first; |
| 79 | |
| 80 | strategy.afterReceiveInterest(*face1, interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_SUITE_END() |
| 86 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 87 | } // namespace tests |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 88 | } // namespace nfd |