Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Teng Liang | 6308644 | 2018-02-25 20:39:42 -0700 | [diff] [blame] | 2 | /* |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 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. |
| 10 | * |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "dummy-strategy.hpp" |
| 27 | |
| 28 | namespace nfd { |
| 29 | namespace tests { |
| 30 | |
| 31 | NFD_REGISTER_STRATEGY(DummyStrategy); |
| 32 | |
| 33 | void |
| 34 | DummyStrategy::registerAs(const Name& strategyName) |
| 35 | { |
| 36 | registerAsImpl<DummyStrategy>(strategyName); |
| 37 | } |
| 38 | |
| 39 | Name |
| 40 | DummyStrategy::getStrategyName(uint64_t version) |
| 41 | { |
| 42 | return Name("/dummy-strategy").appendVersion(version); |
| 43 | } |
| 44 | |
| 45 | DummyStrategy::DummyStrategy(Forwarder& forwarder, const Name& name) |
| 46 | : Strategy(forwarder) |
| 47 | , afterReceiveInterest_count(0) |
| 48 | , beforeSatisfyInterest_count(0) |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 49 | , afterContentStoreHit_count(0) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 50 | , afterReceiveData_count(0) |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 51 | , afterReceiveNack_count(0) |
| 52 | { |
| 53 | this->setInstanceName(name); |
| 54 | } |
| 55 | |
| 56 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 57 | DummyStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 58 | const shared_ptr<pit::Entry>& pitEntry) |
| 59 | { |
| 60 | ++afterReceiveInterest_count; |
| 61 | |
| 62 | if (interestOutFace != nullptr) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 63 | this->sendInterest(pitEntry, FaceEndpoint(*interestOutFace, 0), interest); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 64 | } |
| 65 | else { |
| 66 | this->rejectPendingInterest(pitEntry); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | DummyStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 72 | const FaceEndpoint& ingress, const Data& data) |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 73 | { |
| 74 | ++beforeSatisfyInterest_count; |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame^] | 75 | |
| 76 | Strategy::beforeSatisfyInterest(pitEntry, ingress, data); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 80 | DummyStrategy::afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 81 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 82 | { |
| 83 | ++afterContentStoreHit_count; |
| 84 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 85 | Strategy::afterContentStoreHit(pitEntry, ingress, data); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void |
| 89 | DummyStrategy::afterReceiveData(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 90 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 91 | { |
| 92 | ++afterReceiveData_count; |
| 93 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 94 | Strategy::afterReceiveData(pitEntry, ingress, data); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 98 | DummyStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 99 | const shared_ptr<pit::Entry>& pitEntry) |
| 100 | { |
| 101 | ++afterReceiveNack_count; |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame^] | 102 | |
| 103 | Strategy::afterReceiveNack(ingress, nack, pitEntry); |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | DummyStrategy::afterNewNextHop(const fib::NextHop& nextHop, const shared_ptr<pit::Entry>& pitEntry) |
| 108 | { |
| 109 | afterNewNextHopCalls.push_back(pitEntry->getName()); |
| 110 | |
| 111 | Strategy::afterNewNextHop(nextHop, pitEntry); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | } // namespace tests |
| 115 | } // namespace nfd |