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-2024 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"
28 
29 namespace ndn {
30 
35 {
37 
39  const std::function<void(time::milliseconds)>& processEventsOverride = nullptr)
43  {
44  }
45 
47  bool enablePacketLogging = true;
48 
51 
54 
57 };
58 
62 class DummyClientFace : public Face
63 {
64 public:
65  class AlreadyLinkedError : public Error
66  {
67  public:
69  };
70 
72 
76  explicit
77  DummyClientFace(const Options& options = {});
78 
82  explicit
83  DummyClientFace(KeyChain& keyChain, const Options& options = {});
84 
88  explicit
89  DummyClientFace(boost::asio::io_context& ioCtx, const Options& options = {});
90 
94  DummyClientFace(boost::asio::io_context& ioCtx, KeyChain& keyChain, const Options& options = {});
95 
96  ~DummyClientFace() override;
97 
101  void
102  receive(const Interest& interest);
103 
107  void
108  receive(const Data& data);
109 
113  void
114  receive(const lp::Nack& nack);
115 
119  void
120  linkTo(DummyClientFace& other);
121 
125  void
126  unlink();
127 
128 private:
129  void
130  construct(const Options& options);
131 
132  void
133  enableBroadcastLink();
134 
135  void
136  enablePacketLogging();
137 
138  void
139  enableRegistrationReply(uint64_t faceId);
140 
141  void
142  doProcessEvents(time::milliseconds timeout, bool keepRunning) override;
143 
144 public:
153  std::vector<Interest> sentInterests;
154 
163  std::vector<Data> sentData;
164 
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 ndn
202 
203 #endif // NDN_CXX_UTIL_DUMMY_CLIENT_FACE_HPP
A client-side face for unit testing.
void linkTo(DummyClientFace &other)
Link another DummyClientFace through a broadcast medium.
DummyClientFaceOptions Options
signal::Signal< DummyClientFace, Interest > onSendInterest
Emitted whenever an Interest is sent.
void receive(const Interest &interest)
Cause the face to receive an Interest packet.
signal::Signal< DummyClientFace, lp::Nack > onSendNack
Emitted whenever a Nack is sent.
std::vector< Data > sentData
Data sent out of this DummyClientFace.
signal::Signal< DummyClientFace, Data > onSendData
Emitted whenever a Data packet is sent.
DummyClientFace(const Options &options={})
Create a dummy face with an internal I/O context.
void unlink()
Unlink the broadcast medium if previously linked.
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:91
The main interface for signing key management.
Definition: key-chain.hpp:87
Provides a lightweight signal / event system.
Definition: signal.hpp:51
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:49
::boost::chrono::milliseconds milliseconds
Definition: time.hpp:52
@ Data
Definition: tlv.hpp:69
@ Interest
Definition: tlv.hpp:68
Definition: data.cpp:25
Options for DummyClientFace.
std::function< void(time::milliseconds)> processEventsOverride
If not empty, face.processEvents() will be overridden by this function.
DummyClientFaceOptions(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride=nullptr)
uint64_t registrationReplyFaceId
FaceId used in prefix registration replies.
bool enableRegistrationReply
If true, prefix registration commands will be automatically replied to with a successful response.
bool enablePacketLogging
If true, packets sent out of DummyClientFace will be appended to a container.