blob: 3ee72cace487706372e8a9146f47a08a0a431c39 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070024
25#include "fw/client-control-strategy.hpp"
26#include "strategy-tester.hpp"
27#include "tests/face/dummy-face.hpp"
28
29#include "tests/test-common.hpp"
30
31namespace nfd {
32namespace tests {
33
34BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture)
35
36BOOST_AUTO_TEST_CASE(Forward3)
37{
38 Forwarder forwarder;
39 typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester;
40 ClientControlStrategyTester strategy(forwarder);
41
42 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
43 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
44 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
45 shared_ptr<DummyLocalFace> face4 = make_shared<DummyLocalFace>();
Steve DiBenedetto7564d972014-03-24 14:28:46 -060046 face4->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070047 forwarder.addFace(face1);
48 forwarder.addFace(face2);
49 forwarder.addFace(face3);
50 forwarder.addFace(face4);
51
52 Fib& fib = forwarder.getFib();
53 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
54 fibEntry->addNextHop(face2, 0);
55
56 Pit& pit = forwarder.getPit();
57
58 // Interest with valid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070059 shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070060 interest1->setNextHopFaceId(face1->getId());
61 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070062 pitEntry1->insertOrUpdateInRecord(face4, *interest1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070063
64 strategy.m_sendInterestHistory.clear();
65 strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1);
66 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
67 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1);
68
69 // Interest without NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070070 shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070071 shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070072 pitEntry2->insertOrUpdateInRecord(face4, *interest2);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070073
74 strategy.m_sendInterestHistory.clear();
75 strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2);
76 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
77 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2);
78
79 // Interest with invalid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070080 shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070081 interest3->setNextHopFaceId(face3->getId());
82 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070083 pitEntry3->insertOrUpdateInRecord(face4, *interest3);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070084
Junxiao Shic542b2b2014-03-16 21:45:52 -070085 face3->close(); // face3 is closed and its FaceId becomes invalid
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070086 strategy.m_sendInterestHistory.clear();
87 strategy.m_rejectPendingInterestHistory.clear();
88 strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3);
89 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0);
90 BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
91}
92
93BOOST_AUTO_TEST_SUITE_END()
94
95} // namespace tests
96} // namespace nfd