Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 9 | namespace nfd { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 10 | namespace fw { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 11 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 12 | const Name BestRouteStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route"); |
| 13 | |
| 14 | BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name) |
| 15 | : Strategy(forwarder, name) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 16 | { |
| 17 | } |
| 18 | |
| 19 | BestRouteStrategy::~BestRouteStrategy() |
| 20 | { |
| 21 | } |
| 22 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 23 | static inline bool |
| 24 | predicate_PitEntry_canForwardTo_NextHop(shared_ptr<pit::Entry> pitEntry, |
| 25 | const fib::NextHop& nexthop) |
| 26 | { |
| 27 | return pitEntry->canForwardTo(*nexthop.getFace()); |
| 28 | } |
| 29 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 30 | void |
| 31 | BestRouteStrategy::afterReceiveInterest(const Face& inFace, |
| 32 | const Interest& interest, |
| 33 | shared_ptr<fib::Entry> fibEntry, |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 34 | shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 36 | if (pitEntry->hasUnexpiredOutRecords()) { |
| 37 | // not a new Interest, don't forward |
| 38 | return; |
| 39 | } |
| 40 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 41 | const fib::NextHopList& nexthops = fibEntry->getNextHops(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 42 | 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 Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 46 | this->rejectPendingInterest(pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 47 | return; |
| 48 | } |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 49 | |
| 50 | shared_ptr<Face> outFace = it->getFace(); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 51 | this->sendInterest(pitEntry, outFace); |
| 52 | } |
| 53 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 54 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 55 | } // namespace nfd |