NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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-2017, 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 "core/logger.hpp"
29 
30 namespace nfd {
31 namespace fw {
32 
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 
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  BOOST_THROW_EXCEPTION(std::invalid_argument("MulticastStrategy does not accept parameters"));
50  }
51  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
52  BOOST_THROW_EXCEPTION(std::invalid_argument(
53  "MulticastStrategy does not support version " + std::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 Face& inFace, 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  int nEligibleNextHops = 0;
73 
74  bool isSuppressed = false;
75 
76  for (const auto& nexthop : nexthops) {
77  Face& outFace = nexthop.getFace();
78 
79  RetxSuppressionResult suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace);
80 
81  if (suppressResult == RetxSuppressionResult::SUPPRESS) {
82  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
83  << "to=" << outFace.getId() << " suppressed");
84  isSuppressed = true;
85  continue;
86  }
87 
88  if ((outFace.getId() == inFace.getId() && outFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) ||
89  wouldViolateScope(inFace, interest, outFace)) {
90  continue;
91  }
92 
93  this->sendInterest(pitEntry, outFace, interest);
94  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
95  << " pitEntry-to=" << outFace.getId());
96 
97  if (suppressResult == RetxSuppressionResult::FORWARD) {
98  m_retxSuppression.incrementIntervalForOutRecord(*pitEntry->getOutRecord(outFace));
99  }
100  ++nEligibleNextHops;
101  }
102 
103  if (nEligibleNextHops == 0 && !isSuppressed) {
104  NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop");
105 
106  lp::NackHeader nackHeader;
107  nackHeader.setReason(lp::NackReason::NO_ROUTE);
108  this->sendNack(pitEntry, inFace, nackHeader);
109 
110  this->rejectPendingInterest(pitEntry);
111  }
112 }
113 
114 void
116  const shared_ptr<pit::Entry>& pitEntry)
117 {
118  this->processNack(inFace, nack, pitEntry);
119 }
120 
121 } // namespace fw
122 } // namespace nfd
void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
Interest is retransmission and should be forwarded.
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
Definition: strategy.cpp:121
NackHeader & setReason(NackReason reason)
set reason code
MulticastStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
represents a FIB entry
Definition: fib-entry.hpp:51
PartialName parameters
parameter components
Definition: strategy.hpp:263
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Definition: strategy.hpp:217
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
main class of NFD
Definition: forwarder.hpp:54
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:290
represents an Interest packet
Definition: interest.hpp:42
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:55
void processNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
static const Name & getStrategyName()
ndn::optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:262
represents a Network Nack
Definition: nack.hpp:40
void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
ndn Face
Definition: face-impl.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void incrementIntervalForOutRecord(pit::OutRecord &outRecord)
Increment the suppression interval for out record.
NFD_REGISTER_STRATEGY(AccessStrategy)
std::vector< fib::NextHop > NextHopList
Definition: fib-entry.hpp:47
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:196
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:204
Represents an absolute name.
Definition: name.hpp:42
const NextHopList & getNextHops() const
Definition: fib-entry.hpp:64
represents a forwarding strategy
Definition: strategy.hpp:37
This file contains common algorithms used by forwarding strategies.
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
Definition: strategy.cpp:132
std::string to_string(const V &v)
Definition: backports.hpp:84
#define NFD_LOG_INIT(name)
Definition: logger.hpp:34
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
represents a Network NACK header
Definition: nack-header.hpp:59
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
Definition: strategy.hpp:191
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
Definition: algorithm.cpp:37