blob: 07bc0b0d7db73cc1b427032cb9913d7b25fe50ea [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventob84bd3a2016-04-22 02:21:45 +02003 * Copyright (c) 2014-2016, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shi82e7f582014-09-07 15:15:40 -070024 */
Junxiao Shi727ed292014-02-19 23:26:45 -070025
Davide Pesavento97210d52016-10-14 15:45:48 +020026#ifndef NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP
27#define NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP
Junxiao Shi727ed292014-02-19 23:26:45 -070028
29#include <boost/tuple/tuple_comparison.hpp>
30#include "fw/strategy.hpp"
31
32namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080033namespace fw {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070035
Junxiao Shi5e5e4452015-09-24 16:56:52 -070036/** \brief extends strategy S for unit testing
Junxiao Shi727ed292014-02-19 23:26:45 -070037 *
38 * Actions invoked by S are recorded but not passed to forwarder
39 */
40template<typename S>
41class StrategyTester : public S
42{
43public:
44 explicit
45 StrategyTester(Forwarder& forwarder)
Junxiao Shif3c07812014-03-11 21:48:49 -070046 : S(forwarder, Name(S::STRATEGY_NAME).append("tester"))
Junxiao Shi727ed292014-02-19 23:26:45 -070047 {
48 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070049
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070050 /// fires after each Action
Junxiao Shi5e5e4452015-09-24 16:56:52 -070051 signal::Signal<StrategyTester<S>> afterAction;
Junxiao Shi727ed292014-02-19 23:26:45 -070052
53protected:
54 virtual void
Junxiao Shic5f651f2016-11-17 22:58:12 +000055 sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
56 const Interest& interest) override
Junxiao Shib9420cf2016-08-13 04:38:52 +000057 {
Junxiao Shic5f651f2016-11-17 22:58:12 +000058 sendInterestHistory.push_back({pitEntry->getInterest(), outFace.getId(), interest});
59 pitEntry->insertOrUpdateOutRecord(outFace, interest);
Junxiao Shib9420cf2016-08-13 04:38:52 +000060 afterAction();
61 }
Junxiao Shi727ed292014-02-19 23:26:45 -070062
63 virtual void
Junxiao Shib9420cf2016-08-13 04:38:52 +000064 rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry) override
65 {
Junxiao Shi8ff0a862016-08-13 04:50:50 +000066 rejectPendingInterestHistory.push_back({pitEntry->getInterest()});
Junxiao Shib9420cf2016-08-13 04:38:52 +000067 afterAction();
68 }
Junxiao Shi727ed292014-02-19 23:26:45 -070069
Junxiao Shi5e5e4452015-09-24 16:56:52 -070070 virtual void
Junxiao Shib9420cf2016-08-13 04:38:52 +000071 sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
72 const lp::NackHeader& header) override
73 {
Junxiao Shi8ff0a862016-08-13 04:50:50 +000074 sendNackHistory.push_back({pitEntry->getInterest(), outFace.getId(), header});
Junxiao Shib9420cf2016-08-13 04:38:52 +000075 pitEntry->deleteInRecord(outFace);
76 afterAction();
77 }
Junxiao Shi727ed292014-02-19 23:26:45 -070078
Junxiao Shi5e5e4452015-09-24 16:56:52 -070079public:
80 struct SendInterestArgs
81 {
Junxiao Shi8ff0a862016-08-13 04:50:50 +000082 Interest pitInterest;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070083 FaceId outFaceId;
Junxiao Shic5f651f2016-11-17 22:58:12 +000084 Interest interest;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070085 };
86 std::vector<SendInterestArgs> sendInterestHistory;
87
88 struct RejectPendingInterestArgs
89 {
Junxiao Shi8ff0a862016-08-13 04:50:50 +000090 Interest pitInterest;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070091 };
92 std::vector<RejectPendingInterestArgs> rejectPendingInterestHistory;
93
94 struct SendNackArgs
95 {
Junxiao Shi8ff0a862016-08-13 04:50:50 +000096 Interest pitInterest;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070097 FaceId outFaceId;
98 lp::NackHeader header;
99 };
100 std::vector<SendNackArgs> sendNackHistory;
Junxiao Shi727ed292014-02-19 23:26:45 -0700101};
102
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700103} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800104} // namespace fw
Junxiao Shi727ed292014-02-19 23:26:45 -0700105} // namespace nfd
106
Davide Pesavento97210d52016-10-14 15:45:48 +0200107#endif // NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP