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
135  explicit
136  Face(shared_ptr<Transport> transport = nullptr);
137 
166  explicit
167  Face(boost::asio::io_service& ioService);
168 
181  Face(shared_ptr<Transport> transport, KeyChain& keyChain);
182 
196  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
197 
212  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
213 
214  virtual
215  ~Face();
216 
217 public: // consumer
228  const PendingInterestId*
229  expressInterest(const Interest& interest,
230  const DataCallback& afterSatisfied,
231  const NackCallback& afterNacked,
232  const TimeoutCallback& afterTimeout);
233 
239  void
240  removePendingInterest(const PendingInterestId* pendingInterestId);
241 
245  void
247 
251  size_t
252  getNPendingInterests() const;
253 
254 public: // producer
275  const RegisteredPrefixId*
276  setInterestFilter(const InterestFilter& interestFilter,
277  const InterestCallback& onInterest,
278  const RegisterPrefixFailureCallback& onFailure,
279  const security::SigningInfo& signingInfo = security::SigningInfo(),
280  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
281 
303  const RegisteredPrefixId*
304  setInterestFilter(const InterestFilter& interestFilter,
305  const InterestCallback& onInterest,
306  const RegisterPrefixSuccessCallback& onSuccess,
307  const RegisterPrefixFailureCallback& onFailure,
308  const security::SigningInfo& signingInfo = security::SigningInfo(),
309  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
310 
323  const InterestFilterId*
324  setInterestFilter(const InterestFilter& interestFilter,
325  const InterestCallback& onInterest);
326 
344  const RegisteredPrefixId*
345  registerPrefix(const Name& prefix,
346  const RegisterPrefixSuccessCallback& onSuccess,
347  const RegisterPrefixFailureCallback& onFailure,
348  const security::SigningInfo& signingInfo = security::SigningInfo(),
349  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
350 
363  void
364  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
365 
374  void
375  unsetInterestFilter(const InterestFilterId* interestFilterId);
376 
390  void
391  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
392  const UnregisterPrefixSuccessCallback& onSuccess,
393  const UnregisterPrefixFailureCallback& onFailure);
394 
405  void
406  put(Data data);
407 
414  void
415  put(lp::Nack nack);
416 
417 public: // IO routine
441  void
442  processEvents(time::milliseconds timeout = time::milliseconds::zero(),
443  bool keepThread = false)
444  {
445  this->doProcessEvents(timeout, keepThread);
446  }
447 
456  void
457  shutdown();
458 
462  boost::asio::io_service&
464  {
465  return *static_cast<boost::asio::io_service*>(nullptr);
466  }
467 
472  shared_ptr<Transport>
473  getTransport();
474 
475 protected:
476  virtual void
477  doProcessEvents(time::milliseconds timeout, bool keepThread);
478 
479 private:
483  shared_ptr<Transport>
484  makeDefaultTransport();
485 
490  void
491  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
492 
493  void
494  onReceiveElement(const Block& blockFromDaemon);
495 
496  void
497  asyncShutdown();
498 
499 private:
500  shared_ptr<Transport> m_transport;
501 
502  unique_ptr<nfd::Controller> m_nfdController;
503 
504  class Impl;
505  shared_ptr<Impl> m_impl;
506 };
507 
508 } // namespace ndn
509 
510 #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:277
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:198
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
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:267
represents a Network Nack
Definition: nack.hpp:40
void removeAllPendingInterests()
Cancel all previously expressed Interests.
Definition: face.cpp:168
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:176
void shutdown()
Shutdown face operations.
Definition: face.cpp:282
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:442
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:251
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
Definition: face.hpp:463
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp: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:182
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:144
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:238
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted)
Definition: face.cpp:65
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:160
Exception thrown when attempting to send a packet over size limit.
Definition: face.hpp:106