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-2018 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_UTIL_DUMMY_CLIENT_FACE_HPP
23 #define NDN_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 
72  std::function<void(time::milliseconds)> processEventsOverride;
73  };
74 
75  class AlreadyLinkedError : public Error
76  {
77  public:
79  };
80 
83  explicit
84  DummyClientFace(const Options& options = Options());
85 
88  explicit
89  DummyClientFace(KeyChain& keyChain, const Options& options = Options());
90 
93  explicit
94  DummyClientFace(boost::asio::io_service& ioService, const Options& options = Options());
95 
98  DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
99  const Options& options = Options());
100 
102 
105  void
106  receive(const Interest& interest);
107 
110  void
111  receive(const Data& data);
112 
115  void
116  receive(const lp::Nack& nack);
117 
120  void
121  linkTo(DummyClientFace& other);
122 
125  void
126  unlink();
127 
128 private:
129  class Transport;
130 
131  void
132  construct(const Options& options);
133 
134  void
135  enableBroadcastLink();
136 
137  void
138  enablePacketLogging();
139 
140  void
141  enableRegistrationReply();
142 
143  void
144  doProcessEvents(time::milliseconds timeout, bool keepThread) override;
145 
146 public:
153  std::vector<Interest> sentInterests;
154 
161  std::vector<Data> sentData;
162 
169  std::vector<lp::Nack> sentNacks;
170 
176 
182 
188 
190  struct BroadcastLink;
191  shared_ptr<BroadcastLink> m_bcastLink;
192  std::unique_ptr<KeyChain> m_internalKeyChain;
194  std::function<void(time::milliseconds)> m_processEventsOverride;
195 };
196 
197 } // namespace util
198 } // namespace ndn
199 
200 #endif // NDN_UTIL_DUMMY_CLIENT_FACE_HPP
ndn::util::DummyClientFace::unlink
void unlink()
unlink the broadcast media if previously linked
Definition: dummy-client-face.cpp:314
ndn::util::DummyClientFace::Options
options for DummyClientFace
Definition: dummy-client-face.hpp:40
ndn::util::DummyClientFace::onSendData
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
Definition: dummy-client-face.hpp:181
ndn::util::DummyClientFace::receive
void receive(const Interest &interest)
cause the Face to receive an interest
Definition: dummy-client-face.cpp:253
ndn::util::DummyClientFace::onSendInterest
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
Definition: dummy-client-face.hpp:175
signal.hpp
ndn::util::DummyClientFace::m_processEventsOverride
std::function< void(time::milliseconds)> m_processEventsOverride
Definition: dummy-client-face.hpp:194
key-chain.hpp
ndn::util::DummyClientFace::m_internalKeyChain
std::unique_ptr< KeyChain > m_internalKeyChain
Definition: dummy-client-face.hpp:192
ndn::util::DummyClientFace::linkTo
void linkTo(DummyClientFace &other)
link another DummyClientFace through a broadcast media
Definition: dummy-client-face.cpp:290
ndn::util::DummyClientFace::Options::Options
Options(bool enablePacketLogging, bool enableRegistrationReply)
Definition: dummy-client-face.hpp:50
ndn::Face
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
ndn::util::DummyClientFace::~DummyClientFace
~DummyClientFace()
Definition: dummy-client-face.cpp:128
ndn::util::DummyClientFace::sentNacks
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
Definition: dummy-client-face.hpp:169
ndn::util::DummyClientFace::Options::Options
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
Definition: dummy-client-face.hpp:42
ndn::util::DummyClientFace::DummyClientFace
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Definition: dummy-client-face.cpp:98
ndn::util::DummyClientFace::Options::processEventsOverride
std::function< void(time::milliseconds)> processEventsOverride
if not empty, face.processEvents() will be overridden by this function
Definition: dummy-client-face.hpp:72
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition: signal.hpp:52
ndn::util::DummyClientFace
a client-side face for unit testing
Definition: dummy-client-face.hpp:35
ndn::security::v2::KeyChain
The interface of signing key management.
Definition: key-chain.hpp:47
ndn::util::DummyClientFace::AlreadyLinkedError::AlreadyLinkedError
AlreadyLinkedError()
Definition: dummy-client-face.cpp:93
ndn::util::DummyClientFace::m_bcastLink
shared_ptr< BroadcastLink > m_bcastLink
Definition: dummy-client-face.hpp:191
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
ndn::util::DummyClientFace::Options::enablePacketLogging
bool enablePacketLogging
if true, packets sent out of DummyClientFace will be appended to a container
Definition: dummy-client-face.hpp:63
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
ndn::util::DummyClientFace::sentData
std::vector< Data > sentData
Data sent out of this DummyClientFace.
Definition: dummy-client-face.hpp:161
ndn::util::DummyClientFace::m_keyChain
KeyChain & m_keyChain
Definition: dummy-client-face.hpp:193
ndn::Data
Represents a Data packet.
Definition: data.hpp:36
ndn::util::DummyClientFace::Transport
Definition: dummy-client-face.cpp:36
ndn::util::DummyClientFace::sentInterests
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
Definition: dummy-client-face.hpp:153
face.hpp
ndn::lp::Nack
represents a Network Nack
Definition: nack.hpp:39
ndn::util::DummyClientFace::AlreadyLinkedError
Definition: dummy-client-face.hpp:76
ndn::util::DummyClientFace::Options::enableRegistrationReply
bool enableRegistrationReply
if true, prefix registration command will be automatically replied with a successful response
Definition: dummy-client-face.hpp:68
ndn::util::DummyClientFace::onSendNack
Signal< DummyClientFace, lp::Nack > onSendNack
emits whenever a Nack is sent
Definition: dummy-client-face.hpp:187
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::util::DummyClientFace::Options::Options
Options()
Definition: dummy-client-face.hpp:55