NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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-2017 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 "../face.hpp"
26 #include "signal.hpp"
27 #include "../security/key-chain.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 
72  std::function<void(time::milliseconds)> processEventsOverride;
73  };
74 
77  explicit
78  DummyClientFace(const Options& options = Options());
79 
82  explicit
83  DummyClientFace(KeyChain& keyChain, const Options& options = Options());
84 
87  explicit
88  DummyClientFace(boost::asio::io_service& ioService, const Options& options = Options());
89 
92  DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
93  const Options& options = Options());
94 
97  void
98  receive(const Interest& interest);
99 
102  void
103  receive(const Data& data);
104 
107  void
108  receive(const lp::Nack& nack);
109 
110 private:
111  class Transport;
112 
113  void
114  construct(const Options& options);
115 
116  void
118 
119  void
121 
122  void
123  doProcessEvents(time::milliseconds timeout, bool keepThread) override;
124 
125 public:
132  std::vector<Interest> sentInterests;
133 
140  std::vector<Data> sentData;
141 
148  std::vector<lp::Nack> sentNacks;
149 
154  Signal<DummyClientFace, Interest> onSendInterest;
155 
160  Signal<DummyClientFace, Data> onSendData;
161 
166  Signal<DummyClientFace, lp::Nack> onSendNack;
167 
168 private:
169  std::unique_ptr<KeyChain> m_internalKeyChain;
170  KeyChain& m_keyChain;
171  std::function<void(time::milliseconds)> m_processEventsOverride;
172 };
173 
174 } // namespace util
175 } // namespace ndn
176 
177 #endif // NDN_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
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
represents an Interest packet
Definition: interest.hpp:42
std::vector< Data > sentData
Data sent out of this DummyClientFace.
represents a Network Nack
Definition: nack.hpp:40
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:95
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
void receive(const Interest &interest)
cause the Face to receive an interest
a client-side face for unit testing
Options(bool enablePacketLogging, bool enableRegistrationReply)
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
Represents a Data packet.
Definition: data.hpp:35
ndn security v2 KeyChain
Definition: key-chain.cpp:76
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