Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -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 "client-control-strategy.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame^] | 8 | #include "core/logger.hpp" |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 9 | |
| 10 | namespace nfd { |
| 11 | namespace fw { |
| 12 | |
| 13 | NFD_LOG_INIT("ClientControlStrategy"); |
| 14 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 15 | const Name ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control"); |
| 16 | |
| 17 | ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name) |
| 18 | : BestRouteStrategy(forwarder, name) |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 19 | { |
| 20 | } |
| 21 | |
| 22 | ClientControlStrategy::~ClientControlStrategy() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | void |
| 27 | ClientControlStrategy::afterReceiveInterest(const Face& inFace, |
| 28 | const Interest& interest, |
| 29 | shared_ptr<fib::Entry> fibEntry, |
| 30 | shared_ptr<pit::Entry> pitEntry) |
| 31 | { |
| 32 | // Strategy needn't check whether LocalControlHeader-NextHopFaceId is enabled. |
| 33 | // LocalFace does this check. |
| 34 | if (!interest.getLocalControlHeader().hasNextHopFaceId()) { |
| 35 | this->BestRouteStrategy::afterReceiveInterest(inFace, interest, fibEntry, pitEntry); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | FaceId outFaceId = static_cast<FaceId>(interest.getNextHopFaceId()); |
| 40 | shared_ptr<Face> outFace = this->getFace(outFaceId); |
| 41 | if (!static_cast<bool>(outFace)) { |
| 42 | // If outFace doesn't exist, it's better to reject the Interest |
| 43 | // than to use BestRouteStrategy. |
| 44 | NFD_LOG_WARN("Interest " << interest.getName() << |
| 45 | " NextHopFaceId=" << outFaceId << " non-existent face"); |
| 46 | this->rejectPendingInterest(pitEntry); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | this->sendInterest(pitEntry, outFace); |
| 51 | } |
| 52 | |
| 53 | } // namespace fw |
| 54 | } // namespace nfd |