NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 }
45 }
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 }
58 using security::KeyChain;
59 
60 namespace nfd {
61 class Controller;
62 }
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&)> OnInterest;
95 
99 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
100 
104 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
105 
109 typedef function<void()> UnregisterPrefixSuccessCallback;
110 
114 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
115 
119 class Face : noncopyable
120 {
121 public:
122  class Error : public std::runtime_error
123  {
124  public:
125  explicit
126  Error(const std::string& what)
127  : std::runtime_error(what)
128  {
129  }
130  };
131 
132 public: // constructors
139  Face();
140 
167  explicit
168  Face(boost::asio::io_service& ioService);
169 
177  explicit
178  Face(shared_ptr<Transport> transport);
179 
190  Face(shared_ptr<Transport> transport,
191  boost::asio::io_service& ioService);
192 
202  Face(shared_ptr<Transport> transport,
203  boost::asio::io_service& ioService,
204  KeyChain& keyChain);
205 
206  ~Face();
207 
208 public: // consumer
218  const PendingInterestId*
219  expressInterest(const Interest& interest,
220  const DataCallback& afterSatisfied,
221  const NackCallback& afterNacked,
222  const TimeoutCallback& afterTimeout);
223 
237  const PendingInterestId*
238  expressInterest(const Interest& interest,
239  const OnData& onData,
240  const OnTimeout& onTimeout = nullptr);
241 
256  const PendingInterestId*
257  expressInterest(const Name& name,
258  const Interest& tmpl,
259  const OnData& onData,
260  const OnTimeout& onTimeout = nullptr);
261 
267  void
268  removePendingInterest(const PendingInterestId* pendingInterestId);
269 
273  void
274  removeAllPendingInterests();
275 
279  size_t
280  getNPendingInterests() const;
281 
282 public: // producer
303  const RegisteredPrefixId*
304  setInterestFilter(const InterestFilter& interestFilter,
305  const OnInterest& onInterest,
306  const RegisterPrefixFailureCallback& onFailure,
307  const security::SigningInfo& signingInfo = security::SigningInfo(),
308  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
309 
331  const RegisteredPrefixId*
332  setInterestFilter(const InterestFilter& interestFilter,
333  const OnInterest& onInterest,
334  const RegisterPrefixSuccessCallback& onSuccess,
335  const RegisterPrefixFailureCallback& onFailure,
336  const security::SigningInfo& signingInfo = security::SigningInfo(),
337  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
338 
351  const InterestFilterId*
352  setInterestFilter(const InterestFilter& interestFilter,
353  const OnInterest& onInterest);
354 
355 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
356 
379  DEPRECATED(
380  const RegisteredPrefixId*
381  setInterestFilter(const InterestFilter& interestFilter,
382  const OnInterest& onInterest,
383  const RegisterPrefixSuccessCallback& onSuccess,
384  const RegisterPrefixFailureCallback& onFailure,
385  const IdentityCertificate& certificate,
386  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
387 
410  DEPRECATED(
411  const RegisteredPrefixId*
412  setInterestFilter(const InterestFilter& interestFilter,
413  const OnInterest& onInterest,
414  const RegisterPrefixFailureCallback& onFailure,
415  const IdentityCertificate& certificate,
416  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
417 
439  DEPRECATED(
440  const RegisteredPrefixId*
441  setInterestFilter(const InterestFilter& interestFilter,
442  const OnInterest& onInterest,
443  const RegisterPrefixSuccessCallback& onSuccess,
444  const RegisterPrefixFailureCallback& onFailure,
445  const Name& identity,
446  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
447 
468  DEPRECATED(
469  const RegisteredPrefixId*
470  setInterestFilter(const InterestFilter& interestFilter,
471  const OnInterest& onInterest,
472  const RegisterPrefixFailureCallback& onFailure,
473  const Name& identity,
474  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
475 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
476 
494  const RegisteredPrefixId*
495  registerPrefix(const Name& prefix,
496  const RegisterPrefixSuccessCallback& onSuccess,
497  const RegisterPrefixFailureCallback& onFailure,
498  const security::SigningInfo& signingInfo = security::SigningInfo(),
499  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
500 
501 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
502 
520  DEPRECATED(
521  const RegisteredPrefixId*
522  registerPrefix(const Name& prefix,
523  const RegisterPrefixSuccessCallback& onSuccess,
524  const RegisterPrefixFailureCallback& onFailure,
525  const IdentityCertificate& certificate,
526  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
527 
546  DEPRECATED(
547  const RegisteredPrefixId*
548  registerPrefix(const Name& prefix,
549  const RegisterPrefixSuccessCallback& onSuccess,
550  const RegisterPrefixFailureCallback& onFailure,
551  const Name& identity,
552  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
553 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
554 
567  void
568  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
569 
578  void
579  unsetInterestFilter(const InterestFilterId* interestFilterId);
580 
594  void
595  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
596  const UnregisterPrefixSuccessCallback& onSuccess,
597  const UnregisterPrefixFailureCallback& onFailure);
598 
612  void
613  put(const Data& data);
614 
620  void
621  put(const lp::Nack& nack);
622 
623 public: // IO routine
645  void
646  processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
647  bool keepThread = false);
648 
657  void
658  shutdown();
659 
663  boost::asio::io_service&
665  {
666  return *static_cast<boost::asio::io_service*>(nullptr);
667  }
668 
673  shared_ptr<Transport>
674  getTransport();
675 
676 private:
677 
681  shared_ptr<Transport>
682  makeDefaultTransport();
683 
688  void
689  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
690 
691  void
692  onReceiveElement(const Block& blockFromDaemon);
693 
694  void
695  asyncShutdown();
696 
697 private:
698  shared_ptr<Transport> m_transport;
699 
700  unique_ptr<nfd::Controller> m_nfdController;
701 
702  class Impl;
703  unique_ptr<Impl> m_impl;
704 };
705 
706 } // namespace ndn
707 
708 #endif // NDN_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Error(const std::string &what)
Definition: face.hpp:126
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback called when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:114
Copyright (c) 2013-2015 Regents of the University of California.
The packet signing interface.
Definition: key-chain.hpp:48
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
function< void(const Interest &)> OnTimeout
Callback called when expressed Interest times out.
Definition: face.hpp:89
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback called when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:94
Copyright (c) 2013-2015 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
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:119
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback called when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:104
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback called when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:99
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:664
function< void(const Interest &, Data &)> OnData
Callback called when expressed Interest gets satisfied with Data packet.
Definition: face.hpp:83
function< void()> UnregisterPrefixSuccessCallback
Callback called when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:109
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42
#define DEPRECATED(func)
Definition: common.hpp:85
function< void(const Interest &)> TimeoutCallback
Callback called when expressed Interest times out.
Definition: face.hpp:77
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback called when Nack is sent in response to expressed Interest.
Definition: face.hpp:72
represents a Data packet
Definition: data.hpp:39
function< void(const Interest &, const Data &)> DataCallback
Callback called when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:67