32 #include "ns3/node-list.h" 33 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp" 34 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 35 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" 40 #define IO_CAPTURE_WEAK_IMPL(OP) \ 42 weak_ptr<Impl> implWeak(m_impl); \ 43 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \ 44 auto impl = implWeak.lock(); \ 45 if (impl != nullptr) { 46 #define IO_CAPTURE_WEAK_IMPL_END \ 54 : m_impl(new Impl(*this))
60 : m_impl(new Impl(*this))
66 : m_impl(new Impl(*this))
68 construct(transport, keyChain);
71 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
72 : m_impl(new Impl(*this))
77 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService,
KeyChain& keyChain)
78 : m_impl(new Impl(*this))
80 construct(transport, keyChain);
84 Face::makeDefaultTransport()
86 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
88 "NDN stack should be installed on the node " << node);
90 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
95 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
96 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
99 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
100 clientTransport->connectToForwarder(forwarderTransport);
104 return clientTransport;
108 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
110 if (transport ==
nullptr) {
111 transport = makeDefaultTransport();
113 BOOST_ASSERT(transport !=
nullptr);
114 m_transport = transport;
119 impl->ensureConnected(
false);
125 shared_ptr<Transport>
131 const PendingInterestId*
137 shared_ptr<Interest> interestToExpress = make_shared<Interest>(interest);
141 BOOST_THROW_EXCEPTION(
Error(
"Interest size exceeds maximum limit"));
146 impl->asyncExpressInterest(interestToExpress, afterSatisfied, afterNacked, afterTimeout);
149 return reinterpret_cast<const PendingInterestId*
>(interestToExpress.get());
152 const PendingInterestId*
160 if (onData !=
nullptr) {
161 onData(interest, const_cast<Data&>(data));
165 if (onTimeout !=
nullptr) {
173 const PendingInterestId*
185 impl->asyncRemovePendingInterest(pendingInterestId);
193 impl->asyncRemoveAllPendingInterests();
200 return m_impl->m_pendingInterestTable.size();
209 bool hasLpFields =
false;
212 if (cachePolicyTag !=
nullptr) {
218 if (congestionMarkTag !=
nullptr) {
229 BOOST_THROW_EXCEPTION(
Error(
"Data size exceeds maximum limit"));
232 impl->asyncSend(wire);
245 if (congestionMarkTag !=
nullptr) {
252 BOOST_THROW_EXCEPTION(
Error(
"Nack size exceeds maximum limit"));
255 impl->asyncSend(wire);
259 const RegisteredPrefixId*
266 return setInterestFilter(interestFilter, onInterest,
nullptr, onFailure, signingInfo, flags);
269 const RegisteredPrefixId*
277 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
282 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
283 onSuccess, onFailure, flags, options);
286 const InterestFilterId*
290 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
293 impl->asyncSetInterestFilter(filter);
296 return reinterpret_cast<const InterestFilterId*
>(filter.get());
299 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 301 const RegisteredPrefixId*
313 return setInterestFilter(interestFilter, onInterest, onSuccess, onFailure, signingInfo, flags);
316 const RegisteredPrefixId*
327 return setInterestFilter(interestFilter, onInterest, onFailure, signingInfo, flags);
330 const RegisteredPrefixId*
335 const Name& identity,
340 onSuccess, onFailure,
344 const RegisteredPrefixId*
348 const Name& identity,
352 return setInterestFilter(interestFilter, onInterest, onFailure, signingInfo, flags);
355 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 357 const RegisteredPrefixId*
367 return m_impl->registerPrefix(prefix,
nullptr, onSuccess, onFailure, flags, options);
370 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 371 const RegisteredPrefixId*
382 return registerPrefix(prefix, onSuccess, onFailure, signingInfo, flags);
385 const RegisteredPrefixId*
389 const Name& identity,
393 return registerPrefix(prefix, onSuccess, onFailure, signingInfo, flags);
395 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 401 impl->asyncUnregisterPrefix(registeredPrefixId,
nullptr,
nullptr);
409 impl->asyncUnsetInterestFilter(interestFilterId);
419 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
432 this->asyncShutdown();
437 Face::asyncShutdown()
439 m_impl->m_pendingInterestTable.clear();
440 m_impl->m_registeredPrefixTable.clear();
442 if (m_transport->isConnected())
443 m_transport->close();
449 template<
typename NetPkt>
463 Face::onReceiveElement(
const Block& blockFromDaemon)
468 Buffer::const_iterator begin, end;
470 Block netPacket(&*begin, std::distance(begin, end));
471 switch (netPacket.type()) {
473 auto interest = make_shared<Interest>(netPacket);
475 auto nack = make_shared<lp::Nack>(std::move(*interest));
478 m_impl->nackPendingInterests(*nack);
482 m_impl->processInterestFilters(*interest);
487 auto data = make_shared<Data>(netPacket);
489 m_impl->satisfyPendingInterests(*data);
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< T > getTag() const
get a tag item
size_t wireEncode(EncodingImpl< TAG > &encoder) const
append packet to encoder
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
#define IO_CAPTURE_WEAK_IMPL_END
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy ...
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...
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
represents the underlying protocol and address used by a Face
const Name & getName() const
Get name of the Data packet.
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
The packet signing interface.
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
function< void(const Interest &)> OnTimeout
Callback invoked when expressed Interest times out.
const NackHeader & getHeader() const
static void extractLpLocalFields(NetPkt &netPacket, const lp::Packet &lpPacket)
extract local fields from NDNLPv2 packet and tag onto a network layer packet
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback invoked when incoming Interest matches the specified InterestFilter.
virtual void doProcessEvents(const time::milliseconds &timeout, bool keepThread)
Signing parameters passed to KeyChain.
SigningInfo signingByCertificate(const Name &certName)
void unregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
Unregister prefix from RIB.
represents a Network Nack
provides a tag type for simple types
void removeAllPendingInterests()
Cancel all previously expressed Interests.
FIELD::ValueType get(size_t index=0) const
implements a forwarder-side transport that can be paired with another
contains options for ControlCommand execution
size_t getNPendingInterests() const
Get number of pending Interests.
void shutdown()
Shutdown face operations.
SigningInfo signingByIdentity(const Name &identity)
NFD Management protocol client.
Buffer::const_iterator begin() const
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Name abstraction to represent an absolute name.
Buffer::const_iterator end() const
void unsetInterestFilter(const RegisteredPrefixId *registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId.
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters
Implementation network-layer of NDN stack.
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Options that control the behavior of GenericLinkService.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
function< void(const Interest &, Data &)> OnData
Callback invoked when expressed Interest gets satisfied with Data packet.
#define IO_CAPTURE_WEAK_IMPL(OP)
Copyright (c) 2013-2016 Regents of the University of California.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
bool empty() const
Check if name is emtpy.
static KeyChain & getKeyChain()
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
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.
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted)
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.
void put(const Data &data)
Publish data packet.
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size