blob: 0b1c5f5e84605364f00d0abe76a0e8517eff7b25 [file] [log] [blame]
Junxiao Shi2d9bdc82014-03-02 20:55:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi8d843142016-07-11 22:42:42 +00003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shifaf3eb02015-02-16 10:50:36 -07004 * 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 Shicbc8e942016-09-06 03:17:45 +000028#include <ndn-cxx/lp/tags.hpp>
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070029
30namespace nfd {
31namespace fw {
32
33NFD_LOG_INIT("ClientControlStrategy");
34
Junxiao Shie93d6a32014-09-07 16:13:22 -070035const Name
36ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control/%FD%01");
Junxiao Shifaf3eb02015-02-16 10:50:36 -070037NFD_REGISTER_STRATEGY(ClientControlStrategy);
Junxiao Shif3c07812014-03-11 21:48:49 -070038
39ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name)
40 : BestRouteStrategy(forwarder, name)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070041{
42}
43
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070044void
Junxiao Shi15e98b02016-08-12 11:21:44 +000045ClientControlStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest,
46 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070047{
Junxiao Shi0de23a22015-12-03 20:07:02 +000048 shared_ptr<lp::NextHopFaceIdTag> tag = interest.getTag<lp::NextHopFaceIdTag>();
49 if (tag == nullptr) {
Junxiao Shi8d843142016-07-11 22:42:42 +000050 this->BestRouteStrategy::afterReceiveInterest(inFace, interest, pitEntry);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070051 return;
52 }
53
Junxiao Shi0de23a22015-12-03 20:07:02 +000054 FaceId outFaceId = static_cast<FaceId>(*tag);
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000055 Face* outFace = this->getFace(outFaceId);
Junxiao Shicde37ad2015-12-24 01:02:05 -070056 if (outFace == nullptr) {
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070057 // If outFace doesn't exist, it's better to reject the Interest
58 // than to use BestRouteStrategy.
59 NFD_LOG_WARN("Interest " << interest.getName() <<
60 " NextHopFaceId=" << outFaceId << " non-existent face");
61 this->rejectPendingInterest(pitEntry);
62 return;
63 }
64
Junxiao Shia6de4292016-07-12 02:08:10 +000065 this->sendInterest(pitEntry, *outFace);
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070066}
67
68} // namespace fw
69} // namespace nfd