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);
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 = std::move(transport);
116 m_nfdController = make_unique<nfd::Controller>(*
this, keyChain);
119 impl->ensureConnected(
false);
125 shared_ptr<Transport>
131 const PendingInterestId*
137 shared_ptr<Interest> interest2 = make_shared<Interest>(interest);
138 interest2->getNonce();
141 impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout);
144 return reinterpret_cast<const PendingInterestId*
>(interest2.get());
151 impl->asyncRemovePendingInterest(pendingInterestId);
159 impl->asyncRemoveAllPendingInterests();
166 return m_impl->m_pendingInterestTable.size();
173 impl->asyncPutData(data);
181 impl->asyncPutNack(nack);
185 const RegisteredPrefixId*
192 return setInterestFilter(interestFilter, onInterest,
nullptr, onFailure, signingInfo, flags);
195 const RegisteredPrefixId*
203 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
208 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
209 onSuccess, onFailure, flags, options);
212 const InterestFilterId*
216 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
219 impl->asyncSetInterestFilter(filter);
222 return reinterpret_cast<const InterestFilterId*
>(filter.get());
225 const RegisteredPrefixId*
235 return m_impl->registerPrefix(prefix,
nullptr, onSuccess, onFailure, flags, options);
242 impl->asyncUnregisterPrefix(registeredPrefixId,
nullptr,
nullptr);
250 impl->asyncUnsetInterestFilter(interestFilterId);
260 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
273 this->asyncShutdown();
278 Face::asyncShutdown()
280 m_impl->m_pendingInterestTable.clear();
281 m_impl->m_registeredPrefixTable.clear();
283 if (m_transport->isConnected())
284 m_transport->close();
290 template<
typename NetPkt>
294 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
295 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
303 Face::onReceiveElement(
const Block& blockFromDaemon)
308 Buffer::const_iterator begin, end;
310 Block netPacket(&*begin, std::distance(begin, end));
311 switch (netPacket.type()) {
313 auto interest = make_shared<Interest>(netPacket);
315 auto nack = make_shared<lp::Nack>(std::move(*interest));
318 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
319 m_impl->nackPendingInterests(*nack);
324 m_impl->processIncomingInterest(std::move(interest));
329 auto data = make_shared<Data>(netPacket);
332 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.
Face(DummyIoService &ioService)
Create Face using default transport and given io_service.
#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.
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