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; -*- */
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 "security/key-chain.hpp"
33 
34 namespace boost {
35 namespace asio {
36 class io_service;
37 } // namespace asio
38 } // namespace boost
39 
40 namespace ndn {
41 
42 class Transport;
43 
44 class PendingInterestId;
45 class RegisteredPrefixId;
46 class InterestFilterId;
47 
48 namespace nfd {
49 class Controller;
50 } // namespace nfd
51 
55 typedef function<void(const Interest&, const Data&)> DataCallback;
56 
60 typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
61 
65 typedef function<void(const Interest&)> TimeoutCallback;
66 
70 typedef function<void(const InterestFilter&, const Interest&)> InterestCallback;
71 
75 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
76 
80 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
81 
85 typedef function<void()> UnregisterPrefixSuccessCallback;
86 
90 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
91 
95 class Face : noncopyable
96 {
97 public:
98  class Error : public std::runtime_error
99  {
100  public:
101  explicit
102  Error(const std::string& what)
103  : std::runtime_error(what)
104  {
105  }
106  };
107 
112  {
113  public:
120  OversizedPacketError(char pktType, const Name& name, size_t wireSize);
121 
122  public:
123  const char pktType;
124  const Name name;
125  const size_t wireSize;
126  };
127 
128 public: // constructors
140  explicit
141  Face(shared_ptr<Transport> transport = nullptr);
142 
171  explicit
172  Face(boost::asio::io_service& ioService);
173 
186  Face(shared_ptr<Transport> transport, KeyChain& keyChain);
187 
201  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
202 
217  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
218 
219  virtual
220  ~Face();
221 
222 public: // consumer
233  const PendingInterestId*
234  expressInterest(const Interest& interest,
235  const DataCallback& afterSatisfied,
236  const NackCallback& afterNacked,
237  const TimeoutCallback& afterTimeout);
238 
244  void
245  removePendingInterest(const PendingInterestId* pendingInterestId);
246 
250  void
251  removeAllPendingInterests();
252 
256  size_t
257  getNPendingInterests() const;
258 
259 public: // producer
280  const RegisteredPrefixId*
281  setInterestFilter(const InterestFilter& interestFilter,
282  const InterestCallback& onInterest,
283  const RegisterPrefixFailureCallback& onFailure,
284  const security::SigningInfo& signingInfo = security::SigningInfo(),
285  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
286 
308  const RegisteredPrefixId*
309  setInterestFilter(const InterestFilter& interestFilter,
310  const InterestCallback& onInterest,
311  const RegisterPrefixSuccessCallback& onSuccess,
312  const RegisterPrefixFailureCallback& onFailure,
313  const security::SigningInfo& signingInfo = security::SigningInfo(),
314  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
315 
328  const InterestFilterId*
329  setInterestFilter(const InterestFilter& interestFilter,
330  const InterestCallback& onInterest);
331 
349  const RegisteredPrefixId*
350  registerPrefix(const Name& prefix,
351  const RegisterPrefixSuccessCallback& onSuccess,
352  const RegisterPrefixFailureCallback& onFailure,
353  const security::SigningInfo& signingInfo = security::SigningInfo(),
354  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
355 
368  void
369  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
370 
379  void
380  unsetInterestFilter(const InterestFilterId* interestFilterId);
381 
395  void
396  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
397  const UnregisterPrefixSuccessCallback& onSuccess,
398  const UnregisterPrefixFailureCallback& onFailure);
399 
410  void
411  put(Data data);
412 
419  void
420  put(lp::Nack nack);
421 
422 public: // IO routine
446  void
447  processEvents(time::milliseconds timeout = time::milliseconds::zero(),
448  bool keepThread = false)
449  {
450  this->doProcessEvents(timeout, keepThread);
451  }
452 
461  void
462  shutdown();
463 
467  boost::asio::io_service&
469  {
470  return *static_cast<boost::asio::io_service*>(nullptr);
471  }
472 
477  shared_ptr<Transport>
478  getTransport();
479 
480 protected:
481  virtual void
482  doProcessEvents(time::milliseconds timeout, bool keepThread);
483 
484 private:
488  shared_ptr<Transport>
489  makeDefaultTransport();
490 
495  void
496  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
497 
498  void
499  onReceiveElement(const Block& blockFromDaemon);
500 
501  void
502  asyncShutdown();
503 
504 private:
505  shared_ptr<Transport> m_transport;
506 
507  unique_ptr<nfd::Controller> m_nfdController;
508 
509  class Impl;
510  shared_ptr<Impl> m_impl;
511 };
512 
513 } // namespace ndn
514 
515 #endif // NDN_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Error(const std::string &what)
Definition: face.hpp:102
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:90
Copyright (c) 2013-2017 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
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
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.
represents a Network Nack
Definition: nack.hpp:40
ndn Face
Definition: face-impl.hpp:41
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:95
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:80
void processEvents(time::milliseconds timeout=time::milliseconds::zero(), bool keepThread=false)
Process any data to receive or call timeout callbacks.
Definition: face.hpp:447
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:75
Represents an absolute name.
Definition: name.hpp:42
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
Definition: face.hpp:468
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:70
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:85
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
Definition: face.hpp:65
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
Definition: face.hpp:60
Represents a Data packet.
Definition: data.hpp:35
ndn security v2 KeyChain
Definition: key-chain.cpp:76
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:55
Exception thrown when attempting to send a packet over size limit.
Definition: face.hpp:111