30 #include "ns3/node-list.h" 31 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp" 32 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 33 #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.scheduleEvent(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, " 65 : m_impl(new
Impl(*this))
71 : m_impl(new
Impl(*this))
77 : m_impl(new
Impl(*this))
79 construct(std::move(transport), keyChain);
83 Face::makeDefaultTransport()
85 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
87 "NDN stack should be installed on the node " << node);
89 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
94 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
95 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
96 auto forwarderTransport = static_cast<::nfd::face::InternalForwarderTransport*>(
nfdFace->getTransport());
98 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
99 clientTransport->connectToForwarder(forwarderTransport);
103 return clientTransport;
107 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
109 if (transport ==
nullptr) {
110 transport = makeDefaultTransport();
112 BOOST_ASSERT(transport !=
nullptr);
113 m_transport = std::move(transport);
115 m_nfdController = make_unique<nfd::Controller>(*
this, keyChain);
118 impl->ensureConnected(
false);
124 shared_ptr<Transport>
130 PendingInterestHandle
136 auto interest2 = make_shared<Interest>(interest);
137 interest2->getNonce();
140 impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout);
150 impl->asyncRemovePendingInterest(pendingInterestId);
158 impl->asyncRemoveAllPendingInterests();
165 return m_impl->m_pendingInterestTable.size();
172 impl->asyncPutData(data);
180 impl->asyncPutNack(nack);
191 return setInterestFilter(interestFilter, onInterest,
nullptr, onFailure, signingInfo, flags);
202 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
207 auto id = m_impl->registerPrefix(interestFilter.
getPrefix(), filter,
208 onSuccess, onFailure, flags, options);
216 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
219 impl->asyncSetInterestFilter(filter);
222 auto id = reinterpret_cast<const InterestFilterId*>(filter.get());
236 auto id = m_impl->registerPrefix(prefix,
nullptr, onSuccess, onFailure, flags, options);
244 impl->asyncUnregisterPrefix(registeredPrefixId,
nullptr,
nullptr);
252 impl->asyncUnsetInterestFilter(interestFilterId);
262 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
275 this->asyncShutdown();
280 Face::asyncShutdown()
282 m_impl->m_pendingInterestTable.clear();
283 m_impl->m_registeredPrefixTable.clear();
285 if (m_transport->isConnected())
286 m_transport->close();
292 template<
typename NetPkt>
296 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
297 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
305 Face::onReceiveElement(
const Block& blockFromDaemon)
310 Buffer::const_iterator begin, end;
312 Block netPacket(&*begin, std::distance(begin, end));
313 switch (netPacket.type()) {
315 auto interest = make_shared<Interest>(netPacket);
317 auto nack = make_shared<lp::Nack>(std::move(*interest));
320 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
321 m_impl->nackPendingInterests(*nack);
326 m_impl->processIncomingInterest(std::move(interest));
331 auto data = make_shared<Data>(netPacket);
334 m_impl->satisfyPendingInterests(*data);
347 : CancelHandle([&face, id] { face.
unregisterPrefix(
id,
nullptr,
nullptr); })
359 if (m_id ==
nullptr) {
360 if (onFailure !=
nullptr) {
361 onFailure(
"RegisteredPrefixHandle is empty");
Copyright (c) 2011-2015 Regents of the University of California.
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
The interface of signing key management.
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
void unregister(const UnregisterPrefixSuccessCallback &onSuccess=nullptr, const UnregisterPrefixFailureCallback &onFailure=nullptr)
Unregister the prefix.
implementation detail of Face
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
const Name & getPrefix() const
declares the set of Interests a producer can serve, which starts with a name prefix,...
#define IO_CAPTURE_WEAK_IMPL_END
#define NDN_LOG_DEBUG(expression)
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.
void unregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
Unregister prefix from RIB.
represents a Network Nack
void removeAllPendingInterests()
Cancel all previously expressed Interests.
FIELD::ValueType get(size_t index=0) const
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)
A handle of pending Interest.
size_t getNPendingInterests() const
Get number of pending Interests.
void shutdown()
Shutdown face operations.
Provide a communication channel with local or remote NDN forwarder.
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
void unsetInterestFilter(const RegisteredPrefixId *registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId.
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 incoming Interest matches the specified InterestFilter.
Options that control the behavior of GenericLinkService.
RegisteredPrefixHandle() noexcept
InterestFilterHandle() noexcept=default
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
static KeyChain & getKeyChain()
void put(Data data)
Publish data packet.
OversizedPacketError(char pktType, const Name &name, size_t wireSize)
Constructor.
std::string to_string(const V &v)
A handle of registered Interest filter.
PendingInterestHandle() noexcept=default
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.
Represents a Data packet.
RegisteredPrefixHandle 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...
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted)
A handle of registered prefix.
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.
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size