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