22 #ifndef NDN_DETAIL_FACE_IMPL_HPP 23 #define NDN_DETAIL_FACE_IMPL_HPP 25 #include "../common.hpp" 26 #include "../face.hpp" 32 #include "../util/scheduler.hpp" 33 #include "../util/config-file.hpp" 34 #include "../util/signal.hpp" 36 #include "../transport/transport.hpp" 37 #include "../transport/unix-transport.hpp" 38 #include "../transport/tcp-transport.hpp" 40 #include "../management/nfd-controller.hpp" 41 #include "../management/nfd-command-options.hpp" 45 #include <ns3/node-list.h> 46 #include <ns3/ndnSIM/model/ndn-l3-protocol.hpp> 48 #include "ns3/ndnSIM/NFD/daemon/face/local-face.hpp" 62 NfdFace(
Impl& face, const ::nfd::FaceUri& localUri, const ::nfd::FaceUri& remoteUri)
75 NS_LOG_DEBUG(
"<< Interest " << interest);
76 shared_ptr<const Interest> interestPtr = interest.shared_from_this();
77 m_appFaceImpl.m_scheduler.scheduleEvent(time::seconds(0), [
this, interestPtr] {
88 NS_LOG_DEBUG(
"<< Data " << data.
getName());
89 shared_ptr<const Data> dataPtr = data.shared_from_this();
90 m_appFaceImpl.m_scheduler.scheduleEvent(time::seconds(0), [
this, dataPtr] {
118 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
120 "NDN stack should be installed on the node " << node);
122 auto uri =
::nfd::FaceUri(
"ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
123 m_nfdFace = make_shared<NfdFace>(*
this, uri, uri);
134 for (
auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) {
135 if ((*entry)->getInterest().matchesData(data)) {
136 shared_ptr<PendingInterest> matchedEntry = *entry;
138 entry = m_pendingInterestTable.erase(entry);
140 matchedEntry->invokeDataCallback(data);
150 for (
const auto& filter : m_interestFilterTable) {
151 if (filter->doesMatch(interest.
getName())) {
152 filter->invokeInterestCallback(interest);
165 m_pendingInterestTable.insert(make_shared<PendingInterest>(interest,
167 ref(m_scheduler))).first;
168 (*entry)->setDeleter([
this, entry] { m_pendingInterestTable.erase(entry); });
176 m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId));
191 m_interestFilterTable.push_back(interestFilterRecord);
198 m_interestFilterTable.end(),
199 MatchInterestFilterId(interestFilterId));
200 if (i != m_interestFilterTable.end())
202 m_interestFilterTable.erase(i);
209 const RegisteredPrefixId*
211 const shared_ptr<InterestFilterRecord>& filter,
215 const nfd::CommandOptions& options)
223 auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options);
225 m_face.m_nfdController->start<RibRegisterCommand>(params,
227 prefixToRegister, onSuccess),
228 bind(onFailure, prefixToRegister->getPrefix(), _2),
231 return reinterpret_cast<const RegisteredPrefixId*
>(prefixToRegister.get());
238 m_registeredPrefixTable.insert(registeredPrefix);
240 if (static_cast<bool>(registeredPrefix->getFilter())) {
242 m_interestFilterTable.push_back(registeredPrefix->getFilter());
245 if (static_cast<bool>(onSuccess)) {
246 onSuccess(registeredPrefix->getPrefix());
256 auto i = std::find_if(m_registeredPrefixTable.begin(),
257 m_registeredPrefixTable.end(),
258 MatchRegisteredPrefixId(registeredPrefixId));
259 if (i != m_registeredPrefixTable.end()) {
260 RegisteredPrefix& record = **i;
262 const shared_ptr<InterestFilterRecord>& filter = record.getFilter();
264 if (filter !=
nullptr) {
266 m_interestFilterTable.remove(filter);
270 params.
setName(record.getPrefix());
271 m_face.m_nfdController->start<RibUnregisterCommand>(params,
274 record.getCommandOptions());
277 if (onFailure !=
nullptr) {
278 onFailure(
"Unrecognized PrefixId");
289 m_registeredPrefixTable.erase(item);
291 if (static_cast<bool>(onSuccess)) {
298 util::Scheduler m_scheduler;
300 PendingInterestTable m_pendingInterestTable;
301 InterestFilterTable m_interestFilterTable;
302 RegisteredPrefixTable m_registeredPrefixTable;
304 shared_ptr<NfdFace> m_nfdFace;
311 #endif // NDN_DETAIL_FACE_IMPL_HPP NfdFace(Impl &face, const ::nfd::FaceUri &localUri, const ::nfd::FaceUri &remoteUri)
const Name & getName() const
Copyright (c) 2011-2015 Regents of the University of California.
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback called when unregisterPrefix or unsetInterestFilter command fails.
represents parameters in a ControlCommand request or response
represents the underlying protocol and address used by a Face
virtual void sendData(const Data &data)
Send Data towards application.
ControlParameters & setFlags(uint64_t flags)
signal::Signal< Face, Data > onReceiveData
fires when a Data is received
represents an Interest packet
function< void(const Interest &)> OnTimeout
Callback called when expressed Interest times out.
void asyncExpressInterest(const shared_ptr< const Interest > &interest, const OnData &onData, const OnTimeout &onTimeout)
void asyncUnsetInterestFilter(const InterestFilterId *interestFilterId)
void asyncUnregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
const Name & getName() const
Get name of the Data packet.
Table::const_iterator iterator
void fail(const std::string &reason)
fail the face and raise onFail event if it's UP; otherwise do nothing
Copyright (c) 2011-2015 Regents of the University of California.
virtual void close()
Close the face.
void asyncPutData(const shared_ptr< const Data > &data)
void processInterestFilters(const Interest &interest)
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.
boost::asio::io_service & getIoService()
Return nullptr (kept for compatibility)
Implementation network-layer of NDN stack.
void asyncSetInterestFilter(const shared_ptr< InterestFilterRecord > &interestFilterRecord)
const RegisteredPrefixId * registerPrefix(const Name &prefix, const shared_ptr< InterestFilterRecord > &filter, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, uint64_t flags, const nfd::CommandOptions &options)
virtual void sendInterest(const Interest &interest)
Send Interest towards application.
ContainerWithOnEmptySignal< shared_ptr< RegisteredPrefix > > RegisteredPrefixTable
function< void(const Interest &, Data &)> OnData
Callback called when expressed Interest gets satisfied with Data packet.
std::list< shared_ptr< InterestFilterRecord > > InterestFilterTable
ControlParameters & setName(const Name &name)
void satisfyPendingInterests(const Data &data)
function< void()> UnregisterPrefixSuccessCallback
Callback called when unregisterPrefix or unsetInterestFilter command succeeds.
void afterPrefixRegistered(const shared_ptr< RegisteredPrefix > ®isteredPrefix, const RegisterPrefixSuccessCallback &onSuccess)
void asyncRemovePendingInterest(const PendingInterestId *pendingInterestId)
signal::Signal< Face, Interest > onReceiveInterest
fires when an Interest is received
ContainerWithOnEmptySignal< shared_ptr< PendingInterest > > PendingInterestTable
void finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, const UnregisterPrefixSuccessCallback &onSuccess)