Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -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/client-control-strategy.hpp" |
| 8 | #include "strategy-tester.hpp" |
| 9 | #include "tests/face/dummy-face.hpp" |
| 10 | |
| 11 | #include "tests/test-common.hpp" |
| 12 | |
| 13 | namespace nfd { |
| 14 | namespace tests { |
| 15 | |
| 16 | BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture) |
| 17 | |
| 18 | BOOST_AUTO_TEST_CASE(Forward3) |
| 19 | { |
| 20 | Forwarder forwarder; |
| 21 | typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester; |
| 22 | ClientControlStrategyTester 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 | shared_ptr<DummyLocalFace> face4 = make_shared<DummyLocalFace>(); |
| 28 | face4->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID); |
| 29 | forwarder.addFace(face1); |
| 30 | forwarder.addFace(face2); |
| 31 | forwarder.addFace(face3); |
| 32 | forwarder.addFace(face4); |
| 33 | |
| 34 | Fib& fib = forwarder.getFib(); |
| 35 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 36 | fibEntry->addNextHop(face2, 0); |
| 37 | |
| 38 | Pit& pit = forwarder.getPit(); |
| 39 | |
| 40 | // Interest with valid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 41 | shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 42 | interest1->setNextHopFaceId(face1->getId()); |
| 43 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 44 | pitEntry1->insertOrUpdateInRecord(face4, *interest1); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 45 | |
| 46 | strategy.m_sendInterestHistory.clear(); |
| 47 | strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1); |
| 48 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 49 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1); |
| 50 | |
| 51 | // Interest without NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 52 | shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 53 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 54 | pitEntry2->insertOrUpdateInRecord(face4, *interest2); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 55 | |
| 56 | strategy.m_sendInterestHistory.clear(); |
| 57 | strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2); |
| 58 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 59 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2); |
| 60 | |
| 61 | // Interest with invalid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 62 | shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 63 | interest3->setNextHopFaceId(face3->getId()); |
| 64 | shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame^] | 65 | pitEntry3->insertOrUpdateInRecord(face4, *interest3); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 66 | |
| 67 | forwarder.removeFace(face3); // face3 is removed and its FaceId becomes invalid |
| 68 | strategy.m_sendInterestHistory.clear(); |
| 69 | strategy.m_rejectPendingInterestHistory.clear(); |
| 70 | strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3); |
| 71 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 72 | BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_SUITE_END() |
| 76 | |
| 77 | } // namespace tests |
| 78 | } // namespace nfd |