blob: 7b38bc1af6db665780fce3d718e60ef36c9f907c [file] [log] [blame]
Junxiao Shi67ba8d22015-08-21 21:21:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawandee38e2612017-02-25 07:23:41 +00003 * Copyright (c) 2014-2017, 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
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000035NFD_LOG_INIT("MulticastStrategy");
36
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()) {
49 BOOST_THROW_EXCEPTION(std::invalid_argument("MulticastStrategy does not accept parameters"));
50 }
Junxiao Shi91f6ee02016-12-29 21:44:44 +000051 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 }
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
Junxiao Shi15e98b02016-08-12 11:21:44 +000066MulticastStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest,
67 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi67ba8d22015-08-21 21:21:28 -070068{
Ashlesh Gawandeecdbe5f2017-03-04 03:08:24 +000069 // Should the Interest be suppressed?
70 RetxSuppression::Result suppressResult = m_retxSuppression.decide(inFace, interest, *pitEntry);
71 switch (suppressResult) {
72 case RetxSuppression::NEW:
73 case RetxSuppression::FORWARD:
74 break;
75 case RetxSuppression::SUPPRESS:
76 NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " suppressed");
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000077 return;
78 }
79
Junxiao Shi8d843142016-07-11 22:42:42 +000080 const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
81 const fib::NextHopList& nexthops = fibEntry.getNextHops();
Junxiao Shi67ba8d22015-08-21 21:21:28 -070082
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000083 int nEligibleNextHops = 0;
84
85 for (const auto& nexthop : nexthops) {
86 Face& outFace = nexthop.getFace();
87
Teng Liangf995f382017-04-04 22:09:39 +000088 if ((outFace.getId() == inFace.getId() && outFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) ||
89 wouldViolateScope(inFace, interest, outFace)) {
90 continue;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070091 }
Teng Liangf995f382017-04-04 22:09:39 +000092
93 this->sendInterest(pitEntry, outFace, interest);
94 NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
95 << " pitEntry-to=" << outFace.getId());
96 ++nEligibleNextHops;
Junxiao Shi67ba8d22015-08-21 21:21:28 -070097 }
98
Ashlesh Gawandee38e2612017-02-25 07:23:41 +000099 if (nEligibleNextHops == 0) {
100 NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop");
101
102 lp::NackHeader nackHeader;
103 nackHeader.setReason(lp::NackReason::NO_ROUTE);
104 this->sendNack(pitEntry, inFace, nackHeader);
105
106 this->rejectPendingInterest(pitEntry);
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700107 }
108}
109
Ashlesh Gawandee38e2612017-02-25 07:23:41 +0000110void
111MulticastStrategy::afterReceiveNack(const Face& inFace, const lp::Nack& nack,
112 const shared_ptr<pit::Entry>& pitEntry)
113{
114 this->processNack(inFace, nack, pitEntry);
115}
116
Junxiao Shi67ba8d22015-08-21 21:21:28 -0700117} // namespace fw
118} // namespace nfd