dummy-client-face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 Regents of the University of California.
4  *
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_CXX_UTIL_DUMMY_CLIENT_FACE_HPP
23 #define NDN_CXX_UTIL_DUMMY_CLIENT_FACE_HPP
24 
25 #include "ndn-cxx/face.hpp"
26 #include "ndn-cxx/util/signal.hpp"
28 
29 namespace ndn {
30 namespace util {
31 
34 class DummyClientFace : public ndn::Face
35 {
36 public:
39  class Options
40  {
41  public:
43  const std::function<void(time::milliseconds)>& processEventsOverride)
47  {
48  }
49 
52  {
53  }
54 
56  : Options(true, false)
57  {
58  }
59 
60  public:
64 
69 
73 
77  };
78 
79  class AlreadyLinkedError : public Error
80  {
81  public:
83  };
84 
87  explicit
88  DummyClientFace(const Options& options = Options());
89 
92  explicit
93  DummyClientFace(KeyChain& keyChain, const Options& options = Options());
94 
97  explicit
98  DummyClientFace(boost::asio::io_service& ioService, const Options& options = Options());
99 
102  DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
103  const Options& options = Options());
104 
105  ~DummyClientFace() override;
106 
109  void
110  receive(const Interest& interest);
111 
114  void
115  receive(const Data& data);
116 
119  void
120  receive(const lp::Nack& nack);
121 
124  void
125  linkTo(DummyClientFace& other);
126 
129  void
130  unlink();
131 
132 private:
133  class Transport;
134 
135  void
136  construct(const Options& options);
137 
138  void
139  enableBroadcastLink();
140 
141  void
142  enablePacketLogging();
143 
144  void
145  enableRegistrationReply(uint64_t faceId);
146 
147  void
148  doProcessEvents(time::milliseconds timeout, bool keepThread) override;
149 
150 public:
157  std::vector<Interest> sentInterests;
158 
165  std::vector<Data> sentData;
166 
173  std::vector<lp::Nack> sentNacks;
174 
180 
186 
192 
194  struct BroadcastLink;
195  shared_ptr<BroadcastLink> m_bcastLink;
196  std::unique_ptr<KeyChain> m_internalKeyChain;
197  KeyChain& m_keyChain;
198  std::function<void(time::milliseconds)> m_processEventsOverride;
199 };
200 
201 } // namespace util
202 } // namespace ndn
203 
204 #endif // NDN_CXX_UTIL_DUMMY_CLIENT_FACE_HPP
Represents a Data packet.
Definition: data.hpp:39
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:91
Represents an Interest packet.
Definition: interest.hpp:50
Represents a Network Nack.
Definition: nack.hpp:40
Options for DummyClientFace.
Options(bool enablePacketLogging, bool enableRegistrationReply)
std::function< void(time::milliseconds)> processEventsOverride
If not empty, face.processEvents() will be overridden by this function.
uint64_t registrationReplyFaceId
FaceId used in prefix registration replies.
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
bool enablePacketLogging
If true, packets sent out of DummyClientFace will be appended to a container.
bool enableRegistrationReply
If true, prefix registration command will be automatically replied with a successful response.
A client-side face for unit testing.
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
void receive(const Interest &interest)
Cause the Face to receive an Interest packet.
Signal< DummyClientFace, Interest > onSendInterest
Emits whenever an Interest is sent.
void linkTo(DummyClientFace &other)
Link another DummyClientFace through a broadcast media.
Signal< DummyClientFace, lp::Nack > onSendNack
Emits whenever a Nack is sent.
void unlink()
Unlink the broadcast media if previously linked.
Signal< DummyClientFace, Data > onSendData
Emits whenever a Data packet is sent.
std::vector< Data > sentData
Data sent out of this DummyClientFace.
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Provides a lightweight signal / event system.
Definition: signal.hpp:53
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48
Definition: data.cpp:25