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-2020, 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 {
31 namespace fw {
32 
33 NFD_REGISTER_STRATEGY(MulticastStrategy);
34 
35 NFD_LOG_INIT(MulticastStrategy);
36 
37 const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_INITIAL(10);
38 const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_MAX(250);
39 
40 MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
41  : Strategy(forwarder)
42  , ProcessNackTraits(this)
43  , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
44  RetxSuppressionExponential::DEFAULT_MULTIPLIER,
45  RETX_SUPPRESSION_MAX)
46 {
48  if (!parsed.parameters.empty()) {
49  NDN_THROW(std::invalid_argument("MulticastStrategy does not accept parameters"));
50  }
51  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
52  NDN_THROW(std::invalid_argument(
53  "MulticastStrategy does not support version " + to_string(*parsed.version)));
54  }
56 }
57 
58 const Name&
60 {
61  static Name strategyName("/localhost/nfd/strategy/multicast/%FD%03");
62  return strategyName;
63 }
64 
65 void
66 MulticastStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
67  const shared_ptr<pit::Entry>& pitEntry)
68 {
69  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
70  const fib::NextHopList& nexthops = fibEntry.getNextHops();
71 
72  for (const auto& nexthop : nexthops) {
73  Face& outFace = nexthop.getFace();
74 
75  RetxSuppressionResult suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace);
76 
77  if (suppressResult == RetxSuppressionResult::SUPPRESS) {
78  NFD_LOG_DEBUG(interest << " from=" << ingress << " to=" << outFace.getId() << " suppressed");
79  continue;
80  }
81 
82  if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
83  continue;
84  }
85 
86  NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
87  bool wasSent = this->sendInterest(pitEntry, outFace, interest) != nullptr;
88  if (wasSent && suppressResult == RetxSuppressionResult::FORWARD) {
89  m_retxSuppression.incrementIntervalForOutRecord(*pitEntry->getOutRecord(outFace));
90  }
91  }
92 
93  if (!hasPendingOutRecords(*pitEntry)) {
94  NFD_LOG_DEBUG(interest << " from=" << ingress << " noNextHop (removing pitEntry)");
95 
96  lp::NackHeader nackHeader;
97  nackHeader.setReason(lp::NackReason::NO_ROUTE);
98  this->sendNack(pitEntry, ingress.face, nackHeader);
99 
100  this->rejectPendingInterest(pitEntry);
101  }
102 }
103 
104 void
105 MulticastStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
106  const shared_ptr<pit::Entry>& pitEntry)
107 {
108  this->processNack(ingress.face, nack, pitEntry);
109 }
110 
111 } // namespace fw
112 } // namespace nfd
Main class of NFD&#39;s forwarding engine.
Definition: forwarder.hpp:51
Interest is retransmission and should be forwarded.
void setInstanceName(const Name &name)
Set strategy instance name.
Definition: strategy.hpp:386
bool sendNack(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const lp::NackHeader &header)
Send a Nack packet.
Definition: strategy.hpp:306
void incrementIntervalForOutRecord(pit::OutRecord &outRecord)
Increment the suppression interval for out record.
represents a FIB entry
Definition: fib-entry.hpp:53
Interest is retransmission and should be suppressed.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
Definition: strategy.cpp:134
RetxSuppressionResult decidePerUpstream(pit::Entry &pitEntry, Face &outFace)
determines whether Interest is a retransmission per upstream and if so, whether it shall be forwarded...
static const Name & getStrategyName()
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
Definition: strategy.cpp:282
Represents a face-endpoint pair in the forwarder.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
bool isNextHopEligible(const Face &inFace, const Interest &interest, const fib::NextHop &nexthop, const shared_ptr< pit::Entry > &pitEntry, bool wantUnused, time::steady_clock::TimePoint now)
determines whether a NextHop is eligible i.e.
Definition: algorithm.cpp:154
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
MulticastStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after Interest is received.
generalization of a network interface
Definition: face.hpp:54
Represents a collection of nexthops.
Definition: fib-entry.hpp:39
PartialName parameters
parameter components
Definition: strategy.hpp:359
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:108
FaceId getId() const
Definition: face.hpp:239
Represents a forwarding strategy.
Definition: strategy.hpp:37
This file contains common algorithms used by forwarding strategies.
const NextHopList & getNextHops() const
Definition: fib-entry.hpp:66
#define NFD_LOG_DEBUG
Definition: logger.hpp:38
#define NFD_LOG_INIT(name)
Definition: logger.hpp:31
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
Definition: strategy.cpp:123
void afterReceiveNack(const FaceEndpoint &ingress, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after Nack is received.
void processNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
Definition: strategy.hpp:291
pit::OutRecord * sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const Interest &interest)
Send an Interest packet.
Definition: strategy.cpp:197
optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:358