blob: b8c3d2f221042d2998ecadd04c1bf2f2efe0ed14 [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 Shi890afe92016-12-15 14:34:34 +000038typedef StrategyTester<MulticastStrategy> MulticastStrategyTester;
39NFD_REGISTER_STRATEGY(MulticastStrategyTester);
40
41class MulticastStrategyFixture : public BaseFixture
42{
43protected:
44 MulticastStrategyFixture()
45 : strategy(forwarder)
46 , fib(forwarder.getFib())
47 , pit(forwarder.getPit())
48 , face1(make_shared<DummyFace>())
49 , face2(make_shared<DummyFace>())
50 , face3(make_shared<DummyFace>())
51 {
52 forwarder.addFace(face1);
53 forwarder.addFace(face2);
54 forwarder.addFace(face3);
55 }
56
57protected:
58 Forwarder forwarder;
59 MulticastStrategyTester strategy;
60 Fib& fib;
61 Pit& pit;
62 shared_ptr<DummyFace> face1;
63 shared_ptr<DummyFace> face2;
64 shared_ptr<DummyFace> face3;
65};
66
Junxiao Shi5e5e4452015-09-24 16:56:52 -070067BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shi890afe92016-12-15 14:34:34 +000068BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070069
Junxiao Shic34d1672016-12-09 15:57:59 +000070BOOST_AUTO_TEST_CASE(Registration)
71{
Junxiao Shi037f4ab2016-12-13 04:27:06 +000072 BOOST_CHECK_EQUAL(Strategy::listRegistered().count(MulticastStrategy::getStrategyName()), 1);
Junxiao Shic34d1672016-12-09 15:57:59 +000073}
74
Junxiao Shi67ba8d22015-08-21 21:21:28 -070075BOOST_AUTO_TEST_CASE(Forward2)
76{
Junxiao Shia6de4292016-07-12 02:08:10 +000077 fib::Entry& fibEntry = *fib.insert(Name()).first;
78 fibEntry.addNextHop(*face1, 0);
79 fibEntry.addNextHop(*face2, 0);
80 fibEntry.addNextHop(*face3, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070081
82 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi67ba8d22015-08-21 21:21:28 -070083 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +000084 pitEntry->insertOrUpdateInRecord(*face3, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070085
Junxiao Shi8d843142016-07-11 22:42:42 +000086 strategy.afterReceiveInterest(*face3, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070087 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
88 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
89 std::set<FaceId> sentInterestFaceIds;
90 std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
91 std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
92 [] (const MulticastStrategyTester::SendInterestArgs& args) {
93 return args.outFaceId;
94 });
95 std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
96 BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
97 expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
Junxiao Shi67ba8d22015-08-21 21:21:28 -070098}
99
100BOOST_AUTO_TEST_CASE(RejectScope)
101{
Junxiao Shia6de4292016-07-12 02:08:10 +0000102 fib::Entry& fibEntry = *fib.insert("ndn:/localhop/uS09bub6tm").first;
103 fibEntry.addNextHop(*face2, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700104
105 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700106 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000107 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700108
Junxiao Shi8d843142016-07-11 22:42:42 +0000109 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700110 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
111 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700112}
113
114BOOST_AUTO_TEST_CASE(RejectLoopback)
115{
Junxiao Shia6de4292016-07-12 02:08:10 +0000116 fib::Entry& fibEntry = *fib.insert(Name()).first;
117 fibEntry.addNextHop(*face1, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700118
119 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700120 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000121 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700122
Junxiao Shi8d843142016-07-11 22:42:42 +0000123 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700124 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
125 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700126}
127
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700128BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
129BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700130
131} // namespace tests
132} // namespace fw
133} // namespace nfd