Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [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 | /* |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, Regents of the University of California, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 25 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 26 | #ifndef NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP |
| 27 | #define NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 28 | |
| 29 | #include "fw/strategy.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace tests { |
| 33 | |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 34 | /** \brief Forwarding strategy for unit testing |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 35 | * |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 36 | * Triggers are recorded but do nothing. |
| 37 | * |
| 38 | * DummyStrategy registers itself as /dummy-strategy/<max-version>, so that it can be instantiated |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 39 | * with any version number. Aliases can be created with the registerAs() function. |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 40 | */ |
| 41 | class DummyStrategy : public fw::Strategy |
| 42 | { |
| 43 | public: |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 44 | static void |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 45 | registerAs(const Name& strategyName); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 46 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 47 | static Name |
| 48 | getStrategyName(uint64_t version = std::numeric_limits<uint64_t>::max()); |
| 49 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 50 | /** |
| 51 | * \brief Constructor |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 52 | * |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 53 | * \p name is recorded unchanged as getInstanceName(), and will not automatically |
| 54 | * gain a version number when instantiated without a version number. |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 55 | */ |
| 56 | explicit |
| 57 | DummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 58 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 59 | /** |
| 60 | * \brief After receive Interest trigger |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 61 | * |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 62 | * If interestOutFace is not null, \p interest is forwarded to that face; |
| 63 | * otherwise, rejectPendingInterest() is invoked. |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 64 | */ |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 65 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 66 | afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 67 | const shared_ptr<pit::Entry>& pitEntry) override; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 69 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 70 | afterContentStoreHit(const Data& data, const FaceEndpoint& ingress, |
| 71 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 73 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 74 | beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 75 | const shared_ptr<pit::Entry>& pitEntry) override; |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 76 | |
| 77 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 78 | afterReceiveData(const Data& data, const FaceEndpoint& ingress, |
| 79 | const shared_ptr<pit::Entry>& pitEntry) override; |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 80 | |
| 81 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 82 | afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 83 | const shared_ptr<pit::Entry>& pitEntry) override; |
| 84 | |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame] | 85 | void |
| 86 | afterNewNextHop(const fib::NextHop& nextHop, const shared_ptr<pit::Entry>& pitEntry) override; |
| 87 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 88 | protected: |
| 89 | /** \brief register an alias |
| 90 | * \tparam S subclass of DummyStrategy |
| 91 | */ |
| 92 | template<typename S> |
| 93 | static void |
| 94 | registerAsImpl(const Name& strategyName) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 95 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 96 | if (!fw::Strategy::canCreate(strategyName)) { |
| 97 | fw::Strategy::registerType<S>(strategyName); |
| 98 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 101 | public: |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 102 | int afterReceiveInterest_count = 0; |
| 103 | int afterContentStoreHit_count = 0; |
| 104 | int beforeSatisfyInterest_count = 0; |
| 105 | int afterReceiveData_count = 0; |
| 106 | int afterReceiveNack_count = 0; |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 107 | |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame] | 108 | // a collection of names of PIT entries that afterNewNextHop() was called on |
| 109 | std::vector<Name> afterNewNextHopCalls; |
| 110 | |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 111 | shared_ptr<Face> interestOutFace; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 114 | /** \brief DummyStrategy with specific version |
| 115 | */ |
| 116 | template<uint64_t VERSION> |
| 117 | class VersionedDummyStrategy : public DummyStrategy |
| 118 | { |
| 119 | public: |
| 120 | static void |
| 121 | registerAs(const Name& strategyName) |
| 122 | { |
| 123 | DummyStrategy::registerAsImpl<VersionedDummyStrategy<VERSION>>(strategyName); |
| 124 | } |
| 125 | |
| 126 | static Name |
| 127 | getStrategyName() |
| 128 | { |
| 129 | return DummyStrategy::getStrategyName(VERSION); |
| 130 | } |
| 131 | |
| 132 | /** \brief constructor |
| 133 | * |
| 134 | * The strategy instance name is taken from \p name ; if it does not contain a version component, |
| 135 | * \p VERSION will be appended. |
| 136 | */ |
| 137 | explicit |
| 138 | VersionedDummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName()) |
| 139 | : DummyStrategy(forwarder, Strategy::makeInstanceName(name, getStrategyName())) |
| 140 | { |
| 141 | } |
| 142 | }; |
| 143 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 144 | } // namespace tests |
| 145 | } // namespace nfd |
| 146 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 147 | #endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP |