blob: 9cf4855d9f51984f3f84bfcdc0b7f7e7eb708340 [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * Copyright (c) 2014-2015, 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 Shi727ed292014-02-19 23:26:45 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_TESTS_NFD_FW_STRATEGY_TESTER_HPP
27#define NFD_TESTS_NFD_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
36/** \class StrategyTester
37 * \brief extends strategy S for unit testing
38 *
39 * Actions invoked by S are recorded but not passed to forwarder
40 */
41template<typename S>
42class StrategyTester : public S
43{
44public:
45 explicit
46 StrategyTester(Forwarder& forwarder)
Junxiao Shif3c07812014-03-11 21:48:49 -070047 : S(forwarder, Name(S::STRATEGY_NAME).append("tester"))
Junxiao Shi727ed292014-02-19 23:26:45 -070048 {
49 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070050
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070051 /// fires after each Action
Junxiao Shi3cb4fc62014-12-25 22:17:39 -070052 signal::Signal<StrategyTester<S>> onAction;
Junxiao Shi727ed292014-02-19 23:26:45 -070053
54protected:
55 virtual void
Junxiao Shid938a6b2014-05-11 23:40:29 -070056 sendInterest(shared_ptr<pit::Entry> pitEntry,
57 shared_ptr<Face> outFace,
Junxiao Shi1c93cae2014-12-09 22:52:17 -070058 bool wantNewNonce = false) DECL_OVERRIDE;
Junxiao Shi727ed292014-02-19 23:26:45 -070059
60 virtual void
Junxiao Shi1c93cae2014-12-09 22:52:17 -070061 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
Junxiao Shi727ed292014-02-19 23:26:45 -070062
63public:
Junxiao Shi1c93cae2014-12-09 22:52:17 -070064 typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face>> SendInterestArgs;
Junxiao Shi727ed292014-02-19 23:26:45 -070065 std::vector<SendInterestArgs> m_sendInterestHistory;
66
Junxiao Shi1c93cae2014-12-09 22:52:17 -070067 typedef boost::tuple<shared_ptr<pit::Entry>> RejectPendingInterestArgs;
Junxiao Shi09498f02014-02-26 19:41:08 -070068 std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
Junxiao Shi727ed292014-02-19 23:26:45 -070069};
70
71
72template<typename S>
73inline void
74StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry,
Junxiao Shid938a6b2014-05-11 23:40:29 -070075 shared_ptr<Face> outFace,
76 bool wantNewNonce)
Junxiao Shi727ed292014-02-19 23:26:45 -070077{
78 m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070079 pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
80 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070081}
82
83template<typename S>
84inline void
Junxiao Shi09498f02014-02-26 19:41:08 -070085StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
Junxiao Shi727ed292014-02-19 23:26:45 -070086{
Junxiao Shi09498f02014-02-26 19:41:08 -070087 m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070088 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070089}
90
Junxiao Shid9ee45c2014-02-27 15:38:11 -070091} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080092} // namespace fw
Junxiao Shi727ed292014-02-19 23:26:45 -070093} // namespace nfd
94
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070095#endif // NFD_TESTS_NFD_FW_STRATEGY_TESTER_HPP