blob: 1322930635579cceaba55199a2ad0fe8a11047d9 [file] [log] [blame]
Junxiao Shi67ba8d22015-08-21 21:21:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi8d843142016-07-11 22:42:42 +00003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shi67ba8d22015-08-21 21:21:28 -07004 * 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
Junxiao Shic34d1672016-12-09 15:57:59 +000041BOOST_AUTO_TEST_CASE(Registration)
42{
Junxiao Shi037f4ab2016-12-13 04:27:06 +000043 BOOST_CHECK_EQUAL(Strategy::listRegistered().count(MulticastStrategy::getStrategyName()), 1);
Junxiao Shic34d1672016-12-09 15:57:59 +000044}
45
Junxiao Shi67ba8d22015-08-21 21:21:28 -070046BOOST_AUTO_TEST_CASE(Forward2)
47{
48 Forwarder forwarder;
49 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
50 MulticastStrategyTester strategy(forwarder);
51
52 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
53 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
54 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
55 forwarder.addFace(face1);
56 forwarder.addFace(face2);
57 forwarder.addFace(face3);
58
59 Fib& fib = forwarder.getFib();
Junxiao Shia6de4292016-07-12 02:08:10 +000060 fib::Entry& fibEntry = *fib.insert(Name()).first;
61 fibEntry.addNextHop(*face1, 0);
62 fibEntry.addNextHop(*face2, 0);
63 fibEntry.addNextHop(*face3, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070064
65 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
66 Pit& pit = forwarder.getPit();
67 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000068 pitEntry->insertOrUpdateInRecord(*face3, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070069
Junxiao Shi8d843142016-07-11 22:42:42 +000070 strategy.afterReceiveInterest(*face3, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070071 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
72 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
73 std::set<FaceId> sentInterestFaceIds;
74 std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
75 std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
76 [] (const MulticastStrategyTester::SendInterestArgs& args) {
77 return args.outFaceId;
78 });
79 std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
80 BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
81 expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
Junxiao Shi67ba8d22015-08-21 21:21:28 -070082}
83
84BOOST_AUTO_TEST_CASE(RejectScope)
85{
86 Forwarder forwarder;
87 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
88 MulticastStrategyTester strategy(forwarder);
89
90 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
91 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
92 forwarder.addFace(face1);
93 forwarder.addFace(face2);
94
95 Fib& fib = forwarder.getFib();
Junxiao Shia6de4292016-07-12 02:08:10 +000096 fib::Entry& fibEntry = *fib.insert("ndn:/localhop/uS09bub6tm").first;
97 fibEntry.addNextHop(*face2, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070098
99 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
100 Pit& pit = forwarder.getPit();
101 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000102 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700103
Junxiao Shi8d843142016-07-11 22:42:42 +0000104 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700105 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
106 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700107}
108
109BOOST_AUTO_TEST_CASE(RejectLoopback)
110{
111 Forwarder forwarder;
112 typedef StrategyTester<fw::MulticastStrategy> MulticastStrategyTester;
113 MulticastStrategyTester strategy(forwarder);
114
115 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
116 forwarder.addFace(face1);
117
118 Fib& fib = forwarder.getFib();
Junxiao Shia6de4292016-07-12 02:08:10 +0000119 fib::Entry& fibEntry = *fib.insert(Name()).first;
120 fibEntry.addNextHop(*face1, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700121
122 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
123 Pit& pit = forwarder.getPit();
124 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000125 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700126
Junxiao Shi8d843142016-07-11 22:42:42 +0000127 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700128 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
129 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700130}
131
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700132BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
133BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700134
135} // namespace tests
136} // namespace fw
137} // namespace nfd