32 #include "ns3/node-list.h" 33 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp" 34 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 35 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" 40 : m_impl(new Impl(*this))
46 : m_impl(new Impl(*this))
52 : m_impl(new Impl(*this))
58 boost::asio::io_service& ioService)
59 : m_impl(new Impl(*this))
65 boost::asio::io_service& ioService,
67 : m_impl(new Impl(*this))
69 construct(transport, keyChain);
73 Face::makeDefaultTransport()
75 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
77 "NDN stack should be installed on the node " << node);
79 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
84 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
85 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
88 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
89 clientTransport->connectToForwarder(forwarderTransport);
93 return clientTransport;
97 Face::construct(shared_ptr<Transport> transport,
KeyChain& keyChain)
99 if (transport ==
nullptr) {
100 transport = makeDefaultTransport();
102 BOOST_ASSERT(transport !=
nullptr);
103 m_transport = transport;
110 shared_ptr<Transport>
116 const PendingInterestId*
122 shared_ptr<Interest> interestToExpress = make_shared<Interest>(interest);
126 BOOST_THROW_EXCEPTION(
Error(
"Interest size exceeds maximum limit"));
130 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] {
131 m_impl->asyncExpressInterest(interestToExpress, afterSatisfied,
132 afterNacked, afterTimeout);
135 return reinterpret_cast<const PendingInterestId*
>(interestToExpress.get());
138 const PendingInterestId*
146 if (onData !=
nullptr) {
147 onData(interest, const_cast<Data&>(data));
151 if (onTimeout !=
nullptr) {
159 const PendingInterestId*
175 BOOST_THROW_EXCEPTION(
Error(
"Data size exceeds maximum limit"));
177 shared_ptr<const Data> dataPtr;
179 dataPtr = data.shared_from_this();
181 catch (
const bad_weak_ptr& e) {
182 std::cerr <<
"Face::put WARNING: the supplied Data should be created using make_shared<Data>()" 184 dataPtr = make_shared<Data>(data);
188 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncPutData(dataPtr); });
194 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncPutNack(make_shared<lp::Nack>(nack)); });
200 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncRemovePendingInterest(pendingInterestId); });
206 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncRemoveAllPendingInterests(); });
212 return m_impl->m_pendingInterestTable.size();
215 const RegisteredPrefixId*
230 const RegisteredPrefixId*
238 shared_ptr<InterestFilterRecord> filter =
239 make_shared<InterestFilterRecord>(interestFilter, onInterest);
244 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
245 onSuccess, onFailure,
249 const InterestFilterId*
253 shared_ptr<InterestFilterRecord> filter =
254 make_shared<InterestFilterRecord>(interestFilter, onInterest);
256 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] {
257 m_impl->asyncSetInterestFilter(filter);
260 return reinterpret_cast<const InterestFilterId*
>(filter.get());
263 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 265 const RegisteredPrefixId*
278 onSuccess, onFailure,
282 const RegisteredPrefixId*
294 onFailure, signingInfo, flags);
297 const RegisteredPrefixId*
302 const Name& identity,
308 onSuccess, onFailure,
312 const RegisteredPrefixId*
316 const Name& identity,
322 onFailure, signingInfo, flags);
325 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 327 const RegisteredPrefixId*
338 return m_impl->registerPrefix(prefix, shared_ptr<InterestFilterRecord>(),
339 onSuccess, onFailure,
343 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 344 const RegisteredPrefixId*
356 onFailure, signingInfo, flags);
359 const RegisteredPrefixId*
363 const Name& identity,
368 onFailure, signingInfo, flags);
370 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING 375 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncUnregisterPrefix(registeredPrefixId,
383 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncUnsetInterestFilter(interestFilterId); });
391 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { m_impl->asyncUnregisterPrefix(registeredPrefixId,onSuccess, onFailure); });
403 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [
this] { this->asyncShutdown(); });
407 Face::asyncShutdown()
409 m_impl->m_pendingInterestTable.clear();
410 m_impl->m_registeredPrefixTable.clear();
412 if (m_transport->isConnected())
413 m_transport->close();
419 template<
typename NETPKT>
429 Face::onReceiveElement(
const Block& blockFromDaemon)
434 Buffer::const_iterator begin, end;
436 Block netPacket(&*begin, std::distance(begin, end));
437 switch (netPacket.type()) {
439 shared_ptr<Interest> interest = make_shared<Interest>(netPacket);
441 auto nack = make_shared<lp::Nack>(std::move(*interest));
444 m_impl->nackPendingInterests(*nack);
448 m_impl->processInterestFilters(*interest);
453 shared_ptr<Data> data = make_shared<Data>(netPacket);
455 m_impl->satisfyPendingInterests(*data);
Copyright (c) 2011-2015 Regents of the University of California.
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback called when unregisterPrefix or unsetInterestFilter command fails.
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy ...
represents the underlying protocol and address used by a Face
const Name & getName() const
Get name of the Data packet.
The packet signing interface.
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
function< void(const Interest &)> OnTimeout
Callback called when expressed Interest times out.
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback called when incoming Interest matches the specified InterestFilter.
Signing parameters passed to KeyChain.
SigningInfo signingByCertificate(const Name &certName)
void unregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
Unregister prefix from RIB.
represents a Network Nack
Face()
Create a new Face using the default transport (UnixTransport)
void removeAllPendingInterests()
Cancel all previously expressed Interests.
FIELD::ValueType get(size_t index=0) const
implements a forwarder-side transport that can be paired with another
contains options for ControlCommand execution
const RegisteredPrefixId * setInterestFilter(const InterestFilter &interestFilter, const OnInterest &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...
size_t getNPendingInterests() const
Get number of pending Interests.
void shutdown()
Shutdown face operations.
SigningInfo signingByIdentity(const Name &identity)
NFD Management protocol - ControlCommand client.
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback called when registerPrefix or setInterestFilter command fails.
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback called when registerPrefix or setInterestFilter command succeeds.
Name abstraction to represent an absolute name.
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.
Options that control the behavior of GenericLinkService.
function< void(const Interest &, Data &)> OnData
Callback called when expressed Interest gets satisfied with Data packet.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
function< void()> UnregisterPrefixSuccessCallback
Callback called when unregisterPrefix or unsetInterestFilter command succeeds.
bool empty() const
Check if name is emtpy.
static KeyChain & getKeyChain()
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
void processEvents(const time::milliseconds &timeout=time::milliseconds::zero(), bool keepThread=false)
Process any data to receive or call timeout callbacks.
static void extractLpLocalFields(NETPKT &netPacket, const lp::Packet &lpPacket)
extract local fields from NDNLPv2 packet and tag onto a network layer packet
function< void(const Interest &)> TimeoutCallback
Callback called when expressed Interest times out.
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback called when Nack is sent in response to expressed Interest.
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 called when expressed Interest gets satisfied with a Data packet.
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.
void put(const Data &data)
Publish data packet.
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size