Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 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 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 47 | auto face1 = make_shared<DummyFace>(); |
| 48 | auto face2 = make_shared<DummyFace>(); |
| 49 | auto face3 = make_shared<DummyFace>(); |
| 50 | auto face4 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 51 | forwarder.addFace(face1); |
| 52 | forwarder.addFace(face2); |
| 53 | forwarder.addFace(face3); |
| 54 | forwarder.addFace(face4); |
| 55 | |
| 56 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 57 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 58 | fibEntry.addNextHop(*face2, 0); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 59 | |
| 60 | Pit& pit = forwarder.getPit(); |
| 61 | |
| 62 | // Interest with valid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 63 | shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 64 | interest1->setTag(make_shared<lp::NextHopFaceIdTag>(face1->getId())); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 65 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame^] | 66 | pitEntry1->insertOrUpdateInRecord(*face4, *interest1); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 67 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 68 | strategy.sendInterestHistory.clear(); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 69 | strategy.afterReceiveInterest(*face4, *interest1, pitEntry1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 70 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 71 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 72 | |
| 73 | // Interest without NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 74 | shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz"); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 75 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame^] | 76 | pitEntry2->insertOrUpdateInRecord(*face4, *interest2); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 77 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 78 | strategy.sendInterestHistory.clear(); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 79 | strategy.afterReceiveInterest(*face4, *interest2, pitEntry2); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 80 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 81 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId()); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 82 | |
| 83 | // Interest with invalid NextHopFaceId |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 84 | shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 85 | interest3->setTag(make_shared<lp::NextHopFaceIdTag>(face3->getId())); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 86 | shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame^] | 87 | pitEntry3->insertOrUpdateInRecord(*face4, *interest3); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 88 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 89 | face3->close(); // face3 is closed and its FaceId becomes invalid |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 90 | strategy.sendInterestHistory.clear(); |
| 91 | strategy.rejectPendingInterestHistory.clear(); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 92 | strategy.afterReceiveInterest(*face4, *interest3, pitEntry3); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 93 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 0); |
| 94 | BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 97 | BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy |
| 98 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 99 | |
| 100 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 101 | } // namespace fw |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 102 | } // namespace nfd |