29 #include "ns3/node-list.h"
30 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
31 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp"
32 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp"
39 #define IO_CAPTURE_WEAK_IMPL(OP) \
41 weak_ptr<Impl> implWeak(m_impl); \
42 m_impl->m_scheduler.schedule(time::seconds(0), [=] { \
43 auto impl = implWeak.lock(); \
44 if (impl != nullptr) {
45 #define IO_CAPTURE_WEAK_IMPL_END \
53 :
Error((pktType ==
'I' ?
"Interest " : pktType ==
'D' ?
"Data " :
"Nack ") +
54 name.toUri() +
" encodes into " +
to_string(wireSize) +
" octets, "
74 construct(
std::move(transport), keyChain);
78 Face::makeDefaultTransport()
80 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
82 "NDN stack should be installed on the node " << node);
84 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
89 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
90 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
93 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
94 clientTransport->connectToForwarder(forwarderTransport);
98 return clientTransport;
102 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
104 BOOST_ASSERT(m_impl ==
nullptr);
105 m_impl = make_shared<Impl>(*
this, keyChain);
107 if (transport ==
nullptr) {
108 transport = makeDefaultTransport();
109 BOOST_ASSERT(transport !=
nullptr);
114 impl->ensureConnected(
false);
120 PendingInterestHandle
126 auto id = m_impl->m_pendingInterestTable.allocateId();
128 auto interest2 = make_shared<Interest>(interest);
129 interest2->getNonce();
132 impl->asyncExpressInterest(
id, interest2, afterSatisfied, afterNacked, afterTimeout);
139 Face::cancelPendingInterest(
const PendingInterestId* pendingInterestId)
142 impl->asyncRemovePendingInterest(
reinterpret_cast<RecordId>(pendingInterestId));
150 impl->asyncRemoveAllPendingInterests();
157 return m_impl->m_pendingInterestTable.size();
164 impl->asyncPutData(data);
172 impl->asyncPutNack(nack);
181 return setInterestFilter(filter, onInterest,
nullptr, onFailure, signingInfo, flags);
193 auto id = m_impl->registerPrefix(filter.
getPrefix(), onSuccess, onFailure, flags, options,
201 auto id = m_impl->m_interestFilterTable.allocateId();
204 impl->asyncSetInterestFilter(
id, filter, onInterest);
211 Face::clearInterestFilter(
const InterestFilterId* interestFilterId)
214 impl->asyncUnsetInterestFilter(
reinterpret_cast<RecordId>(interestFilterId));
218 RegisteredPrefixHandle
228 auto id = m_impl->registerPrefix(prefix, onSuccess, onFailure, flags, options,
nullopt,
nullptr);
233 Face::unregisterPrefixImpl(
const RegisteredPrefixId* registeredPrefixId,
238 impl->asyncUnregisterPrefix(
reinterpret_cast<RecordId>(registeredPrefixId),
239 onSuccess, onFailure);
253 if (m_transport->isConnected())
254 m_transport->close();
261 template<
typename NetPkt>
265 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
266 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
274 Face::onReceiveElement(
const Block& blockFromDaemon)
279 Buffer::const_iterator begin, end;
281 Block netPacket(&*begin, std::distance(begin, end));
282 switch (netPacket.type()) {
284 auto interest = make_shared<Interest>(netPacket);
286 auto nack = make_shared<lp::Nack>(
std::move(*interest));
289 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
290 m_impl->nackPendingInterests(*nack);
295 m_impl->processIncomingInterest(
std::move(interest));
300 auto data = make_shared<Data>(netPacket);
303 m_impl->satisfyPendingInterests(*data);
310 : CancelHandle([&face, id] { face.cancelPendingInterest(
id); })
315 : CancelHandle([&face, id] { face.unregisterPrefixImpl(
id,
nullptr,
nullptr); })
327 if (m_id ==
nullptr) {
328 if (onFailure !=
nullptr) {
329 onFailure(
"RegisteredPrefixHandle is empty");
334 m_face->unregisterPrefixImpl(m_id, onSuccess, onFailure);
340 : CancelHandle([&face, id] { face.clearInterestFilter(
id); })