blob: 33d2656caeac5e315292eb9ea6066ed77bac82f0 [file] [log] [blame]
Junxiao Shif3c07812014-03-11 21:48:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi82e7f582014-09-07 15:15:40 -07003 * Copyright (c) 2014, 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:
41 DummyStrategy(Forwarder& forwarder, const Name& name)
42 : Strategy(forwarder, name)
Junxiao Shi0355e9f2015-09-02 07:24:53 -070043 , afterReceiveInterest_count(0)
44 , wantAfterReceiveInterestCalls(false)
45 , beforeSatisfyInterest_count(0)
46 , beforeExpirePendingInterest_count(0)
Junxiao Shif3c07812014-03-11 21:48:49 -070047 {
48 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070049
Junxiao Shi5e5e4452015-09-24 16:56:52 -070050 /** \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 Shif3c07812014-03-11 21:48:49 -070055 virtual void
Junxiao Shi5e5e4452015-09-24 16:56:52 -070056 afterReceiveInterest(const Face& inFace, const Interest& interest,
Junxiao Shif3c07812014-03-11 21:48:49 -070057 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi1c93cae2014-12-09 22:52:17 -070058 shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
Junxiao Shif3c07812014-03-11 21:48:49 -070059 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070060 ++afterReceiveInterest_count;
61 if (wantAfterReceiveInterestCalls) {
62 afterReceiveInterestCalls.push_back(std::make_tuple(inFace.getId(),
63 interest, fibEntry, pitEntry));
64 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070065
Junxiao Shi5e5e4452015-09-24 16:56:52 -070066 if (interestOutFace) {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070067 this->sendInterest(pitEntry, interestOutFace);
Junxiao Shif3c07812014-03-11 21:48:49 -070068 }
69 else {
70 this->rejectPendingInterest(pitEntry);
71 }
72 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070073
Junxiao Shif3c07812014-03-11 21:48:49 -070074 virtual void
Junxiao Shi82e7f582014-09-07 15:15:40 -070075 beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
Junxiao Shi1c93cae2014-12-09 22:52:17 -070076 const Face& inFace, const Data& data) DECL_OVERRIDE
Junxiao Shif3c07812014-03-11 21:48:49 -070077 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070078 ++beforeSatisfyInterest_count;
Junxiao Shif3c07812014-03-11 21:48:49 -070079 }
80
81 virtual void
Junxiao Shi1c93cae2014-12-09 22:52:17 -070082 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
Junxiao Shif3c07812014-03-11 21:48:49 -070083 {
Junxiao Shi0355e9f2015-09-02 07:24:53 -070084 ++beforeExpirePendingInterest_count;
Junxiao Shif3c07812014-03-11 21:48:49 -070085 }
86
Junxiao Shi5e5e4452015-09-24 16:56:52 -070087 virtual void
88 afterReceiveNack(const Face& inFace, const lp::Nack& nack,
89 shared_ptr<fib::Entry> fibEntry,
90 shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
91 {
92 ++afterReceiveNack_count;
93 }
94
Junxiao Shif3c07812014-03-11 21:48:49 -070095public:
Junxiao Shi0355e9f2015-09-02 07:24:53 -070096 int afterReceiveInterest_count;
97 bool wantAfterReceiveInterestCalls;
98 std::vector<std::tuple<FaceId, Interest, shared_ptr<fib::Entry>,
99 shared_ptr<pit::Entry>>> afterReceiveInterestCalls;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700100 shared_ptr<Face> interestOutFace;
101
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700102 int beforeSatisfyInterest_count;
103 int beforeExpirePendingInterest_count;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700104 int afterReceiveNack_count;
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700105
Junxiao Shif3c07812014-03-11 21:48:49 -0700106};
107
108} // namespace tests
109} // namespace nfd
110
Junxiao Shi82e7f582014-09-07 15:15:40 -0700111#endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP