blob: 502887931b6f0fd95d29d0529f6f353ae64fdaf9 [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"
8
9namespace nfd {
10namespace fw {
11
12NFD_LOG_INIT("ClientControlStrategy");
13
Junxiao Shif3c07812014-03-11 21:48:49 -070014const Name ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control");
15
16ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name)
17 : BestRouteStrategy(forwarder, name)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070018{
19}
20
21ClientControlStrategy::~ClientControlStrategy()
22{
23}
24
25void
26ClientControlStrategy::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