blob: 3476cd3920b601b09256b2c2e7d8783d4a4b9efc [file] [log] [blame]
Junxiao Shi67ba8d22015-08-21 21:21:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * 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.
10 *
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/>.
24 */
25
26#include "fw/multicast-strategy.hpp"
27#include "strategy-tester.hpp"
28#include "tests/daemon/face/dummy-face.hpp"
29
30#include "tests/test-common.hpp"
31
32namespace nfd {
33namespace fw {
34namespace tests {
35
36using namespace nfd::tests;
37
Junxiao Shi5e5e4452015-09-24 16:56:52 -070038BOOST_AUTO_TEST_SUITE(Fw)
39BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, BaseFixture)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070040
41BOOST_AUTO_TEST_CASE(Forward2)
42{
43 Forwarder forwarder;
44 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
45 MulticastStrategyTester 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 forwarder.addFace(face1);
51 forwarder.addFace(face2);
52 forwarder.addFace(face3);
53
54 Fib& fib = forwarder.getFib();
55 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
56 fibEntry->addNextHop(face1, 0);
57 fibEntry->addNextHop(face2, 0);
58 fibEntry->addNextHop(face3, 0);
59
60 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
61 Pit& pit = forwarder.getPit();
62 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
63 pitEntry->insertOrUpdateInRecord(face3, *interest);
64
65 strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070066 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
67 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
68 std::set<FaceId> sentInterestFaceIds;
69 std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
70 std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
71 [] (const MulticastStrategyTester::SendInterestArgs& args) {
72 return args.outFaceId;
73 });
74 std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
75 BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
76 expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
Junxiao Shi67ba8d22015-08-21 21:21:28 -070077}
78
79BOOST_AUTO_TEST_CASE(RejectScope)
80{
81 Forwarder forwarder;
82 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
83 MulticastStrategyTester strategy(forwarder);
84
85 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
86 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
87 forwarder.addFace(face1);
88 forwarder.addFace(face2);
89
90 Fib& fib = forwarder.getFib();
91 shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first;
92 fibEntry->addNextHop(face2, 0);
93
94 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
95 Pit& pit = forwarder.getPit();
96 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
97 pitEntry->insertOrUpdateInRecord(face1, *interest);
98
99 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700100 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
101 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700102}
103
104BOOST_AUTO_TEST_CASE(RejectLoopback)
105{
106 Forwarder forwarder;
107 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
108 MulticastStrategyTester strategy(forwarder);
109
110 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
111 forwarder.addFace(face1);
112
113 Fib& fib = forwarder.getFib();
114 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
115 fibEntry->addNextHop(face1, 0);
116
117 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
118 Pit& pit = forwarder.getPit();
119 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
120 pitEntry->insertOrUpdateInRecord(face1, *interest);
121
122 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700123 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
124 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700125}
126
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700127BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
128BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700129
130} // namespace tests
131} // namespace fw
132} // namespace nfd