Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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 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 | |
| 34 | /** \brief strategy for unit testing |
| 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 |
| 39 | * with any version number. Aliases can be created with \p 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 | |
| 50 | /** \brief constructor |
| 51 | * |
| 52 | * \p name is recorded unchanged as \p getInstanceName() , and will not automatically |
| 53 | * gain a version number when instantiated without a version number. |
| 54 | */ |
| 55 | explicit |
| 56 | DummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 57 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 58 | /** \brief after receive Interest trigger |
| 59 | * |
Junxiao Shi | a6350d9 | 2016-11-22 14:22:25 +0000 | [diff] [blame] | 60 | * If \p interestOutFace is not null, Interest is forwarded to that face via send Interest action; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 61 | * otherwise, reject pending Interest action is invoked. |
| 62 | */ |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 63 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 64 | afterReceiveInterest(const Face& inFace, const Interest& interest, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 65 | const shared_ptr<pit::Entry>& pitEntry) override; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 66 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 67 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 68 | beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 69 | const Face& inFace, const Data& data) override; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 71 | void |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 72 | beforeExpirePendingInterest(const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 74 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 75 | afterReceiveNack(const Face& inFace, const lp::Nack& nack, |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 76 | const shared_ptr<pit::Entry>& pitEntry) override; |
| 77 | |
| 78 | protected: |
| 79 | /** \brief register an alias |
| 80 | * \tparam S subclass of DummyStrategy |
| 81 | */ |
| 82 | template<typename S> |
| 83 | static void |
| 84 | registerAsImpl(const Name& strategyName) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 85 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 86 | if (!fw::Strategy::canCreate(strategyName)) { |
| 87 | fw::Strategy::registerType<S>(strategyName); |
| 88 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 91 | public: |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 92 | int afterReceiveInterest_count; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 93 | int beforeSatisfyInterest_count; |
| 94 | int beforeExpirePendingInterest_count; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 95 | int afterReceiveNack_count; |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 96 | |
| 97 | shared_ptr<Face> interestOutFace; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 100 | /** \brief DummyStrategy with specific version |
| 101 | */ |
| 102 | template<uint64_t VERSION> |
| 103 | class VersionedDummyStrategy : public DummyStrategy |
| 104 | { |
| 105 | public: |
| 106 | static void |
| 107 | registerAs(const Name& strategyName) |
| 108 | { |
| 109 | DummyStrategy::registerAsImpl<VersionedDummyStrategy<VERSION>>(strategyName); |
| 110 | } |
| 111 | |
| 112 | static Name |
| 113 | getStrategyName() |
| 114 | { |
| 115 | return DummyStrategy::getStrategyName(VERSION); |
| 116 | } |
| 117 | |
| 118 | /** \brief constructor |
| 119 | * |
| 120 | * The strategy instance name is taken from \p name ; if it does not contain a version component, |
| 121 | * \p VERSION will be appended. |
| 122 | */ |
| 123 | explicit |
| 124 | VersionedDummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName()) |
| 125 | : DummyStrategy(forwarder, Strategy::makeInstanceName(name, getStrategyName())) |
| 126 | { |
| 127 | } |
| 128 | }; |
| 129 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 130 | } // namespace tests |
| 131 | } // namespace nfd |
| 132 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 133 | #endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP |