blob: 42af192ee80c843eab34bb6abd91a2bcd97858b5 [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
41 shared_ptr<Interest> interest1 = make_shared<Interest>("ndn:/0z8r6yDDe");
42 interest1->setNextHopFaceId(face1->getId());
43 shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
44
45 strategy.m_sendInterestHistory.clear();
46 strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1);
47 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
48 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1);
49
50 // Interest without NextHopFaceId
51 shared_ptr<Interest> interest2 = make_shared<Interest>("ndn:/y6JQADGVz");
52 shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
53
54 strategy.m_sendInterestHistory.clear();
55 strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2);
56 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
57 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2);
58
59 // Interest with invalid NextHopFaceId
60 shared_ptr<Interest> interest3 = make_shared<Interest>("ndn:/0z8r6yDDe");
61 interest3->setNextHopFaceId(face3->getId());
62 shared_ptr<pit::Entry> pitEntry3 = pit.insert(*interest3).first;
63
64 forwarder.removeFace(face3); // face3 is removed and its FaceId becomes invalid
65 strategy.m_sendInterestHistory.clear();
66 strategy.m_rejectPendingInterestHistory.clear();
67 strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3);
68 BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0);
69 BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
70}
71
72BOOST_AUTO_TEST_SUITE_END()
73
74} // namespace tests
75} // namespace nfd