blob: ab8e12a2c984c609888fd0951ac3502a4cac1603 [file] [log] [blame]
Junxiao Shi67ba8d22015-08-21 21:21:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande90015992017-07-11 17:25:48 -05002/*
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -04003 * Copyright (c) 2014-2022, 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 "multicast-strategy.hpp"
Junxiao Shi00dc9142016-11-21 14:23:12 +000027#include "algorithm.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040028#include "common/logger.hpp"
Junxiao Shi67ba8d22015-08-21 21:21:28 -070029
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040030namespace nfd::fw {
Junxiao Shi67ba8d22015-08-21 21:21:28 -070031
Junxiao Shi67ba8d22015-08-21 21:21:28 -070032NFD_REGISTER_STRATEGY(MulticastStrategy);
33
Davide Pesaventoa3148082018-04-12 18:21:54 -040034NFD_LOG_INIT(MulticastStrategy);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000035
Junxiao Shi67ba8d22015-08-21 21:21:28 -070036MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000037 : Strategy(forwarder)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070038{
Junxiao Shi18739c42016-12-22 08:03:00 +000039 ParsedInstanceName parsed = parseInstanceName(name);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000040 if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050041 NDN_THROW(std::invalid_argument(
Alexander Afanasyev0c63c632017-12-05 11:17:09 -050042 "MulticastStrategy does not support version " + to_string(*parsed.version)));
Junxiao Shi91f6ee02016-12-29 21:44:44 +000043 }
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040044
45 StrategyParameters params = parseParameters(parsed.parameters);
46 m_retxSuppression = RetxSuppressionExponential::construct(params);
47
Junxiao Shi18739c42016-12-22 08:03:00 +000048 this->setInstanceName(makeInstanceName(name, getStrategyName()));
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040049
50 NDN_LOG_DEBUG(*m_retxSuppression);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070051}
52
Junxiao Shi037f4ab2016-12-13 04:27:06 +000053const Name&
54MulticastStrategy::getStrategyName()
55{
Eric Newberry358414d2021-03-21 20:56:42 -070056 static const auto strategyName = Name("/localhost/nfd/strategy/multicast").appendVersion(4);
Junxiao Shi037f4ab2016-12-13 04:27:06 +000057 return strategyName;
58}
59
Junxiao Shi67ba8d22015-08-21 21:21:28 -070060void
Davide Pesavento0498ce82021-06-14 02:02:21 -040061MulticastStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000062 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070063{
Junxiao Shi8d843142016-07-11 22:42:42 +000064 const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
65 const fib::NextHopList& nexthops = fibEntry.getNextHops();
Junxiao Shi67ba8d22015-08-21 21:21:28 -070066
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000067 for (const auto& nexthop : nexthops) {
68 Face& outFace = nexthop.getFace();
69
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040070 RetxSuppressionResult suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -050071
72 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
ashiqopuc7079482019-02-20 05:34:37 +000073 NFD_LOG_DEBUG(interest << " from=" << ingress << " to=" << outFace.getId() << " suppressed");
Ashlesh Gawande90015992017-07-11 17:25:48 -050074 continue;
75 }
76
Ashlesh Gawandec1d48372020-08-02 22:30:11 -070077 if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
Teng Liangf995f382017-04-04 22:09:39 +000078 continue;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070079 }
Teng Liangf995f382017-04-04 22:09:39 +000080
ashiqopuc7079482019-02-20 05:34:37 +000081 NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
Davide Pesavento0498ce82021-06-14 02:02:21 -040082 auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -050083 if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040084 m_retxSuppression->incrementIntervalForOutRecord(*sentOutRecord);
Ashlesh Gawande90015992017-07-11 17:25:48 -050085 }
Junxiao Shi67ba8d22015-08-21 21:21:28 -070086 }
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000087}
88
Alexander Afanasyev40604e32021-02-17 12:06:26 -050089void
90MulticastStrategy::afterNewNextHop(const fib::NextHop& nextHop,
91 const shared_ptr<pit::Entry>& pitEntry)
92{
93 // no need to check for suppression, as it is a new next hop
94
95 auto nextHopFaceId = nextHop.getFace().getId();
96 auto& interest = pitEntry->getInterest();
97
98 // try to find an incoming face record that doesn't violate scope restrictions
99 for (const auto& r : pitEntry->getInRecords()) {
100 auto& inFace = r.getFace();
101 if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
102
103 NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " pitEntry-to=" << nextHopFaceId);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400104 this->sendInterest(interest, nextHop.getFace(), pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -0500105
106 break; // just one eligible incoming face record is enough
107 }
108 }
109
110 // if nothing found, the interest will not be forwarded
111}
112
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400113} // namespace nfd::fw