blob: 51534a49c9753a4cd27b1a2aff6a51cbc03070b8 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "fw/client-control-strategy.hpp"
8#include "strategy-tester.hpp"
9#include "tests/face/dummy-face.hpp"
10
11#include "tests/test-common.hpp"
12
13namespace nfd {
14namespace tests {
15
16BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture)
17
18BOOST_AUTO_TEST_CASE(Forward3)
19{
20 Forwarder forwarder;
21 typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester;
22 ClientControlStrategyTester strategy(forwarder);
23
24 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
25 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
26 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
27 shared_ptr<DummyLocalFace> face4 = make_shared<DummyLocalFace>();
28 face4->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID);
29 forwarder.addFace(face1);
30 forwarder.addFace(face2);
31 forwarder.addFace(face3);
32 forwarder.addFace(face4);
33
34 Fib& fib = forwarder.getFib();
35 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
36 fibEntry->addNextHop(face2, 0);
37
38 Pit& pit = forwarder.getPit();
39
40 // Interest with valid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070041 shared_ptr<Interest> interest1 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070042 interest1->setNextHopFaceId(face1->getId());
43 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070044 pitEntry1->insertOrUpdateInRecord(face4, *interest1);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070045
46 strategy.m_sendInterestHistory.clear();
47 strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1);
48 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
49 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1);
50
51 // Interest without NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070052 shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070053 shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070054 pitEntry2->insertOrUpdateInRecord(face4, *interest2);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070055
56 strategy.m_sendInterestHistory.clear();
57 strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2);
58 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
59 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2);
60
61 // Interest with invalid NextHopFaceId
Junxiao Shi57f0f312014-03-16 11:52:20 -070062 shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070063 interest3->setNextHopFaceId(face3->getId());
64 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
Junxiao Shi57f0f312014-03-16 11:52:20 -070065 pitEntry3->insertOrUpdateInRecord(face4, *interest3);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070066
Junxiao Shic542b2b2014-03-16 21:45:52 -070067 face3->close(); // face3 is closed and its FaceId becomes invalid
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070068 strategy.m_sendInterestHistory.clear();
69 strategy.m_rejectPendingInterestHistory.clear();
70 strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3);
71 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0);
72 BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
73}
74
75BOOST_AUTO_TEST_SUITE_END()
76
77} // namespace tests
78} // namespace nfd