NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22 #ifndef NDN_FACE_HPP
23 #define NDN_FACE_HPP
24 
25 #include "common.hpp"
26 
27 #include "name.hpp"
28 #include "interest.hpp"
29 #include "interest-filter.hpp"
30 #include "data.hpp"
32 #include "lp/nack.hpp"
34 
35 #define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
36 
37 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
39 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
40 
41 namespace boost {
42 namespace asio {
43 class io_service;
44 } // namespace asio
45 } // namespace boost
46 
47 namespace ndn {
48 
49 class Transport;
50 
51 class PendingInterestId;
52 class RegisteredPrefixId;
53 class InterestFilterId;
54 
55 namespace security {
56 class KeyChain;
57 } // namespace security
58 using security::KeyChain;
59 
60 namespace nfd {
61 class Controller;
62 } // namespace nfd
63 
67 typedef function<void(const Interest&, const Data&)> DataCallback;
68 
72 typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
73 
77 typedef function<void(const Interest&)> TimeoutCallback;
78 
83 typedef function<void(const Interest&, Data&)> OnData;
84 
89 typedef function<void(const Interest&)> OnTimeout;
90 
94 typedef function<void(const InterestFilter&, const Interest&)> InterestCallback;
95 
100 typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
101 
105 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
106 
110 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
111 
115 typedef function<void()> UnregisterPrefixSuccessCallback;
116 
120 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
121 
125 class Face : noncopyable
126 {
127 public:
128  class Error : public std::runtime_error
129  {
130  public:
131  explicit
132  Error(const std::string& what)
133  : std::runtime_error(what)
134  {
135  }
136  };
137 
138 public: // constructors
150  explicit
151  Face(shared_ptr<Transport> transport = nullptr);
152 
181  explicit
182  Face(boost::asio::io_service& ioService);
183 
196  Face(shared_ptr<Transport> transport, KeyChain& keyChain);
197 
211  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
212 
227  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
228 
229  ~Face();
230 
231 public: // consumer
241  const PendingInterestId*
242  expressInterest(const Interest& interest,
243  const DataCallback& afterSatisfied,
244  const NackCallback& afterNacked,
245  const TimeoutCallback& afterTimeout);
246 
260  const PendingInterestId*
261  expressInterest(const Interest& interest,
262  const OnData& onData,
263  const OnTimeout& onTimeout = nullptr);
264 
279  const PendingInterestId*
280  expressInterest(const Name& name,
281  const Interest& tmpl,
282  const OnData& onData,
283  const OnTimeout& onTimeout = nullptr);
284 
290  void
291  removePendingInterest(const PendingInterestId* pendingInterestId);
292 
296  void
297  removeAllPendingInterests();
298 
302  size_t
303  getNPendingInterests() const;
304 
305 public: // producer
326  const RegisteredPrefixId*
327  setInterestFilter(const InterestFilter& interestFilter,
328  const InterestCallback& onInterest,
329  const RegisterPrefixFailureCallback& onFailure,
330  const security::SigningInfo& signingInfo = security::SigningInfo(),
331  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
332 
354  const RegisteredPrefixId*
355  setInterestFilter(const InterestFilter& interestFilter,
356  const InterestCallback& onInterest,
357  const RegisterPrefixSuccessCallback& onSuccess,
358  const RegisterPrefixFailureCallback& onFailure,
359  const security::SigningInfo& signingInfo = security::SigningInfo(),
360  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
361 
374  const InterestFilterId*
375  setInterestFilter(const InterestFilter& interestFilter,
376  const InterestCallback& onInterest);
377 
378 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
379 
402  DEPRECATED(
403  const RegisteredPrefixId*
404  setInterestFilter(const InterestFilter& interestFilter,
405  const OnInterest& onInterest,
406  const RegisterPrefixSuccessCallback& onSuccess,
407  const RegisterPrefixFailureCallback& onFailure,
408  const security::v1::IdentityCertificate& certificate,
409  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
410 
433  DEPRECATED(
434  const RegisteredPrefixId*
435  setInterestFilter(const InterestFilter& interestFilter,
436  const OnInterest& onInterest,
437  const RegisterPrefixFailureCallback& onFailure,
438  const security::v1::IdentityCertificate& certificate,
439  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
440 
462  DEPRECATED(
463  const RegisteredPrefixId*
464  setInterestFilter(const InterestFilter& interestFilter,
465  const OnInterest& onInterest,
466  const RegisterPrefixSuccessCallback& onSuccess,
467  const RegisterPrefixFailureCallback& onFailure,
468  const Name& identity,
469  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
470 
491  DEPRECATED(
492  const RegisteredPrefixId*
493  setInterestFilter(const InterestFilter& interestFilter,
494  const OnInterest& onInterest,
495  const RegisterPrefixFailureCallback& onFailure,
496  const Name& identity,
497  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
498 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
499 
517  const RegisteredPrefixId*
518  registerPrefix(const Name& prefix,
519  const RegisterPrefixSuccessCallback& onSuccess,
520  const RegisterPrefixFailureCallback& onFailure,
521  const security::SigningInfo& signingInfo = security::SigningInfo(),
522  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
523 
524 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
525 
543  DEPRECATED(
544  const RegisteredPrefixId*
545  registerPrefix(const Name& prefix,
546  const RegisterPrefixSuccessCallback& onSuccess,
547  const RegisterPrefixFailureCallback& onFailure,
548  const security::v1::IdentityCertificate& certificate,
549  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
550 
569  DEPRECATED(
570  const RegisteredPrefixId*
571  registerPrefix(const Name& prefix,
572  const RegisterPrefixSuccessCallback& onSuccess,
573  const RegisterPrefixFailureCallback& onFailure,
574  const Name& identity,
575  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
576 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
577 
590  void
591  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
592 
601  void
602  unsetInterestFilter(const InterestFilterId* interestFilterId);
603 
617  void
618  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
619  const UnregisterPrefixSuccessCallback& onSuccess,
620  const UnregisterPrefixFailureCallback& onFailure);
621 
635  void
636  put(const Data& data);
637 
643  void
644  put(const lp::Nack& nack);
645 
646 public: // IO routine
668  void
669  processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
670  bool keepThread = false)
671  {
672  this->doProcessEvents(timeout, keepThread);
673  }
674 
683  void
684  shutdown();
685 
689  boost::asio::io_service&
691  {
692  return *static_cast<boost::asio::io_service*>(nullptr);
693  }
694 
699  shared_ptr<Transport>
700  getTransport();
701 
702 protected:
703  virtual void
704  doProcessEvents(const time::milliseconds& timeout, bool keepThread);
705 
706 private:
710  shared_ptr<Transport>
711  makeDefaultTransport();
712 
717  void
718  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
719 
720  void
721  onReceiveElement(const Block& blockFromDaemon);
722 
723  void
724  asyncShutdown();
725 
726 private:
727  shared_ptr<Transport> m_transport;
728 
729  unique_ptr<nfd::Controller> m_nfdController;
730 
731  class Impl;
732  shared_ptr<Impl> m_impl;
733 };
734 
735 } // namespace ndn
736 
737 #endif // NDN_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Error(const std::string &what)
Definition: face.hpp:132
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:120
Copyright (c) 2013-2016 Regents of the University of California.
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
The packet signing interface.
Definition: key-chain.hpp:47
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:42
function< void(const Interest &)> OnTimeout
Callback invoked when expressed Interest times out.
Definition: face.hpp:89
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:100
Copyright (c) 2013-2016 Regents of the University of California.
Signing parameters passed to KeyChain.
represents a Network Nack
Definition: nack.hpp:40
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:125
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:110
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:105
Name abstraction to represent an absolute name.
Definition: name.hpp:46
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
Definition: face.hpp:690
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:94
function< void(const Interest &, Data &)> OnData
Callback invoked when expressed Interest gets satisfied with Data packet.
Definition: face.hpp:83
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:115
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42
#define DEPRECATED(func)
Definition: common.hpp:71
void processEvents(const time::milliseconds &timeout=time::milliseconds::zero(), bool keepThread=false)
Process any data to receive or call timeout callbacks.
Definition: face.hpp:669
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
Definition: face.hpp:77
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
Definition: face.hpp:72
represents a Data packet
Definition: data.hpp:37
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:67