blob: d3700e34ed747836095e009e92b5b47a29c52d70 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shie93d6a32014-09-07 16:13:22 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shie93d6a32014-09-07 16:13:22 -070024 */
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070025
26#include "client-control-strategy.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060027#include "core/logger.hpp"
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070028
29namespace nfd {
30namespace fw {
31
32NFD_LOG_INIT("ClientControlStrategy");
33
Junxiao Shie93d6a32014-09-07 16:13:22 -070034const Name
35ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control/%FD%01");
Junxiao Shif3c07812014-03-11 21:48:49 -070036
37ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name)
38 : BestRouteStrategy(forwarder, name)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070039{
40}
41
42ClientControlStrategy::~ClientControlStrategy()
43{
44}
45
46void
47ClientControlStrategy::afterReceiveInterest(const Face& inFace,
48 const Interest& interest,
49 shared_ptr<fib::Entry> fibEntry,
50 shared_ptr<pit::Entry> pitEntry)
51{
52 // Strategy needn't check whether LocalControlHeader-NextHopFaceId is enabled.
53 // LocalFace does this check.
54 if (!interest.getLocalControlHeader().hasNextHopFaceId()) {
55 this->BestRouteStrategy::afterReceiveInterest(inFace, interest, fibEntry, pitEntry);
56 return;
57 }
58
59 FaceId outFaceId = static_cast<FaceId>(interest.getNextHopFaceId());
60 shared_ptr<Face> outFace = this->getFace(outFaceId);
61 if (!static_cast<bool>(outFace)) {
62 // If outFace doesn't exist, it's better to reject the Interest
63 // than to use BestRouteStrategy.
64 NFD_LOG_WARN("Interest " << interest.getName() <<
65 " NextHopFaceId=" << outFaceId << " non-existent face");
66 this->rejectPendingInterest(pitEntry);
67 return;
68 }
69
70 this->sendInterest(pitEntry, outFace);
71}
72
73} // namespace fw
74} // namespace nfd