blob: a6af8acd1433d13d22852bbfa85db007c296fe59 [file] [log] [blame]
Junxiao Shif3c07812014-03-11 21:48:49 -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,
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 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 Shif3c07812014-03-11 21:48:49 -070025
Junxiao Shi82e7f582014-09-07 15:15:40 -070026#ifndef NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP
27#define NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP
Junxiao Shif3c07812014-03-11 21:48:49 -070028
29#include "fw/strategy.hpp"
30
31namespace nfd {
32namespace tests {
33
34/** \brief strategy for unit testing
35 *
Junxiao Shi5e5e4452015-09-24 16:56:52 -070036 * Unless otherwise indicated, triggers are recorded but does nothing.
Junxiao Shif3c07812014-03-11 21:48:49 -070037 */
38class DummyStrategy : public fw::Strategy
39{
40public:
Junxiao Shi18739c42016-12-22 08:03:00 +000041 static void
42 registerAs(const Name& name)
43 {
44 if (!fw::Strategy::canCreate(name)) {
45 fw::Strategy::registerType<DummyStrategy>(name);
46 }
47 }
48
Junxiao Shif3c07812014-03-11 21:48:49 -070049 DummyStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000050 : Strategy(forwarder)
Junxiao Shi0355e9f2015-09-02 07:24:53 -070051 , afterReceiveInterest_count(0)
Junxiao Shi0355e9f2015-09-02 07:24:53 -070052 , beforeSatisfyInterest_count(0)
53 , beforeExpirePendingInterest_count(0)
Junxiao Shi15e98b02016-08-12 11:21:44 +000054 , afterReceiveNack_count(0)
Junxiao Shif3c07812014-03-11 21:48:49 -070055 {
Junxiao Shi18739c42016-12-22 08:03:00 +000056 this->setInstanceName(name);
Junxiao Shif3c07812014-03-11 21:48:49 -070057 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070058
Junxiao Shi5e5e4452015-09-24 16:56:52 -070059 /** \brief after receive Interest trigger
60 *
Junxiao Shia6350d92016-11-22 14:22:25 +000061 * If \p interestOutFace is not null, Interest is forwarded to that face via send Interest action;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070062 * otherwise, reject pending Interest action is invoked.
63 */
Junxiao Shi18739c42016-12-22 08:03:00 +000064 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000065 afterReceiveInterest(const Face& inFace, const Interest& interest,
66 const shared_ptr<pit::Entry>& pitEntry) override
Junxiao Shif3c07812014-03-11 21:48:49 -070067 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070068 ++afterReceiveInterest_count;
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070069
Junxiao Shia6350d92016-11-22 14:22:25 +000070 if (interestOutFace != nullptr) {
71 this->sendInterest(pitEntry, *interestOutFace, interest);
Junxiao Shif3c07812014-03-11 21:48:49 -070072 }
73 else {
74 this->rejectPendingInterest(pitEntry);
75 }
76 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070077
Junxiao Shi18739c42016-12-22 08:03:00 +000078 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000079 beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
80 const Face& inFace, const Data& data) override
Junxiao Shif3c07812014-03-11 21:48:49 -070081 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070082 ++beforeSatisfyInterest_count;
Junxiao Shif3c07812014-03-11 21:48:49 -070083 }
84
Junxiao Shi18739c42016-12-22 08:03:00 +000085 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000086 beforeExpirePendingInterest(const shared_ptr<pit::Entry>& pitEntry) override
Junxiao Shif3c07812014-03-11 21:48:49 -070087 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070088 ++beforeExpirePendingInterest_count;
Junxiao Shif3c07812014-03-11 21:48:49 -070089 }
90
Junxiao Shi18739c42016-12-22 08:03:00 +000091 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000092 afterReceiveNack(const Face& inFace, const lp::Nack& nack,
93 const shared_ptr<pit::Entry>& pitEntry) override
Junxiao Shi5e5e4452015-09-24 16:56:52 -070094 {
95 ++afterReceiveNack_count;
96 }
97
Junxiao Shif3c07812014-03-11 21:48:49 -070098public:
Junxiao Shi0355e9f2015-09-02 07:24:53 -070099 int afterReceiveInterest_count;
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700100 int beforeSatisfyInterest_count;
101 int beforeExpirePendingInterest_count;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700102 int afterReceiveNack_count;
Junxiao Shi15e98b02016-08-12 11:21:44 +0000103
104 shared_ptr<Face> interestOutFace;
Junxiao Shif3c07812014-03-11 21:48:49 -0700105};
106
107} // namespace tests
108} // namespace nfd
109
Junxiao Shi82e7f582014-09-07 15:15:40 -0700110#endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP