Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 24 | |
| 25 | #include "fw/client-control-strategy.hpp" |
| 26 | #include "strategy-tester.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 27 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace tests { |
| 33 | |
| 34 | BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Forward3) |
| 37 | { |
| 38 | Forwarder forwarder; |
| 39 | typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester; |
| 40 | ClientControlStrategyTester strategy(forwarder); |
| 41 | |
| 42 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 43 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 44 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 45 | shared_ptr<DummyLocalFace> face4 = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 46 | face4->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 47 | forwarder.addFace(face1); |
| 48 | forwarder.addFace(face2); |
| 49 | forwarder.addFace(face3); |
| 50 | forwarder.addFace(face4); |
| 51 | |
| 52 | Fib& fib = forwarder.getFib(); |
| 53 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 54 | fibEntry->addNextHop(face2, 0); |
| 55 | |
| 56 | Pit& pit = forwarder.getPit(); |
| 57 | |
| 58 | // Interest with valid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 59 | shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 60 | interest1->setNextHopFaceId(face1->getId()); |
| 61 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 62 | pitEntry1->insertOrUpdateInRecord(face4, *interest1); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 63 | |
| 64 | strategy.m_sendInterestHistory.clear(); |
| 65 | strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1); |
| 66 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 67 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1); |
| 68 | |
| 69 | // Interest without NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 70 | shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 71 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 72 | pitEntry2->insertOrUpdateInRecord(face4, *interest2); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 73 | |
| 74 | strategy.m_sendInterestHistory.clear(); |
| 75 | strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2); |
| 76 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 77 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2); |
| 78 | |
| 79 | // Interest with invalid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 80 | shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 81 | interest3->setNextHopFaceId(face3->getId()); |
| 82 | shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 83 | pitEntry3->insertOrUpdateInRecord(face4, *interest3); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 84 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 85 | face3->close(); // face3 is closed and its FaceId becomes invalid |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 86 | strategy.m_sendInterestHistory.clear(); |
| 87 | strategy.m_rejectPendingInterestHistory.clear(); |
| 88 | strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3); |
| 89 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0); |
| 90 | BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1); |
| 91 | } |
| 92 | |
| 93 | BOOST_AUTO_TEST_SUITE_END() |
| 94 | |
| 95 | } // namespace tests |
| 96 | } // namespace nfd |