blob: 9a2445b371d3d8b74d83b6cfd687364685206d56 [file] [log] [blame]
Junxiao Shif3c07812014-03-11 21:48:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Teng Liang63086442018-02-25 20:39:42 -07002/*
ashiqopuc7079482019-02-20 05:34:37 +00003 * Copyright (c) 2014-2019, Regents of the University of California,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +02004 * 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 Shi0e4a1f12016-12-24 02:39:01 +000036 * 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.
ashiqopuc7079482019-02-20 05:34:37 +000040 *
41 * \note This strategy is not EndpointId-aware.
Junxiao Shif3c07812014-03-11 21:48:49 -070042 */
43class DummyStrategy : public fw::Strategy
44{
45public:
Junxiao Shi18739c42016-12-22 08:03:00 +000046 static void
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000047 registerAs(const Name& strategyName);
Junxiao Shi18739c42016-12-22 08:03:00 +000048
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000049 static Name
50 getStrategyName(uint64_t version = std::numeric_limits<uint64_t>::max());
51
52 /** \brief constructor
53 *
54 * \p name is recorded unchanged as \p getInstanceName() , and will not automatically
55 * gain a version number when instantiated without a version number.
56 */
57 explicit
58 DummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070059
Junxiao Shi5e5e4452015-09-24 16:56:52 -070060 /** \brief after receive Interest trigger
61 *
ashiqopuc7079482019-02-20 05:34:37 +000062 * If \p interestOutFace is not null, Interest is forwarded to that face and endpoint via send Interest action;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070063 * otherwise, reject pending Interest action is invoked.
64 */
Junxiao Shi18739c42016-12-22 08:03:00 +000065 void
ashiqopuc7079482019-02-20 05:34:37 +000066 afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000067 const shared_ptr<pit::Entry>& pitEntry) override;
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070068
Junxiao Shi18739c42016-12-22 08:03:00 +000069 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000070 beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
ashiqopuc7079482019-02-20 05:34:37 +000071 const FaceEndpoint& ingress, const Data& data) override;
Junxiao Shif3c07812014-03-11 21:48:49 -070072
Junxiao Shi18739c42016-12-22 08:03:00 +000073 void
Teng Liang85a36632018-03-21 05:59:34 -070074 afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry,
ashiqopuc7079482019-02-20 05:34:37 +000075 const FaceEndpoint& ingress, const Data& data) override;
Teng Liang85a36632018-03-21 05:59:34 -070076
77 void
Teng Liang43bb2312018-03-26 04:16:42 -070078 afterReceiveData(const shared_ptr<pit::Entry>& pitEntry,
ashiqopuc7079482019-02-20 05:34:37 +000079 const FaceEndpoint& ingress, const Data& data) override;
Teng Liang43bb2312018-03-26 04:16:42 -070080
81 void
ashiqopuc7079482019-02-20 05:34:37 +000082 afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000083 const shared_ptr<pit::Entry>& pitEntry) override;
84
85protected:
86 /** \brief register an alias
87 * \tparam S subclass of DummyStrategy
88 */
89 template<typename S>
90 static void
91 registerAsImpl(const Name& strategyName)
Junxiao Shi5e5e4452015-09-24 16:56:52 -070092 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000093 if (!fw::Strategy::canCreate(strategyName)) {
94 fw::Strategy::registerType<S>(strategyName);
95 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -070096 }
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;
Teng Liang85a36632018-03-21 05:59:34 -0700101 int afterContentStoreHit_count;
Teng Liang43bb2312018-03-26 04:16:42 -0700102 int afterReceiveData_count;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700103 int afterReceiveNack_count;
Junxiao Shi15e98b02016-08-12 11:21:44 +0000104
105 shared_ptr<Face> interestOutFace;
Junxiao Shif3c07812014-03-11 21:48:49 -0700106};
107
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000108/** \brief DummyStrategy with specific version
109 */
110template<uint64_t VERSION>
111class VersionedDummyStrategy : public DummyStrategy
112{
113public:
114 static void
115 registerAs(const Name& strategyName)
116 {
117 DummyStrategy::registerAsImpl<VersionedDummyStrategy<VERSION>>(strategyName);
118 }
119
120 static Name
121 getStrategyName()
122 {
123 return DummyStrategy::getStrategyName(VERSION);
124 }
125
126 /** \brief constructor
127 *
128 * The strategy instance name is taken from \p name ; if it does not contain a version component,
129 * \p VERSION will be appended.
130 */
131 explicit
132 VersionedDummyStrategy(Forwarder& forwarder, const Name& name = getStrategyName())
133 : DummyStrategy(forwarder, Strategy::makeInstanceName(name, getStrategyName()))
134 {
135 }
136};
137
Junxiao Shif3c07812014-03-11 21:48:49 -0700138} // namespace tests
139} // namespace nfd
140
Junxiao Shi82e7f582014-09-07 15:15:40 -0700141#endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP