blob: f49f60a33bd5dac5685496fdfa6747aeb5d254fb [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
30namespace nfd {
31namespace fw {
32
Junxiao Shi67ba8d22015-08-21 21:21:28 -070033NFD_REGISTER_STRATEGY(MulticastStrategy);
34
Davide Pesaventoa3148082018-04-12 18:21:54 -040035NFD_LOG_INIT(MulticastStrategy);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000036
Junxiao Shi67ba8d22015-08-21 21:21:28 -070037MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000038 : Strategy(forwarder)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070039{
Junxiao Shi18739c42016-12-22 08:03:00 +000040 ParsedInstanceName parsed = parseInstanceName(name);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000041 if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050042 NDN_THROW(std::invalid_argument(
Alexander Afanasyev0c63c632017-12-05 11:17:09 -050043 "MulticastStrategy does not support version " + to_string(*parsed.version)));
Junxiao Shi91f6ee02016-12-29 21:44:44 +000044 }
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040045
46 StrategyParameters params = parseParameters(parsed.parameters);
47 m_retxSuppression = RetxSuppressionExponential::construct(params);
48
Junxiao Shi18739c42016-12-22 08:03:00 +000049 this->setInstanceName(makeInstanceName(name, getStrategyName()));
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040050
51 NDN_LOG_DEBUG(*m_retxSuppression);
Junxiao Shi67ba8d22015-08-21 21:21:28 -070052}
53
Junxiao Shi037f4ab2016-12-13 04:27:06 +000054const Name&
55MulticastStrategy::getStrategyName()
56{
Eric Newberry358414d2021-03-21 20:56:42 -070057 static const auto strategyName = Name("/localhost/nfd/strategy/multicast").appendVersion(4);
Junxiao Shi037f4ab2016-12-13 04:27:06 +000058 return strategyName;
59}
60
Junxiao Shi67ba8d22015-08-21 21:21:28 -070061void
Davide Pesavento0498ce82021-06-14 02:02:21 -040062MulticastStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000063 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070064{
Junxiao Shi8d843142016-07-11 22:42:42 +000065 const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
66 const fib::NextHopList& nexthops = fibEntry.getNextHops();
Junxiao Shi67ba8d22015-08-21 21:21:28 -070067
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000068 for (const auto& nexthop : nexthops) {
69 Face& outFace = nexthop.getFace();
70
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040071 RetxSuppressionResult suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -050072
73 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
ashiqopuc7079482019-02-20 05:34:37 +000074 NFD_LOG_DEBUG(interest << " from=" << ingress << " to=" << outFace.getId() << " suppressed");
Ashlesh Gawande90015992017-07-11 17:25:48 -050075 continue;
76 }
77
Ashlesh Gawandec1d48372020-08-02 22:30:11 -070078 if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
Teng Liangf995f382017-04-04 22:09:39 +000079 continue;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070080 }
Teng Liangf995f382017-04-04 22:09:39 +000081
ashiqopuc7079482019-02-20 05:34:37 +000082 NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
Davide Pesavento0498ce82021-06-14 02:02:21 -040083 auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -050084 if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040085 m_retxSuppression->incrementIntervalForOutRecord(*sentOutRecord);
Ashlesh Gawande90015992017-07-11 17:25:48 -050086 }
Junxiao Shi67ba8d22015-08-21 21:21:28 -070087 }
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000088}
89
Alexander Afanasyev40604e32021-02-17 12:06:26 -050090void
91MulticastStrategy::afterNewNextHop(const fib::NextHop& nextHop,
92 const shared_ptr<pit::Entry>& pitEntry)
93{
94 // no need to check for suppression, as it is a new next hop
95
96 auto nextHopFaceId = nextHop.getFace().getId();
97 auto& interest = pitEntry->getInterest();
98
99 // try to find an incoming face record that doesn't violate scope restrictions
100 for (const auto& r : pitEntry->getInRecords()) {
101 auto& inFace = r.getFace();
102 if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
103
104 NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " pitEntry-to=" << nextHopFaceId);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400105 this->sendInterest(interest, nextHop.getFace(), pitEntry);
Alexander Afanasyev40604e32021-02-17 12:06:26 -0500106
107 break; // just one eligible incoming face record is enough
108 }
109 }
110
111 // if nothing found, the interest will not be forwarded
112}
113
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700114} // namespace fw
115} // namespace nfd