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