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 | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 36 | * Unless otherwise indicated, triggers are recorded but does nothing. |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 37 | */ |
| 38 | class DummyStrategy : public fw::Strategy |
| 39 | { |
| 40 | public: |
| 41 | DummyStrategy(Forwarder& forwarder, const Name& name) |
| 42 | : Strategy(forwarder, name) |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 43 | , afterReceiveInterest_count(0) |
| 44 | , wantAfterReceiveInterestCalls(false) |
| 45 | , beforeSatisfyInterest_count(0) |
| 46 | , beforeExpirePendingInterest_count(0) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 47 | { |
| 48 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 49 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 50 | /** \brief after receive Interest trigger |
| 51 | * |
| 52 | * If \p interestOutFace is not null, send Interest action is invoked with that face; |
| 53 | * otherwise, reject pending Interest action is invoked. |
| 54 | */ |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 55 | virtual void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 56 | afterReceiveInterest(const Face& inFace, |
| 57 | const Interest& interest, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 58 | shared_ptr<pit::Entry> pitEntry) override |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 59 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 60 | ++afterReceiveInterest_count; |
| 61 | if (wantAfterReceiveInterestCalls) { |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame^] | 62 | afterReceiveInterestCalls.emplace_back(inFace.getId(), interest, pitEntry); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 63 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 64 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 65 | if (interestOutFace) { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 66 | this->sendInterest(pitEntry, interestOutFace); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 67 | } |
| 68 | else { |
| 69 | this->rejectPendingInterest(pitEntry); |
| 70 | } |
| 71 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 73 | virtual void |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 74 | beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 75 | const Face& inFace, |
| 76 | const Data& data) override |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 77 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 78 | ++beforeSatisfyInterest_count; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | virtual void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 82 | beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry) override |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 83 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 84 | ++beforeExpirePendingInterest_count; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 87 | virtual void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 88 | afterReceiveNack(const Face& inFace, |
| 89 | const lp::Nack& nack, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 90 | shared_ptr<pit::Entry> pitEntry) override |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 91 | { |
| 92 | ++afterReceiveNack_count; |
| 93 | } |
| 94 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 95 | public: |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 96 | int afterReceiveInterest_count; |
| 97 | bool wantAfterReceiveInterestCalls; |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame^] | 98 | std::vector<std::tuple<FaceId, Interest, shared_ptr<pit::Entry>>> afterReceiveInterestCalls; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 99 | shared_ptr<Face> interestOutFace; |
| 100 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 101 | int beforeSatisfyInterest_count; |
| 102 | int beforeExpirePendingInterest_count; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 103 | int afterReceiveNack_count; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | } // namespace tests |
| 107 | } // namespace nfd |
| 108 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 109 | #endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP |