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" 42 #define IO_CAPTURE_WEAK_IMPL(OP) \ 44 weak_ptr<Impl> implWeak(m_impl); \ 45 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \ 46 auto impl = implWeak.lock(); \ 47 if (impl != nullptr) { 48 #define IO_CAPTURE_WEAK_IMPL_END \ 56 :
Error((pktType ==
'I' ?
"Interest " : pktType ==
'D' ?
"Data " :
"Nack ") +
57 name.toUri() +
" encodes into " +
to_string(wireSize) +
" octets, " 66 : m_impl(new Impl(*this))
72 : m_impl(new Impl(*this))
78 : m_impl(new Impl(*this))
80 construct(std::move(transport), keyChain);
83 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
84 : m_impl(new Impl(*this))
89 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService,
KeyChain& keyChain)
90 : m_impl(new Impl(*this))
92 construct(std::move(transport), keyChain);
96 Face::makeDefaultTransport()
98 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
100 "NDN stack should be installed on the node " << node);
102 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
107 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
108 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
111 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
112 clientTransport->connectToForwarder(forwarderTransport);
116 return clientTransport;
120 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
122 if (transport ==
nullptr) {
123 transport = makeDefaultTransport();
125 BOOST_ASSERT(transport !=
nullptr);
126 m_transport = std::move(transport);
128 m_nfdController = make_unique<nfd::Controller>(*
this, keyChain);
131 impl->ensureConnected(
false);
137 shared_ptr<Transport>
143 const PendingInterestId*
149 shared_ptr<Interest> interest2 = make_shared<Interest>(interest);
150 interest2->getNonce();
153 impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout);
156 return reinterpret_cast<const PendingInterestId*
>(interest2.get());
163 impl->asyncRemovePendingInterest(pendingInterestId);
171 impl->asyncRemoveAllPendingInterests();
178 return m_impl->m_pendingInterestTable.size();
185 impl->asyncPutData(data);
193 impl->asyncPutNack(nack);
197 const RegisteredPrefixId*
204 return setInterestFilter(interestFilter, onInterest,
nullptr, onFailure, signingInfo, flags);
207 const RegisteredPrefixId*
215 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
220 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
221 onSuccess, onFailure, flags, options);
224 const InterestFilterId*
228 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
231 impl->asyncSetInterestFilter(filter);
234 return reinterpret_cast<const InterestFilterId*
>(filter.get());
237 const RegisteredPrefixId*
247 return m_impl->registerPrefix(prefix,
nullptr, onSuccess, onFailure, flags, options);
254 impl->asyncUnregisterPrefix(registeredPrefixId,
nullptr,
nullptr);
262 impl->asyncUnsetInterestFilter(interestFilterId);
272 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
285 this->asyncShutdown();
290 Face::asyncShutdown()
292 m_impl->m_pendingInterestTable.clear();
293 m_impl->m_registeredPrefixTable.clear();
295 if (m_transport->isConnected())
296 m_transport->close();
302 template<
typename NetPkt>
306 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
307 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
315 Face::onReceiveElement(
const Block& blockFromDaemon)
320 Buffer::const_iterator begin, end;
322 Block netPacket(&*begin, std::distance(begin, end));
323 switch (netPacket.type()) {
325 auto interest = make_shared<Interest>(netPacket);
327 auto nack = make_shared<lp::Nack>(std::move(*interest));
330 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
331 m_impl->nackPendingInterests(*nack);
336 m_impl->processIncomingInterest(std::move(interest));
341 auto data = make_shared<Data>(netPacket);
344 m_impl->satisfyPendingInterests(*data);
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.
#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...
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular 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
#define NDN_LOG_DEBUG(expression)
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.
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
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.
#define IO_CAPTURE_WEAK_IMPL(OP)
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)
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.
Represents a Data packet.
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)
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