Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -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, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [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 | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 26 | #ifndef NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP |
| 27 | #define NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 28 | |
| 29 | #include <boost/tuple/tuple_comparison.hpp> |
| 30 | #include "fw/strategy.hpp" |
| 31 | |
| 32 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 33 | namespace fw { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | namespace tests { |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 36 | /** \brief extends strategy S for unit testing |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 37 | * |
| 38 | * Actions invoked by S are recorded but not passed to forwarder |
| 39 | */ |
| 40 | template<typename S> |
| 41 | class StrategyTester : public S |
| 42 | { |
| 43 | public: |
| 44 | explicit |
| 45 | StrategyTester(Forwarder& forwarder) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 46 | : S(forwarder, Name(S::STRATEGY_NAME).append("tester")) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 47 | { |
| 48 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 49 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 50 | /// fires after each Action |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 51 | signal::Signal<StrategyTester<S>> afterAction; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 52 | |
| 53 | protected: |
| 54 | virtual void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 55 | sendInterest(const shared_ptr<pit::Entry>& pitEntry, |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 56 | Face& outFace, |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 57 | bool wantNewNonce = false) override |
| 58 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 59 | sendInterestHistory.push_back({pitEntry->getInterest(), outFace.getId(), wantNewNonce}); |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 60 | pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest()); |
| 61 | afterAction(); |
| 62 | } |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 63 | |
| 64 | virtual void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 65 | rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry) override |
| 66 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 67 | rejectPendingInterestHistory.push_back({pitEntry->getInterest()}); |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 68 | afterAction(); |
| 69 | } |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 71 | virtual void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 72 | sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, |
| 73 | const lp::NackHeader& header) override |
| 74 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 75 | sendNackHistory.push_back({pitEntry->getInterest(), outFace.getId(), header}); |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 76 | pitEntry->deleteInRecord(outFace); |
| 77 | afterAction(); |
| 78 | } |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 79 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 80 | public: |
| 81 | struct SendInterestArgs |
| 82 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 83 | Interest pitInterest; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 84 | FaceId outFaceId; |
| 85 | bool wantNewNonce; |
| 86 | }; |
| 87 | std::vector<SendInterestArgs> sendInterestHistory; |
| 88 | |
| 89 | struct RejectPendingInterestArgs |
| 90 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 91 | Interest pitInterest; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 92 | }; |
| 93 | std::vector<RejectPendingInterestArgs> rejectPendingInterestHistory; |
| 94 | |
| 95 | struct SendNackArgs |
| 96 | { |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 97 | Interest pitInterest; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 98 | FaceId outFaceId; |
| 99 | lp::NackHeader header; |
| 100 | }; |
| 101 | std::vector<SendNackArgs> sendNackHistory; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 104 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 105 | } // namespace fw |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 106 | } // namespace nfd |
| 107 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 108 | #endif // NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP |