blob: f22514a6f5be3d03aa42fad143419af26f1ffcd2 [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 Pesavento19779d82019-02-14 13:40:04 -05003 * 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 "multicast-strategy.hpp"
Junxiao Shi00dc9142016-11-21 14:23:12 +000027#include "algorithm.hpp"
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000028#include "core/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
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000037const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_INITIAL(10);
38const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_MAX(250);
39
Junxiao Shi67ba8d22015-08-21 21:21:28 -070040MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000041 : Strategy(forwarder)
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000042 , ProcessNackTraits(this)
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000043 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
44 RetxSuppressionExponential::DEFAULT_MULTIPLIER,
45 RETX_SUPPRESSION_MAX)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070046{
Junxiao Shi18739c42016-12-22 08:03:00 +000047 ParsedInstanceName parsed = parseInstanceName(name);
48 if (!parsed.parameters.empty()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050049 NDN_THROW(std::invalid_argument("MulticastStrategy does not accept parameters"));
Junxiao Shi18739c42016-12-22 08:03:00 +000050 }
Junxiao Shi91f6ee02016-12-29 21:44:44 +000051 if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050052 NDN_THROW(std::invalid_argument(
Alexander Afanasyev0c63c632017-12-05 11:17:09 -050053 "MulticastStrategy does not support version " + to_string(*parsed.version)));
Junxiao Shi91f6ee02016-12-29 21:44:44 +000054 }
Junxiao Shi18739c42016-12-22 08:03:00 +000055 this->setInstanceName(makeInstanceName(name, getStrategyName()));
Junxiao Shi67ba8d22015-08-21 21:21:28 -070056}
57
Junxiao Shi037f4ab2016-12-13 04:27:06 +000058const Name&
59MulticastStrategy::getStrategyName()
60{
Teng Liangf995f382017-04-04 22:09:39 +000061 static Name strategyName("/localhost/nfd/strategy/multicast/%FD%03");
Junxiao Shi037f4ab2016-12-13 04:27:06 +000062 return strategyName;
63}
64
Junxiao Shi67ba8d22015-08-21 21:21:28 -070065void
ashiqopuc7079482019-02-20 05:34:37 +000066MulticastStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi15e98b02016-08-12 11:21:44 +000067 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070068{
Junxiao Shi8d843142016-07-11 22:42:42 +000069 const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
70 const fib::NextHopList& nexthops = fibEntry.getNextHops();
Junxiao Shi67ba8d22015-08-21 21:21:28 -070071
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000072 int nEligibleNextHops = 0;
73
Ashlesh Gawande90015992017-07-11 17:25:48 -050074 bool isSuppressed = false;
75
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000076 for (const auto& nexthop : nexthops) {
77 Face& outFace = nexthop.getFace();
78
Ashlesh Gawande90015992017-07-11 17:25:48 -050079 RetxSuppressionResult suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace);
80
81 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
ashiqopuc7079482019-02-20 05:34:37 +000082 NFD_LOG_DEBUG(interest << " from=" << ingress << " to=" << outFace.getId() << " suppressed");
Ashlesh Gawande90015992017-07-11 17:25:48 -050083 isSuppressed = true;
84 continue;
85 }
86
ashiqopuc7079482019-02-20 05:34:37 +000087 if ((outFace.getId() == ingress.face.getId() && outFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) ||
88 wouldViolateScope(ingress.face, interest, outFace)) {
Teng Liangf995f382017-04-04 22:09:39 +000089 continue;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070090 }
Teng Liangf995f382017-04-04 22:09:39 +000091
ashiqopuc7079482019-02-20 05:34:37 +000092 this->sendInterest(pitEntry, FaceEndpoint(outFace, 0), interest);
93 NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
Ashlesh Gawande90015992017-07-11 17:25:48 -050094
95 if (suppressResult == RetxSuppressionResult::FORWARD) {
ashiqopud3ae85d2019-02-17 02:29:55 +000096 m_retxSuppression.incrementIntervalForOutRecord(*pitEntry->getOutRecord(outFace, 0));
Ashlesh Gawande90015992017-07-11 17:25:48 -050097 }
Teng Liangf995f382017-04-04 22:09:39 +000098 ++nEligibleNextHops;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070099 }
100
Ashlesh Gawande90015992017-07-11 17:25:48 -0500101 if (nEligibleNextHops == 0 && !isSuppressed) {
ashiqopuc7079482019-02-20 05:34:37 +0000102 NFD_LOG_DEBUG(interest << " from=" << ingress << " noNextHop");
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000103
Ashlesh Gawande90015992017-07-11 17:25:48 -0500104 lp::NackHeader nackHeader;
105 nackHeader.setReason(lp::NackReason::NO_ROUTE);
ashiqopuc7079482019-02-20 05:34:37 +0000106 this->sendNack(pitEntry, ingress, nackHeader);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000107
Ashlesh Gawande90015992017-07-11 17:25:48 -0500108 this->rejectPendingInterest(pitEntry);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700109 }
110}
111
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000112void
ashiqopuc7079482019-02-20 05:34:37 +0000113MulticastStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000114 const shared_ptr<pit::Entry>& pitEntry)
115{
ashiqopuc7079482019-02-20 05:34:37 +0000116 this->processNack(ingress.face, nack, pitEntry);
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000117}
118
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700119} // namespace fw
120} // namespace nfd