NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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_FACE_HPP
23 #define NDN_FACE_HPP
24 
25 #include "data.hpp"
26 #include "name.hpp"
27 #include "interest.hpp"
28 #include "interest-filter.hpp"
30 #include "lp/nack.hpp"
31 #include "net/asio-fwd.hpp"
32 #include "security/key-chain.hpp"
34 
35 namespace ndn {
36 
37 class Transport;
38 
39 class PendingInterestId;
40 class RegisteredPrefixId;
41 class InterestFilterId;
42 
43 namespace nfd {
44 class Controller;
45 } // namespace nfd
46 
50 typedef function<void(const Interest&, const Data&)> DataCallback;
51 
55 typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
56 
60 typedef function<void(const Interest&)> TimeoutCallback;
61 
65 typedef function<void(const InterestFilter&, const Interest&)> InterestCallback;
66 
70 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
71 
75 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
76 
80 typedef function<void()> UnregisterPrefixSuccessCallback;
81 
85 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
86 
90 class Face : noncopyable
91 {
92 public:
93  class Error : public std::runtime_error
94  {
95  public:
96  explicit
97  Error(const std::string& what)
98  : std::runtime_error(what)
99  {
100  }
101  };
102 
107  {
108  public:
115  OversizedPacketError(char pktType, const Name& name, size_t wireSize);
116 
117  public:
118  const char pktType;
119  const Name name;
120  const size_t wireSize;
121  };
122 
123 public: // constructors
152  explicit
153  Face(DummyIoService& ioService);
154 
166  explicit
167  Face(shared_ptr<Transport> transport = nullptr);
168 
181  Face(shared_ptr<Transport> transport, KeyChain& keyChain);
182 
183  virtual
184  ~Face();
185 
186 public: // consumer
197  const PendingInterestId*
198  expressInterest(const Interest& interest,
199  const DataCallback& afterSatisfied,
200  const NackCallback& afterNacked,
201  const TimeoutCallback& afterTimeout);
202 
208  void
209  removePendingInterest(const PendingInterestId* pendingInterestId);
210 
214  void
216 
220  size_t
221  getNPendingInterests() const;
222 
223 public: // producer
244  const RegisteredPrefixId*
245  setInterestFilter(const InterestFilter& interestFilter,
246  const InterestCallback& onInterest,
247  const RegisterPrefixFailureCallback& onFailure,
248  const security::SigningInfo& signingInfo = security::SigningInfo(),
249  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
250 
272  const RegisteredPrefixId*
273  setInterestFilter(const InterestFilter& interestFilter,
274  const InterestCallback& onInterest,
275  const RegisterPrefixSuccessCallback& onSuccess,
276  const RegisterPrefixFailureCallback& onFailure,
277  const security::SigningInfo& signingInfo = security::SigningInfo(),
278  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
279 
292  const InterestFilterId*
293  setInterestFilter(const InterestFilter& interestFilter,
294  const InterestCallback& onInterest);
295 
313  const RegisteredPrefixId*
314  registerPrefix(const Name& prefix,
315  const RegisterPrefixSuccessCallback& onSuccess,
316  const RegisterPrefixFailureCallback& onFailure,
317  const security::SigningInfo& signingInfo = security::SigningInfo(),
318  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
319 
332  void
333  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
334 
343  void
344  unsetInterestFilter(const InterestFilterId* interestFilterId);
345 
359  void
360  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
361  const UnregisterPrefixSuccessCallback& onSuccess,
362  const UnregisterPrefixFailureCallback& onFailure);
363 
374  void
375  put(Data data);
376 
383  void
384  put(lp::Nack nack);
385 
386 public: // IO routine
410  void
411  processEvents(time::milliseconds timeout = time::milliseconds::zero(),
412  bool keepThread = false)
413  {
414  this->doProcessEvents(timeout, keepThread);
415  }
416 
425  void
426  shutdown();
427 
433  {
434  static DummyIoService io;
435  return io;
436  }
437 
442  shared_ptr<Transport>
443  getTransport();
444 
445 protected:
446  virtual void
447  doProcessEvents(time::milliseconds timeout, bool keepThread);
448 
449 private:
453  shared_ptr<Transport>
454  makeDefaultTransport();
455 
460  void
461  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
462 
463  void
464  onReceiveElement(const Block& blockFromDaemon);
465 
466  void
467  asyncShutdown();
468 
469 private:
470  shared_ptr<Transport> m_transport;
471 
472  unique_ptr<nfd::Controller> m_nfdController;
473 
474  class Impl;
475  shared_ptr<Impl> m_impl;
476 };
477 
478 } // namespace ndn
479 
480 #endif // NDN_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
Definition: face.cpp:265
Error(const std::string &what)
Definition: face.hpp:97
The interface of signing key management.
Definition: key-chain.hpp:46
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:85
virtual ~Face()
const RegisteredPrefixId * setInterestFilter(const InterestFilter &interestFilter, const InterestCallback &onInterest, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the fil...
Definition: face.cpp:186
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
DummyIoService & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
Definition: face.hpp:432
STL namespace.
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
Represents an Interest packet.
Definition: interest.hpp:42
Signing parameters passed to KeyChain.
void unregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
Unregister prefix from RIB.
Definition: face.cpp:255
represents a Network Nack
Definition: nack.hpp:40
void removeAllPendingInterests()
Cancel all previously expressed Interests.
Definition: face.cpp:156
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
size_t getNPendingInterests() const
Get number of pending Interests.
Definition: face.cpp:164
void shutdown()
Shutdown face operations.
Definition: face.cpp:270
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:75
void processEvents(time::milliseconds timeout=time::milliseconds::zero(), bool keepThread=false)
Process any data to receive or call timeout callbacks.
Definition: face.hpp:411
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:70
Represents an absolute name.
Definition: name.hpp:42
void unsetInterestFilter(const RegisteredPrefixId *registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId.
Definition: face.cpp:239
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:65
Face(DummyIoService &ioService)
Create Face using default transport and given io_service.
Definition: face.cpp:65
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:80
void put(Data data)
Publish data packet.
Definition: face.cpp:170
OversizedPacketError(char pktType, const Name &name, size_t wireSize)
Constructor.
Definition: face.cpp:55
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Definition: face.cpp:132
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
Definition: face.hpp:60
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
Definition: face.hpp:55
Represents a Data packet.
Definition: data.hpp:35
const RegisteredPrefixId * registerPrefix(const Name &prefix, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Register prefix with the connected NDN forwarder.
Definition: face.cpp:226
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:50
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.
Definition: face.cpp:148
Exception thrown when attempting to send a packet over size limit.
Definition: face.hpp:106