blob: ac865d0a9c8c1e61b0810cacf549c9e94dc4c8c4 [file] [log] [blame]
Junxiao Shid3c792f2014-01-30 00:46:13 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "best-route-strategy.hpp"
8
9namespace nfd {
Junxiao Shi8c8d2182014-01-30 22:33:00 -070010namespace fw {
Junxiao Shid3c792f2014-01-30 00:46:13 -070011
Junxiao Shif3c07812014-03-11 21:48:49 -070012const Name BestRouteStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route");
13
14BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name)
15 : Strategy(forwarder, name)
Junxiao Shid3c792f2014-01-30 00:46:13 -070016{
17}
18
19BestRouteStrategy::~BestRouteStrategy()
20{
21}
22
Junxiao Shi57f0f312014-03-16 11:52:20 -070023static inline bool
24predicate_PitEntry_canForwardTo_NextHop(shared_ptr<pit::Entry> pitEntry,
25 const fib::NextHop& nexthop)
26{
27 return pitEntry->canForwardTo(*nexthop.getFace());
28}
29
Junxiao Shid3c792f2014-01-30 00:46:13 -070030void
31BestRouteStrategy::afterReceiveInterest(const Face& inFace,
32 const Interest& interest,
33 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi8c8d2182014-01-30 22:33:00 -070034 shared_ptr<pit::Entry> pitEntry)
Junxiao Shid3c792f2014-01-30 00:46:13 -070035{
Junxiao Shi57f0f312014-03-16 11:52:20 -070036 if (pitEntry->hasUnexpiredOutRecords()) {
37 // not a new Interest, don't forward
38 return;
39 }
40
Junxiao Shid3c792f2014-01-30 00:46:13 -070041 const fib::NextHopList& nexthops = fibEntry->getNextHops();
Junxiao Shi57f0f312014-03-16 11:52:20 -070042 fib::NextHopList::const_iterator it = std::find_if(nexthops.begin(), nexthops.end(),
43 bind(&predicate_PitEntry_canForwardTo_NextHop, pitEntry, _1));
44
45 if (it == nexthops.end()) {
Junxiao Shi09498f02014-02-26 19:41:08 -070046 this->rejectPendingInterest(pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070047 return;
48 }
Junxiao Shi57f0f312014-03-16 11:52:20 -070049
50 shared_ptr<Face> outFace = it->getFace();
Junxiao Shid3c792f2014-01-30 00:46:13 -070051 this->sendInterest(pitEntry, outFace);
52}
53
Junxiao Shi8c8d2182014-01-30 22:33:00 -070054} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -070055} // namespace nfd