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 "pit-algorithm.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 
32 const Name BestRouteStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%01");
33 NFD_REGISTER_STRATEGY(BestRouteStrategy);
34 
35 BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name)
36  : Strategy(forwarder, name)
37 {
38 }
39 
40 void
41 BestRouteStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest,
42  const shared_ptr<pit::Entry>& pitEntry)
43 {
44  if (hasPendingOutRecords(*pitEntry)) {
45  // not a new Interest, don't forward
46  return;
47  }
48 
49  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
50  const fib::NextHopList& nexthops = fibEntry.getNextHops();
51  fib::NextHopList::const_iterator it = std::find_if(nexthops.begin(), nexthops.end(),
52  [&pitEntry] (const fib::NextHop& nexthop) { return canForwardToLegacy(*pitEntry, nexthop.getFace()); });
53 
54  if (it == nexthops.end()) {
55  this->rejectPendingInterest(pitEntry);
56  return;
57  }
58 
59  Face& outFace = it->getFace();
60  this->sendInterest(pitEntry, outFace);
61 }
62 
63 } // namespace fw
64 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
#define NFD_REGISTER_STRATEGY(StrategyType)
registers a built-in strategy
main class of NFD
Definition: forwarder.hpp:52
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
represents a FIB entry
Definition: fib-entry.hpp:51
BestRouteStrategy(Forwarder &forwarder, const Name &name=STRATEGY_NAME)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
std::vector< fib::NextHop > NextHopList
Definition: fib-entry.hpp:47
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
represents a forwarding strategy
Definition: strategy.hpp:38
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, bool wantNewNonce=false)
send Interest to outFace
Definition: strategy.hpp:138
represents a nexthop record in FIB entry
Definition: fib-nexthop.hpp:38
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:151
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:91