31 #include "ns3/node-list.h" 32 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp" 33 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 34 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" 41 #define IO_CAPTURE_WEAK_IMPL(OP) \ 43 weak_ptr<Impl> implWeak(m_impl); \ 44 m_impl->m_scheduler.schedule(time::seconds(0), [=] { \ 45 auto impl = implWeak.lock(); \ 46 if (impl != nullptr) { 47 #define IO_CAPTURE_WEAK_IMPL_END \ 55 :
Error((pktType ==
'I' ?
"Interest " : pktType ==
'D' ?
"Data " :
"Nack ") +
56 name.toUri() +
" encodes into " +
to_string(wireSize) +
" octets, " 76 construct(
std::move(transport), keyChain);
80 Face::makeDefaultTransport()
82 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
84 "NDN stack should be installed on the node " << node);
86 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
88 ::nfd::face::GenericLinkService::Options serviceOpts;
89 serviceOpts.allowLocalFields =
true;
91 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
92 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
95 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
96 clientTransport->connectToForwarder(forwarderTransport);
100 return clientTransport;
104 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
106 BOOST_ASSERT(m_impl ==
nullptr);
107 m_impl = make_shared<Impl>(*
this, keyChain);
109 if (transport ==
nullptr) {
110 transport = makeDefaultTransport();
111 BOOST_ASSERT(transport !=
nullptr);
116 impl->ensureConnected(
false);
128 auto id = m_impl->m_pendingInterestTable.allocateId();
130 auto interest2 = make_shared<Interest>(interest);
131 interest2->getNonce();
134 impl->expressInterest(
id, interest2, afterSatisfied, afterNacked, afterTimeout);
144 impl->removeAllPendingInterests();
151 return m_impl->m_pendingInterestTable.size();
175 return setInterestFilter(filter, onInterest,
nullptr, onFailure, signingInfo, flags);
187 auto id = m_impl->registerPrefix(filter.
getPrefix(), onSuccess, onFailure, flags, options,
195 auto id = m_impl->m_interestFilterTable.allocateId();
198 impl->setInterestFilter(
id, filter, onInterest);
214 auto id = m_impl->registerPrefix(prefix, onSuccess, onFailure, flags, options,
nullopt,
nullptr);
228 if (m_transport->isConnected())
229 m_transport->close();
236 template<
typename NetPkt>
240 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
241 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
249 Face::onReceiveElement(
const Block& blockFromDaemon)
255 Block netPacket({frag.first, frag.second});
256 switch (netPacket.type()) {
258 auto interest = make_shared<Interest>(netPacket);
260 auto nack = make_shared<lp::Nack>(
std::move(*interest));
263 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
264 m_impl->nackPendingInterests(*nack);
269 m_impl->processIncomingInterest(
std::move(interest));
274 auto data = make_shared<Data>(netPacket);
277 m_impl->satisfyPendingInterests(*data);
284 : CancelHandle([w =
std::move(weakImpl),
id] {
285 auto impl = w.lock();
286 if (impl !=
nullptr) {
287 impl->asyncRemovePendingInterest(
id);
294 : CancelHandle([=] { unregister(weakImpl,
id,
nullptr,
nullptr); })
308 onFailure(
"RegisteredPrefixHandle is empty");
313 unregister(m_weakImpl, m_id, onSuccess, onFailure);
322 auto impl = weakImpl.lock();
323 if (impl !=
nullptr) {
324 impl->asyncUnregisterPrefix(
id, onSuccess, onFailure);
326 else if (onFailure) {
327 onFailure(
"Face already closed");
332 : CancelHandle([w =
std::move(weakImpl),
id] {
333 auto impl = w.lock();
334 if (impl !=
nullptr) {
335 impl->asyncUnsetInterestFilter(
id);
NDN_CXX_NODISCARD bool has() const
Copyright (c) 2011-2015 Regents of the University of California.
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregistering a prefix fails.
std::string to_string(const T &val)
void unregister(const UnregisterPrefixSuccessCallback &onSuccess=nullptr, const UnregisterPrefixFailureCallback &onFailure=nullptr)
Unregister the prefix.
const Name & getPrefix() const
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
#define IO_CAPTURE_WEAK_IMPL_END
#define NDN_LOG_DEBUG(expression)
Represents a TLV element of the NDN packet format.
Represents an Interest packet.
static void extractLpLocalFields(NetPkt &netPacket, const lp::Packet &lpPacket)
extract local fields from NDNLPv2 packet and tag onto a network layer packet
Signing parameters passed to KeyChain.
represents a Network Nack
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 transport.
RegisteredPrefixHandle 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.
contains options for ControlCommand execution
#define IO_CAPTURE_WEAK_IMPL(OP)
Handle for a pending Interest.
size_t getNPendingInterests() const
Get number of pending Interests.
void shutdown()
Shutdown face operations.
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.
Represents an absolute name.
represents the underlying protocol and address used by a Face
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Implementation network-layer of NDN stack.
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when an incoming Interest matches the specified InterestFilter.
InterestFilterHandle() noexcept=default
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregistering a prefix succeeds.
RegisteredPrefixHandle() noexcept=default
static KeyChain & getKeyChain()
void put(Data data)
Publish data packet.
OversizedPacketError(char pktType, const Name &name, size_t wireSize)
Constructor.
Handle for a registered Interest filter.
PendingInterestHandle() noexcept=default
function< void(const Interest &)> TimeoutCallback
Callback invoked when an expressed Interest times out.
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when a Nack is received in response to an expressed Interest.
Represents a Data packet.
RegisteredPrefixHandle setInterestFilter(const InterestFilter &filter, 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...
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted)
const nullopt_t nullopt((nullopt_t::init()))
Handle for a registered prefix.
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when an expressed Interest is satisfied by a Data packet.
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.
boost::chrono::milliseconds milliseconds