blob: 189d42f3f5980b84304b1f18d2242e0e401c15bb [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * 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 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
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 DiBenedetto7564d972014-03-24 14:28:46 -060051 face4->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
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();
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 Shi57f0f312014-03-16 11:52:20 -070064 shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070065 interest1->setNextHopFaceId(face1->getId());
66 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070067 pitEntry1->insertOrUpdateInRecord(face4, *interest1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070068
Junxiao Shi5e5e4452015-09-24 16:56:52 -070069 strategy.sendInterestHistory.clear();
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070070 strategy.afterReceiveInterest(*face4, *interest1, fibEntry, 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 Shi57f0f312014-03-16 11:52:20 -070077 pitEntry2->insertOrUpdateInRecord(face4, *interest2);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070078
Junxiao Shi5e5e4452015-09-24 16:56:52 -070079 strategy.sendInterestHistory.clear();
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070080 strategy.afterReceiveInterest(*face4, *interest2, fibEntry, 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 Shi2d9bdc82014-03-02 20:55:42 -070086 interest3->setNextHopFaceId(face3->getId());
87 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070088 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 Shi2d9bdc82014-03-02 20:55:42 -070093 strategy.afterReceiveInterest(*face4, *interest3, fibEntry, 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