blob: 9f46ca668ee3bfb10d931243a9a0617cae1a8a0f [file] [log] [blame]
Junxiao Shia60d9362014-11-12 09:38:21 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Junxiao Shia60d9362014-11-12 09:38:21 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_UTIL_DUMMY_CLIENT_FACE_HPP
23#define NDN_UTIL_DUMMY_CLIENT_FACE_HPP
24
25#include "../face.hpp"
Junxiao Shi27913b42014-12-23 14:49:38 -070026#include "signal.hpp"
Eric Newberry83872fd2015-08-06 17:01:24 -070027#include "../lp/packet.hpp"
Junxiao Shia60d9362014-11-12 09:38:21 -070028
29namespace ndn {
30namespace util {
31
32/** \brief a client-side face for unit testing
33 */
34class DummyClientFace : public ndn::Face
35{
36public:
37 /** \brief options for DummyClientFace
38 */
39 struct Options
40 {
41 /** \brief if true, packets sent out of DummyClientFace will be appended to a container
42 */
43 bool enablePacketLogging;
44
45 /** \brief if true, prefix registration command will be automatically
46 * replied with a successful response
47 */
48 bool enableRegistrationReply;
49 };
50
51 /** \brief cause the Face to receive a packet
52 * \tparam Packet either Interest or Data
53 */
54 template<typename Packet>
55 void
56 receive(const Packet& packet);
57
58private: // constructors
59 class Transport;
60
61 // constructors are private; use makeDummyClientFace to create DummyClientFace
62
63 DummyClientFace(const Options& options, shared_ptr<Transport> transport);
64
65 DummyClientFace(const Options& options, shared_ptr<Transport> transport,
66 boost::asio::io_service& ioService);
67
68 void
69 construct(const Options& options);
70
71 friend shared_ptr<DummyClientFace>
72 makeDummyClientFace(const DummyClientFace::Options& options);
73
74 friend shared_ptr<DummyClientFace>
75 makeDummyClientFace(boost::asio::io_service& ioService, const DummyClientFace::Options& options);
76
77private:
78 void
79 enablePacketLogging();
80
81 void
82 enableRegistrationReply();
83
84public:
85 /** \brief default options
86 *
87 * enablePacketLogging=true
88 * enableRegistrationReply=false
89 */
90 static const Options DEFAULT_OPTIONS;
91
92 /** \brief Interests sent out of this DummyClientFace
93 *
94 * Sent Interests are appended to this container if options.enablePacketLogger is true.
95 * User of this class is responsible for cleaning up the container, if necessary.
96 * After .expressInterest, .processEvents must be called before the Interest would show up here.
97 */
98 std::vector<Interest> sentInterests;
99
100 /** \brief Data sent out of this DummyClientFace
101 *
102 * Sent Data are appended to this container if options.enablePacketLogger is true.
103 * User of this class is responsible for cleaning up the container, if necessary.
104 * After .put, .processEvents must be called before the Data would show up here.
105 */
106 std::vector<Data> sentDatas;
107
Eric Newberry83872fd2015-08-06 17:01:24 -0700108 /** \brief NACKs sent out of this DummyClientFace
109 *
110 * Sent NACKs are appended to this container if options.enablePacketLogger is true.
111 * User of this class is responsible for cleaning up the container, if necessary.
112 * After .put, .processEvents must be called before the NACK would show up here.
113 */
114 std::vector<lp::Nack> sentNacks;
115
Junxiao Shi27913b42014-12-23 14:49:38 -0700116 /** \brief emits whenever an Interest is sent
Junxiao Shia60d9362014-11-12 09:38:21 -0700117 *
Junxiao Shi27913b42014-12-23 14:49:38 -0700118 * After .expressInterest, .processEvents must be called before this signal would be emitted.
119 */
120 Signal<DummyClientFace, Interest> onSendInterest;
121
122 /** \brief emits whenever a Data packet is sent
123 *
124 * After .put, .processEvents must be called before this signal would be emitted.
125 */
126 Signal<DummyClientFace, Data> onSendData;
127
Eric Newberry83872fd2015-08-06 17:01:24 -0700128 /** \brief emits whenever a NACK is sent
129 *
130 * After .put, .processEvents must be called before this signal would be emitted.
131 */
132 Signal<DummyClientFace, lp::Nack> onSendNack;
133
Junxiao Shia60d9362014-11-12 09:38:21 -0700134private:
135 shared_ptr<Transport> m_transport;
136};
137
138shared_ptr<DummyClientFace>
139makeDummyClientFace(const DummyClientFace::Options& options = DummyClientFace::DEFAULT_OPTIONS);
140
141shared_ptr<DummyClientFace>
142makeDummyClientFace(boost::asio::io_service& ioService,
143 const DummyClientFace::Options& options = DummyClientFace::DEFAULT_OPTIONS);
144
145} // namespace util
146} // namespace ndn
147
148#endif // NDN_UTIL_DUMMY_CLIENT_FACE_HPP