NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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)
44  : enablePacketLogging(enablePacketLogging)
45  , enableRegistrationReply(enableRegistrationReply)
47  {
48  }
49 
50  Options(bool enablePacketLogging, bool enableRegistrationReply)
51  : Options(enablePacketLogging, enableRegistrationReply, nullptr)
52  {
53  }
54 
56  : Options(true, false)
57  {
58  }
59 
60  public:
64 
69 
73 
76  std::function<void(time::milliseconds)> processEventsOverride;
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
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 
195  shared_ptr<BroadcastLink> m_bcastLink;
196  std::unique_ptr<KeyChain> m_internalKeyChain;
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
bool enableRegistrationReply
if true, prefix registration command will be automatically replied with a successful response ...
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
Copyright (c) 2011-2015 Regents of the University of California.
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
ndn security KeyChain
Definition: key-chain.cpp:70
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
Represents an Interest packet.
Definition: interest.hpp:48
std::vector< Data > sentData
Data sent out of this DummyClientFace.
provides a lightweight signal / event system
Definition: signal.hpp:52
std::function< void(time::milliseconds)> m_processEventsOverride
represents a Network Nack
Definition: nack.hpp:38
options for DummyClientFace
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Signal< DummyClientFace, lp::Nack > onSendNack
emits whenever a Nack is sent
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
void unlink()
unlink the broadcast media if previously linked
void receive(const Interest &interest)
cause the Face to receive an interest
shared_ptr< BroadcastLink > m_bcastLink
void linkTo(DummyClientFace &other)
link another DummyClientFace through a broadcast media
A client-side face for unit testing.
Options(bool enablePacketLogging, bool enableRegistrationReply)
uint64_t registrationReplyFaceId
FaceId used in prefix registration replies.
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
Represents a Data packet.
Definition: data.hpp:37
std::unique_ptr< KeyChain > m_internalKeyChain
bool enablePacketLogging
if true, packets sent out of DummyClientFace will be appended to a container
std::function< void(time::milliseconds)> processEventsOverride
if not empty, face.processEvents() will be overridden by this function
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48