blob: 9f500e8e78a811cb599471a6b45f6146c0025601 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi8d843142016-07-11 22:42:42 +00003 * Copyright (c) 2014-2016, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Mastorakisd0381c02015-02-19 10:29:41 -080024 */
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070025
26#include "fw/client-control-strategy.hpp"
27#include "strategy-tester.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070028#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070029
30#include "tests/test-common.hpp"
31
32namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080033namespace fw {
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070034namespace tests {
35
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080036using namespace nfd::tests;
37
Junxiao Shi5e5e4452015-09-24 16:56:52 -070038BOOST_AUTO_TEST_SUITE(Fw)
39BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070040
41BOOST_AUTO_TEST_CASE(Forward3)
42{
43 Forwarder forwarder;
44 typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester;
45 ClientControlStrategyTester strategy(forwarder);
46
Junxiao Shicde37ad2015-12-24 01:02:05 -070047 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 Shi2d9bdc82014-03-02 20:55:42 -070051 forwarder.addFace(face1);
52 forwarder.addFace(face2);
53 forwarder.addFace(face3);
54 forwarder.addFace(face4);
55
56 Fib& fib = forwarder.getFib();
Junxiao Shia6de4292016-07-12 02:08:10 +000057 fib::Entry& fibEntry = *fib.insert(Name()).first;
58 fibEntry.addNextHop(*face2, 0);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070059
60 Pit& pit = forwarder.getPit();
61
62 // Interest with valid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070063 shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi0de23a22015-12-03 20:07:02 +000064 interest1->setTag(make_shared<lp::NextHopFaceIdTag>(face1->getId()));
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070065 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000066 pitEntry1->insertOrUpdateInRecord(*face4, *interest1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070067
Junxiao Shi5e5e4452015-09-24 16:56:52 -070068 strategy.sendInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000069 strategy.afterReceiveInterest(*face4, *interest1, pitEntry1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070070 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
71 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070072
73 // Interest without NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070074 shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070075 shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000076 pitEntry2->insertOrUpdateInRecord(*face4, *interest2);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070077
Junxiao Shi5e5e4452015-09-24 16:56:52 -070078 strategy.sendInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000079 strategy.afterReceiveInterest(*face4, *interest2, pitEntry2);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070080 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
81 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070082
83 // Interest with invalid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070084 shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi0de23a22015-12-03 20:07:02 +000085 interest3->setTag(make_shared<lp::NextHopFaceIdTag>(face3->getId()));
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070086 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000087 pitEntry3->insertOrUpdateInRecord(*face4, *interest3);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070088
Junxiao Shic542b2b2014-03-16 21:45:52 -070089 face3->close(); // face3 is closed and its FaceId becomes invalid
Junxiao Shi5e5e4452015-09-24 16:56:52 -070090 strategy.sendInterestHistory.clear();
91 strategy.rejectPendingInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000092 strategy.afterReceiveInterest(*face4, *interest3, pitEntry3);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070093 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 0);
94 BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070095}
96
Junxiao Shi5e5e4452015-09-24 16:56:52 -070097BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
98BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070099
100} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800101} // namespace fw
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700102} // namespace nfd