blob: 517d2aac73044932031804dc1498a4c890d90766 [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 Shicbc8e942016-09-06 03:17:45 +000029#include <ndn-cxx/lp/tags.hpp>
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070030
31#include "tests/test-common.hpp"
32
33namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace fw {
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070035namespace tests {
36
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037using namespace nfd::tests;
38
Junxiao Shi5e5e4452015-09-24 16:56:52 -070039BOOST_AUTO_TEST_SUITE(Fw)
40BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070041
42BOOST_AUTO_TEST_CASE(Forward3)
43{
44 Forwarder forwarder;
45 typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester;
46 ClientControlStrategyTester strategy(forwarder);
47
Junxiao Shicde37ad2015-12-24 01:02:05 -070048 auto face1 = make_shared<DummyFace>();
49 auto face2 = make_shared<DummyFace>();
50 auto face3 = make_shared<DummyFace>();
51 auto face4 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070052 forwarder.addFace(face1);
53 forwarder.addFace(face2);
54 forwarder.addFace(face3);
55 forwarder.addFace(face4);
56
57 Fib& fib = forwarder.getFib();
Junxiao Shia6de4292016-07-12 02:08:10 +000058 fib::Entry& fibEntry = *fib.insert(Name()).first;
59 fibEntry.addNextHop(*face2, 0);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070060
61 Pit& pit = forwarder.getPit();
62
63 // Interest with valid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070064 shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi0de23a22015-12-03 20:07:02 +000065 interest1->setTag(make_shared<lp::NextHopFaceIdTag>(face1->getId()));
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070066 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000067 pitEntry1->insertOrUpdateInRecord(*face4, *interest1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070068
Junxiao Shi5e5e4452015-09-24 16:56:52 -070069 strategy.sendInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000070 strategy.afterReceiveInterest(*face4, *interest1, pitEntry1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070071 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
72 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070073
74 // Interest without NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070075 shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070076 shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000077 pitEntry2->insertOrUpdateInRecord(*face4, *interest2);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070078
Junxiao Shi5e5e4452015-09-24 16:56:52 -070079 strategy.sendInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000080 strategy.afterReceiveInterest(*face4, *interest2, pitEntry2);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070081 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
82 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070083
84 // Interest with invalid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070085 shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi0de23a22015-12-03 20:07:02 +000086 interest3->setTag(make_shared<lp::NextHopFaceIdTag>(face3->getId()));
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070087 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000088 pitEntry3->insertOrUpdateInRecord(*face4, *interest3);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070089
Junxiao Shic542b2b2014-03-16 21:45:52 -070090 face3->close(); // face3 is closed and its FaceId becomes invalid
Junxiao Shi5e5e4452015-09-24 16:56:52 -070091 strategy.sendInterestHistory.clear();
92 strategy.rejectPendingInterestHistory.clear();
Junxiao Shi8d843142016-07-11 22:42:42 +000093 strategy.afterReceiveInterest(*face4, *interest3, pitEntry3);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070094 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 0);
95 BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070096}
97
Junxiao Shi5e5e4452015-09-24 16:56:52 -070098BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
99BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700100
101} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800102} // namespace fw
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700103} // namespace nfd