NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
best-route-strategy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "best-route-strategy.hpp"
27 #include "algorithm.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 
33  : Strategy(forwarder)
34 {
35 }
36 
37 void
39  const shared_ptr<pit::Entry>& pitEntry)
40 {
41  if (hasPendingOutRecords(*pitEntry)) {
42  // not a new Interest, don't forward
43  return;
44  }
45 
46  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
47  const fib::NextHopList& nexthops = fibEntry.getNextHops();
48 
49  for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
50  Face& outFace = it->getFace();
51  if (!wouldViolateScope(inFace, interest, outFace) &&
52  canForwardToLegacy(*pitEntry, outFace)) {
53  this->sendInterest(pitEntry, outFace, interest);
54  return;
55  }
56  }
57 
58  this->rejectPendingInterest(pitEntry);
59 }
60 
62 
64  : BestRouteStrategyBase(forwarder)
65 {
67  if (!parsed.parameters.empty()) {
68  BOOST_THROW_EXCEPTION(std::invalid_argument("BestRouteStrategy does not accept parameters"));
69  }
70  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
71  BOOST_THROW_EXCEPTION(std::invalid_argument(
72  "BestRouteStrategy does not support version " + std::to_string(*parsed.version)));
73  }
75 }
76 
77 const Name&
79 {
80  static Name strategyName("/localhost/nfd/strategy/best-route/%FD%01");
81  return strategyName;
82 }
83 
84 } // namespace fw
85 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
Definition: algorithm.cpp:59
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
Definition: strategy.cpp:121
represents a FIB entry
Definition: fib-entry.hpp:51
PartialName parameters
parameter components
Definition: strategy.hpp:263
main class of NFD
Definition: forwarder.hpp:54
void setInstanceName(const Name &name)
set strategy instance name
Definition: strategy.hpp:290
represents an Interest packet
Definition: interest.hpp:42
BestRouteStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
ndn::optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:262
static const Name & getStrategyName()
ndn Face
Definition: face-impl.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Best Route strategy version 1.
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
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:113
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.
BestRouteStrategyBase(Forwarder &forwarder)
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
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
void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received