blob: 14b138d063c9a18642153e0e703515559b1bb417 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -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 "client-control-strategy.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06008#include "core/logger.hpp"
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07009
10namespace nfd {
11namespace fw {
12
13NFD_LOG_INIT("ClientControlStrategy");
14
Junxiao Shif3c07812014-03-11 21:48:49 -070015const Name ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control");
16
17ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name)
18 : BestRouteStrategy(forwarder, name)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070019{
20}
21
22ClientControlStrategy::~ClientControlStrategy()
23{
24}
25
26void
27ClientControlStrategy::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