multicast-strategy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, Regents of the University of California,
4  * 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"
27 #include "algorithm.hpp"
28 #include "common/logger.hpp"
29 
30 namespace nfd::fw {
31 
33 
35 
36 MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
37  : Strategy(forwarder)
38 {
40  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
41  NDN_THROW(std::invalid_argument("MulticastStrategy does not support version " +
42  std::to_string(*parsed.version)));
43  }
44 
46  m_retxSuppression = RetxSuppressionExponential::construct(params);
47 
49 
50  NDN_LOG_DEBUG(*m_retxSuppression);
51 }
52 
53 const Name&
55 {
56  static const auto strategyName = Name("/localhost/nfd/strategy/multicast").appendVersion(5);
57  return strategyName;
58 }
59 
60 void
61 MulticastStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
62  const shared_ptr<pit::Entry>& pitEntry)
63 {
64  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
65  const fib::NextHopList& nexthops = fibEntry.getNextHops();
66 
67  for (const auto& nexthop : nexthops) {
68  Face& outFace = nexthop.getFace();
69 
70  auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace);
71  if (suppressResult == RetxSuppressionResult::SUPPRESS) {
72  NFD_LOG_INTEREST_FROM(interest, ingress, "to=" << outFace.getId() << " suppressed");
73  continue;
74  }
75 
76  if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
77  continue;
78  }
79 
80  NFD_LOG_INTEREST_FROM(interest, ingress, "to=" << outFace.getId());
81  auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
82  if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
83  m_retxSuppression->incrementIntervalForOutRecord(*sentOutRecord);
84  }
85  }
86 }
87 
88 void
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();
95  const auto& interest = pitEntry->getInterest();
96 
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();
100 
101  if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
102  NFD_LOG_INTEREST_FROM(interest, inFace.getId(), "new-nexthop to=" << nextHopFaceId);
103  this->sendInterest(interest, nextHop.getFace(), pitEntry);
104  break; // just one eligible incoming face record is enough
105  }
106  }
107 
108  // if nothing found, the interest will not be forwarded
109 }
110 
111 } // namespace nfd::fw
This file contains common algorithms used by forwarding strategies.
Represents a face-endpoint pair in the forwarder.
Main class of NFD's forwarding engine.
Definition: forwarder.hpp:54
Generalization of a network interface.
Definition: face.hpp:118
FaceId getId() const noexcept
Returns the face ID.
Definition: face.hpp:195
Represents an entry in the FIB.
Definition: fib-entry.hpp:91
const NextHopList & getNextHops() const noexcept
Definition: fib-entry.hpp:103
Represents a nexthop record in a FIB entry.
Definition: fib-entry.hpp:50
Face & getFace() const noexcept
Definition: fib-entry.hpp:59
A forwarding strategy that forwards Interests to all FIB nexthops.
MulticastStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
void afterNewNextHop(const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after a new nexthop is added.
static const Name & getStrategyName()
void afterReceiveInterest(const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after an Interest is received.
static std::unique_ptr< RetxSuppressionExponential > construct(const StrategyParameters &params)
Base class of all forwarding strategies.
Definition: strategy.hpp:46
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
Definition: strategy.cpp:313
pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
Definition: strategy.cpp:236
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
Definition: strategy.cpp:123
void setInstanceName(const Name &name) noexcept
Set strategy instance name.
Definition: strategy.hpp:448
static StrategyParameters parseParameters(const PartialName &params)
Parse strategy parameters encoded in a strategy instance name.
Definition: strategy.cpp:144
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
Definition: strategy.cpp:134
#define NFD_LOG_INIT(name)
Definition: logger.hpp:31
std::vector< NextHop > NextHopList
A collection of nexthops in a FIB entry.
Definition: fib-entry.hpp:84
@ SUPPRESS
Interest is a retransmission and should be suppressed.
@ FORWARD
Interest is a retransmission and should be forwarded.
bool isNextHopEligible(const Face &inFace, const Interest &interest, const fib::NextHop &nexthop, const shared_ptr< pit::Entry > &pitEntry, bool wantUnused, time::steady_clock::time_point now)
Determines whether a NextHop is eligible, i.e., not the same inFace.
Definition: algorithm.cpp:131
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
#define NFD_LOG_INTEREST_FROM(interest, ingress, msg)
Logs the reception of interest on ingress, followed by msg, at DEBUG level.
Definition: strategy.hpp:542
std::optional< uint64_t > version
The strategy version number, if present.
Definition: strategy.hpp:420
PartialName parameters
Parameter components, may be empty.
Definition: strategy.hpp:421