NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2021, 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 
34 
36 
37 const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_INITIAL(10);
38 const time::milliseconds MulticastStrategy::RETX_SUPPRESSION_MAX(250);
39 
41  : Strategy(forwarder)
42  , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
43  RetxSuppressionExponential::DEFAULT_MULTIPLIER,
44  RETX_SUPPRESSION_MAX)
45 {
47  if (!parsed.parameters.empty()) {
48  NDN_THROW(std::invalid_argument("MulticastStrategy does not accept parameters"));
49  }
50  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
51  NDN_THROW(std::invalid_argument(
52  "MulticastStrategy does not support version " + to_string(*parsed.version)));
53  }
55 }
56 
57 const Name&
59 {
60  static const auto strategyName = Name("/localhost/nfd/strategy/multicast").appendVersion(4);
61  return strategyName;
62 }
63 
64 void
66  const shared_ptr<pit::Entry>& pitEntry)
67 {
68  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
69  const fib::NextHopList& nexthops = fibEntry.getNextHops();
70 
71  for (const auto& nexthop : nexthops) {
72  Face& outFace = nexthop.getFace();
73 
74  RetxSuppressionResult suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace);
75 
76  if (suppressResult == RetxSuppressionResult::SUPPRESS) {
77  NFD_LOG_DEBUG(interest << " from=" << ingress << " to=" << outFace.getId() << " suppressed");
78  continue;
79  }
80 
81  if (!isNextHopEligible(ingress.face, interest, nexthop, pitEntry)) {
82  continue;
83  }
84 
85  NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
86  auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
87  if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
88  m_retxSuppression.incrementIntervalForOutRecord(*sentOutRecord);
89  }
90  }
91 }
92 
93 void
95  const shared_ptr<pit::Entry>& pitEntry)
96 {
97  // no need to check for suppression, as it is a new next hop
98 
99  auto nextHopFaceId = nextHop.getFace().getId();
100  auto& interest = pitEntry->getInterest();
101 
102  // try to find an incoming face record that doesn't violate scope restrictions
103  for (const auto& r : pitEntry->getInRecords()) {
104  auto& inFace = r.getFace();
105  if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
106 
107  NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " pitEntry-to=" << nextHopFaceId);
108  this->sendInterest(interest, nextHop.getFace(), pitEntry);
109 
110  break; // just one eligible incoming face record is enough
111  }
112  }
113 
114  // if nothing found, the interest will not be forwarded
115 }
116 
117 } // namespace fw
118 } // namespace nfd
Interest is retransmission and should be forwarded.
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
Definition: strategy.cpp:123
void afterNewNextHop(const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after a new nexthop is added.
void afterReceiveInterest(const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after an Interest is received.
#define NFD_LOG_INIT(name)
Definition: logger.hpp:31
std::string to_string(const T &val)
Definition: backports.hpp:86
MulticastStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
Represents a face-endpoint pair in the forwarder.
represents a FIB entry
Definition: fib-entry.hpp:53
PartialName parameters
parameter components
Definition: strategy.hpp:390
Main class of NFD&#39;s forwarding engine.
Definition: forwarder.hpp:53
RetxSuppressionResult decidePerUpstream(pit::Entry &pitEntry, Face &outFace)
determines whether Interest is a retransmission per upstream and if so, whether it shall be forwarded...
Interest is retransmission and should be suppressed.
void setInstanceName(const Name &name)
Set strategy instance name.
Definition: strategy.hpp:417
Represents an Interest packet.
Definition: interest.hpp:48
Represents a collection of nexthops.
Definition: fib-entry.hpp:39
static const Name & getStrategyName()
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn Face
Definition: face-impl.hpp:42
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
void incrementIntervalForOutRecord(pit::OutRecord &outRecord)
Increment the suppression interval for out record.
#define NFD_LOG_DEBUG
Definition: logger.hpp:38
NFD_REGISTER_STRATEGY(AccessStrategy)
Represents an absolute name.
Definition: name.hpp:41
Represents a forwarding strategy.
Definition: strategy.hpp:38
A forwarding strategy that forwards Interests to all FIB nexthops.
optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:389
This file contains common algorithms used by forwarding strategies.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
Definition: strategy.cpp:331
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)
Definition: algorithm.cpp:131
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
Definition: strategy.cpp:134
const NextHopList & getNextHops() const
Definition: fib-entry.hpp:66
NFD_VIRTUAL_WITH_TESTS pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
Definition: strategy.cpp:237
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
Face & getFace() const
Definition: fib-nexthop.hpp:47
Represents a nexthop record in a FIB entry.
Definition: fib-nexthop.hpp:37
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48