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" |
| 9 | #include "../face/dummy-face.hpp" |
| 10 | |
| 11 | #include <boost/test/unit_test.hpp> |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | BOOST_AUTO_TEST_SUITE(FwBroadcastStrategy) |
| 16 | |
| 17 | BOOST_AUTO_TEST_CASE(ForwardTwo) |
| 18 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 19 | resetGlobalIoService(); |
| 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 | resetGlobalIoService(); |
| 64 | Forwarder forwarder; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 65 | typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester; |
| 66 | BroadcastStrategyTester strategy(forwarder); |
| 67 | |
| 68 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 69 | forwarder.addFace(face1); |
| 70 | |
| 71 | Fib& fib = forwarder.getFib(); |
| 72 | std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name()); |
| 73 | shared_ptr<fib::Entry> fibEntry = fibInsertResult.first; |
| 74 | fibEntry->addNextHop(face1, 0); |
| 75 | |
| 76 | Interest interest(Name("ndn:/H0D6i5fc")); |
| 77 | Pit& pit = forwarder.getPit(); |
| 78 | std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest); |
| 79 | shared_ptr<pit::Entry> pitEntry = pitInsertResult.first; |
| 80 | |
| 81 | strategy.afterReceiveInterest(*face1, interest, fibEntry, pitEntry); |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame^] | 82 | BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_SUITE_END() |
| 87 | |
| 88 | } // namespace nfd |