blob: e3ed88b5540f35f43d7cbac3058c083db1b3eb9b [file] [log] [blame]
Junxiao Shi67ba8d22015-08-21 21:21:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento87fc0f82018-04-11 23:43:51 -04002/*
ashiqopu3ad49db2018-10-20 22:38:47 +00003 * Copyright (c) 2014-2019, 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"
Davide Pesavento3dade002019-03-19 11:29:56 -060027#include "daemon/global.hpp"
Junxiao Shi67ba8d22015-08-21 21:21:28 -070028
Davide Pesavento3dade002019-03-19 11:29:56 -060029#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi67ba8d22015-08-21 21:21:28 -070030#include "tests/test-common.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060031#include "strategy-tester.hpp"
Junxiao Shi67ba8d22015-08-21 21:21:28 -070032
33namespace nfd {
34namespace fw {
35namespace tests {
36
37using namespace nfd::tests;
38
Junxiao Shi890afe92016-12-15 14:34:34 +000039typedef StrategyTester<MulticastStrategy> MulticastStrategyTester;
40NFD_REGISTER_STRATEGY(MulticastStrategyTester);
41
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000042class MulticastStrategyFixture : public UnitTestTimeFixture
Junxiao Shi890afe92016-12-15 14:34:34 +000043{
44protected:
45 MulticastStrategyFixture()
46 : strategy(forwarder)
47 , fib(forwarder.getFib())
48 , pit(forwarder.getPit())
49 , face1(make_shared<DummyFace>())
50 , face2(make_shared<DummyFace>())
51 , face3(make_shared<DummyFace>())
52 {
53 forwarder.addFace(face1);
54 forwarder.addFace(face2);
55 forwarder.addFace(face3);
56 }
57
58protected:
59 Forwarder forwarder;
60 MulticastStrategyTester strategy;
61 Fib& fib;
62 Pit& pit;
63 shared_ptr<DummyFace> face1;
64 shared_ptr<DummyFace> face2;
65 shared_ptr<DummyFace> face3;
66};
67
Junxiao Shi5e5e4452015-09-24 16:56:52 -070068BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shi890afe92016-12-15 14:34:34 +000069BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070070
71BOOST_AUTO_TEST_CASE(Forward2)
72{
Junxiao Shia6de4292016-07-12 02:08:10 +000073 fib::Entry& fibEntry = *fib.insert(Name()).first;
ashiqopu3ad49db2018-10-20 22:38:47 +000074 fibEntry.addOrUpdateNextHop(*face1, 0, 0);
75 fibEntry.addOrUpdateNextHop(*face2, 0, 0);
76 fibEntry.addOrUpdateNextHop(*face3, 0, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070077
78 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi67ba8d22015-08-21 21:21:28 -070079 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +000080 pitEntry->insertOrUpdateInRecord(*face3, 0, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070081
ashiqopuc7079482019-02-20 05:34:37 +000082 strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070083 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
84 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
85 std::set<FaceId> sentInterestFaceIds;
86 std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
87 std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
88 [] (const MulticastStrategyTester::SendInterestArgs& args) {
89 return args.outFaceId;
90 });
91 std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
92 BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
93 expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000094
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000095 const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>(
96 MulticastStrategy::RETX_SUPPRESSION_INITIAL * 0.1);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070097
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000098 // downstream retransmits frequently, but the strategy should not send Interests
99 // more often than DEFAULT_MIN_RETX_INTERVAL
100 scheduler::EventId retxFrom4Evt;
101 size_t nSentLast = strategy.sendInterestHistory.size();
102 time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400103 std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +0000104 periodicalRetxFrom4 = [&] {
ashiqopud3ae85d2019-02-17 02:29:55 +0000105 pitEntry->insertOrUpdateInRecord(*face3, 0, *interest);
ashiqopuc7079482019-02-20 05:34:37 +0000106 strategy.afterReceiveInterest(FaceEndpoint(*face3, 0), *interest, pitEntry);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700107
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +0000108 size_t nSent = strategy.sendInterestHistory.size();
109 if (nSent > nSentLast) {
110 // Multicast strategy should multicast the interest to other two faces
111 BOOST_CHECK_EQUAL(nSent - nSentLast, 2);
Davide Pesavento3dade002019-03-19 11:29:56 -0600112 auto timeSent = time::steady_clock::now();
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +0000113 BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
114 nSentLast = nSent;
115 timeSentLast = timeSent;
116 }
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700117
Davide Pesavento3dade002019-03-19 11:29:56 -0600118 retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4);
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +0000119 };
120 periodicalRetxFrom4();
121 this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16);
Davide Pesavento3dade002019-03-19 11:29:56 -0600122 retxFrom4Evt.cancel();
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700123}
124
125BOOST_AUTO_TEST_CASE(RejectLoopback)
126{
Junxiao Shia6de4292016-07-12 02:08:10 +0000127 fib::Entry& fibEntry = *fib.insert(Name()).first;
ashiqopu3ad49db2018-10-20 22:38:47 +0000128 fibEntry.addOrUpdateNextHop(*face1, 0, 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700129
130 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700131 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
ashiqopud3ae85d2019-02-17 02:29:55 +0000132 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700133
ashiqopuc7079482019-02-20 05:34:37 +0000134 strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700135 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
136 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700137}
138
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700139BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
140BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700141
142} // namespace tests
143} // namespace fw
144} // namespace nfd