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();
154 impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout);
157 return reinterpret_cast<const PendingInterestId*
>(interest2.get());
164 impl->asyncRemovePendingInterest(pendingInterestId);
172 impl->asyncRemoveAllPendingInterests();
179 return m_impl->m_pendingInterestTable.size();
187 impl->asyncPutData(data);
196 impl->asyncPutNack(nack);
200 const RegisteredPrefixId*
207 return setInterestFilter(interestFilter, onInterest,
nullptr, onFailure, signingInfo, flags);
210 const RegisteredPrefixId*
218 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
223 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
224 onSuccess, onFailure, flags, options);
227 const InterestFilterId*
231 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
234 impl->asyncSetInterestFilter(filter);
237 return reinterpret_cast<const InterestFilterId*
>(filter.get());
240 const RegisteredPrefixId*
250 return m_impl->registerPrefix(prefix,
nullptr, onSuccess, onFailure, flags, options);
257 impl->asyncUnregisterPrefix(registeredPrefixId,
nullptr,
nullptr);
265 impl->asyncUnsetInterestFilter(interestFilterId);
275 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
288 this->asyncShutdown();
293 Face::asyncShutdown()
295 m_impl->m_pendingInterestTable.clear();
296 m_impl->m_registeredPrefixTable.clear();
298 if (m_transport->isConnected())
299 m_transport->close();
305 template<
typename NetPkt>
309 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
310 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
318 Face::onReceiveElement(
const Block& blockFromDaemon)
323 Buffer::const_iterator begin, end;
325 Block netPacket(&*begin, std::distance(begin, end));
326 switch (netPacket.type()) {
328 auto interest = make_shared<Interest>(netPacket);
330 auto nack = make_shared<lp::Nack>(std::move(*interest));
333 NDN_LOG_DEBUG(
">N " << nack->getInterest() <<
'~' << nack->getHeader().getReason());
334 m_impl->nackPendingInterests(*nack);
339 m_impl->processIncomingInterest(std::move(interest));
344 auto data = make_shared<Data>(netPacket);
347 m_impl->satisfyPendingInterests(*data);
Copyright (c) 2011-2015 Regents of the University of California.
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
const NackHeader & getHeader() const
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
boost::posix_time::time_duration milliseconds(long duration)
const Interest & getInterest() const
Represents a TLV element of 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.
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.
#define NDN_LOG_DEBUG(expression)
implements a forwarder-side transport that can be paired with another
FIELD::ValueType get(size_t index=0) const
contains options for ControlCommand execution
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.
const Name & getName() const
Get name.
#define IO_CAPTURE_WEAK_IMPL(OP)
size_t getNPendingInterests() const
Get number of pending Interests.
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