multicast-strategy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "multicast-strategy.hpp"
27 #include "algorithm.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 
32 NFD_REGISTER_STRATEGY(MulticastStrategy);
33 
34 MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
35  : Strategy(forwarder)
36 {
38  if (!parsed.parameters.empty()) {
39  BOOST_THROW_EXCEPTION(std::invalid_argument("MulticastStrategy does not accept parameters"));
40  }
41  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
42  BOOST_THROW_EXCEPTION(std::invalid_argument(
43  "MulticastStrategy does not support version " + std::to_string(*parsed.version)));
44  }
46 }
47 
48 const Name&
50 {
51  static Name strategyName("/localhost/nfd/strategy/multicast/%FD%01");
52  return strategyName;
53 }
54 
55 void
56 MulticastStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest,
57  const shared_ptr<pit::Entry>& pitEntry)
58 {
59  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
60  const fib::NextHopList& nexthops = fibEntry.getNextHops();
61 
62  for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
63  Face& outFace = it->getFace();
64  if (!wouldViolateScope(inFace, interest, outFace) &&
65  canForwardToLegacy(*pitEntry, outFace)) {
66  this->sendInterest(pitEntry, outFace, interest);
67  }
68  }
69 
70  if (!hasPendingOutRecords(*pitEntry)) {
71  this->rejectPendingInterest(pitEntry);
72  }
73 }
74 
75 } // namespace fw
76 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
Definition: algorithm.cpp:59
main class of NFD
Definition: forwarder.hpp:52
void setInstanceName(const Name &name)
set strategy instance name
Definition: strategy.hpp:290
represents a FIB entry
Definition: fib-entry.hpp:51
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
Definition: strategy.hpp:191
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
Definition: strategy.cpp:132
static const Name & getStrategyName()
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
#define NFD_REGISTER_STRATEGY(S)
registers a strategy
Definition: strategy.hpp:328
std::vector< fib::NextHop > NextHopList
Definition: fib-entry.hpp:47
MulticastStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
PartialName parameters
parameter components
Definition: strategy.hpp:263
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:113
ndn::optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:262
represents a forwarding strategy
Definition: strategy.hpp:37
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
Definition: strategy.cpp:121
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
const NextHopList & getNextHops() const
Definition: fib-entry.hpp:64
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:204
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:196