blob: 85b05354406765a2c61c857c80bd34a61ecf21d8 [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/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, 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 Pesavento2c9d2ca2024-01-27 16:36:51 -050041 NDN_THROW(std::invalid_argument("MulticastStrategy does not support version " +
42 std::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{
Mark Theeranantachai195b78a2024-02-14 20:54:44 -050056 static const auto strategyName = Name("/localhost/nfd/strategy/multicast").appendVersion(5);
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
Alex Lane653eb072023-07-27 22:11:46 -040070 auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -050071 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
Alex Lane653eb072023-07-27 22:11:46 -040072 NFD_LOG_INTEREST_FROM(interest, ingress, "to=" << outFace.getId() << " suppressed");
Ashlesh Gawande90015992017-07-11 17:25:48 -050073 continue;
74 }
75
Ashlesh Gawandec1d48372020-08-02 22:30:11 -070076 if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
Teng Liangf995f382017-04-04 22:09:39 +000077 continue;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070078 }
Teng Liangf995f382017-04-04 22:09:39 +000079
Alex Lane653eb072023-07-27 22:11:46 -040080 NFD_LOG_INTEREST_FROM(interest, ingress, "to=" << outFace.getId());
Davide Pesavento0498ce82021-06-14 02:02:21 -040081 auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -050082 if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040083 m_retxSuppression->incrementIntervalForOutRecord(*sentOutRecord);
Ashlesh Gawande90015992017-07-11 17:25:48 -050084 }
Junxiao Shi67ba8d22015-08-21 21:21:28 -070085 }
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000086}
87
Alexander Afanasyev40604e32021-02-17 12:06:26 -050088void
89MulticastStrategy::afterNewNextHop(const fib::NextHop& nextHop,
90 const shared_ptr<pit::Entry>& pitEntry)
91{
92 // no need to check for suppression, as it is a new next hop
93
94 auto nextHopFaceId = nextHop.getFace().getId();
Alex Lane653eb072023-07-27 22:11:46 -040095 const auto& interest = pitEntry->getInterest();
Alexander Afanasyev40604e32021-02-17 12:06:26 -050096
97 // try to find an incoming face record that doesn't violate scope restrictions
98 for (const auto& r : pitEntry->getInRecords()) {
99 auto& inFace = r.getFace();
Alex Lane653eb072023-07-27 22:11:46 -0400100
Alexander Afanasyev40604e32021-02-17 12:06:26 -0500101 if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
Alex Lane653eb072023-07-27 22:11:46 -0400102 NFD_LOG_INTEREST_FROM(interest, inFace.getId(), "new-nexthop to=" << nextHopFaceId);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400103 this->sendInterest(interest, nextHop.getFace(), pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -0500104 break; // just one eligible incoming face record is enough
105 }
106 }
107
108 // if nothing found, the interest will not be forwarded
109}
110
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400111} // namespace nfd::fw