22 #ifndef NDN_DETAIL_FACE_IMPL_HPP 23 #define NDN_DETAIL_FACE_IMPL_HPP 25 #include "../face.hpp" 30 #include "../lp/packet.hpp" 31 #include "../lp/tags.hpp" 32 #include "../mgmt/nfd/command-options.hpp" 33 #include "../mgmt/nfd/controller.hpp" 34 #include "../transport/transport.hpp" 37 #include "../util/config-file.hpp" 38 #include "../util/logger.hpp" 39 #include "../util/scheduler.hpp" 40 #include "../util/signal.hpp" 71 , m_processEventsTimeoutEvent(m_scheduler)
73 auto postOnEmptyPitOrNoRegisteredPrefixes = [
this] {
81 m_pendingInterestTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
82 m_registeredPrefixTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
95 const Interest& interest2 = *interest;
96 auto i = m_pendingInterestTable.insert(make_shared<PendingInterest>(
97 std::move(interest), afterSatisfied, afterNacked, afterTimeout, ref(m_scheduler))).first;
101 shared_ptr<PendingInterest> entry = *i;
102 entry->setDeleter([
this, i] { m_pendingInterestTable.erase(i); });
105 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest2);
106 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest2);
108 entry->recordForwarding();
109 m_face.m_transport->send(finishEncoding(std::move(lpPacket), interest2.wireEncode(),
110 'I', interest2.getName()));
117 m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId));
123 m_pendingInterestTable.clear();
131 bool hasAppMatch =
false, hasForwarderMatch =
false;
132 for (
auto i = m_pendingInterestTable.begin(); i != m_pendingInterestTable.end(); ) {
133 shared_ptr<PendingInterest> entry = *i;
134 if (!entry->getInterest()->matchesData(data)) {
139 NDN_LOG_DEBUG(
" satisfying " << *entry->getInterest() <<
" from " << entry->getOrigin());
140 i = m_pendingInterestTable.erase(i);
144 entry->invokeDataCallback(data);
147 hasForwarderMatch =
true;
151 return hasForwarderMatch || !hasAppMatch;
159 optional<lp::Nack> outNack;
160 for (
auto i = m_pendingInterestTable.begin(); i != m_pendingInterestTable.end(); ) {
161 shared_ptr<PendingInterest> entry = *i;
167 NDN_LOG_DEBUG(
" nacking " << *entry->getInterest() <<
" from " << entry->getOrigin());
169 optional<lp::Nack> outNack1 = entry->recordNack(nack);
176 entry->invokeNackCallback(*outNack1);
181 i = m_pendingInterestTable.erase(i);
193 NDN_LOG_INFO(
"setting InterestFilter: " << interestFilterRecord->getFilter());
194 m_interestFilterTable.push_back(std::move(interestFilterRecord));
201 m_interestFilterTable.end(),
202 MatchInterestFilterId(interestFilterId));
203 if (i != m_interestFilterTable.end()) {
204 NDN_LOG_INFO(
"unsetting InterestFilter: " << (*i)->getFilter());
205 m_interestFilterTable.erase(i);
212 const Interest& interest2 = *interest;
213 auto i = m_pendingInterestTable.insert(make_shared<PendingInterest>(
214 std::move(interest), ref(m_scheduler))).first;
218 shared_ptr<PendingInterest> entry = *i;
219 entry->setDeleter([
this, i] { m_pendingInterestTable.erase(i); });
227 for (
const auto& filter : m_interestFilterTable) {
228 if (filter->doesMatch(entry)) {
230 entry.recordForwarding();
231 filter->invokeInterestCallback(interest);
241 if (!shouldSendToForwarder) {
248 addFieldFromTag<lp::CachePolicyField, lp::CachePolicyTag>(lpPacket, data);
249 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
251 m_face.m_transport->send(finishEncoding(std::move(lpPacket), data.wireEncode(),
252 'D', data.getName()));
268 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, *outNack);
270 const Interest& interest = outNack->getInterest();
271 m_face.m_transport->send(finishEncoding(std::move(lpPacket), interest.wireEncode(),
272 'N', interest.getName()));
276 const RegisteredPrefixId*
278 shared_ptr<InterestFilterRecord> filter,
282 const nfd::CommandOptions& options)
285 auto record = make_shared<RegisteredPrefix>(prefix, filter, options);
290 m_face.m_nfdController->start<nfd::RibRegisterCommand>(
294 NDN_LOG_INFO(
"register prefix failed: " << record->getPrefix());
295 onFailure(record->getPrefix(), resp.getText());
299 return reinterpret_cast<const RegisteredPrefixId*
>(record.get());
306 NDN_LOG_INFO(
"registered prefix: " << registeredPrefix->getPrefix());
307 m_registeredPrefixTable.insert(registeredPrefix);
309 if (registeredPrefix->getFilter() !=
nullptr) {
311 m_interestFilterTable.push_back(registeredPrefix->getFilter());
314 if (onSuccess !=
nullptr) {
315 onSuccess(registeredPrefix->getPrefix());
324 auto i = std::find_if(m_registeredPrefixTable.begin(),
325 m_registeredPrefixTable.end(),
326 MatchRegisteredPrefixId(registeredPrefixId));
327 if (i != m_registeredPrefixTable.end()) {
328 RegisteredPrefix& record = **i;
329 const shared_ptr<InterestFilterRecord>& filter = record.getFilter();
331 if (filter !=
nullptr) {
333 m_interestFilterTable.remove(filter);
336 NDN_LOG_INFO(
"unregistering prefix: " << record.getPrefix());
339 params.
setName(record.getPrefix());
340 m_face.m_nfdController->start<nfd::RibUnregisterCommand>(
344 NDN_LOG_INFO(
"unregister prefix failed: " << params.getName());
345 onFailure(resp.getText());
347 record.getCommandOptions());
350 if (onFailure !=
nullptr) {
351 onFailure(
"Unrecognized PrefixId");
362 NDN_LOG_INFO(
"unregistered prefix: " << (*item)->getPrefix());
363 m_registeredPrefixTable.erase(item);
365 if (onSuccess !=
nullptr) {
374 if (!m_face.m_transport->isConnected())
375 m_face.m_transport->connect([=] (
const Block& wire) { m_face.onReceiveElement(wire); });
377 if (wantResume && !m_face.m_transport->isReceiving()) {
378 m_face.m_transport->resume();
385 if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) {
386 m_face.m_transport->pause();
402 if (!lpPacket.empty()) {
404 wire = lpPacket.wireEncode();
408 BOOST_THROW_EXCEPTION(Face::OversizedPacketError(pktType,
name, wire.size()));
416 util::Scheduler m_scheduler;
417 util::scheduler::ScopedEventId m_processEventsTimeoutEvent;
428 #endif // NDN_DETAIL_FACE_IMPL_HPP #define NDN_LOG_INFO(expression)
Copyright (c) 2011-2015 Regents of the University of California.
void ensureConnected(bool wantResume)
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
void asyncExpressInterest(shared_ptr< const Interest > interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
represents parameters in a ControlCommand request or response
implementation detail of Face
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
DummyIoService & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
bool matchesInterest(const Interest &other) const
Check if Interest matches other interest.
ControlParameters & setFlags(uint64_t flags)
void asyncUnsetInterestFilter(const InterestFilterId *interestFilterId)
const NackHeader & getHeader() const
void asyncSetInterestFilter(shared_ptr< InterestFilterRecord > interestFilterRecord)
void asyncUnregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
void asyncPutNack(const lp::Nack &nack)
represents a Network Nack
void asyncPutData(const Data &data)
Table::const_iterator iterator
#define NDN_LOG_INIT(name)
declare a log module
#define NDN_LOG_DEBUG(expression)
void finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, const UnregisterPrefixSuccessCallback &onSuccess)
Provide a communication channel with local or remote NDN forwarder.
void asyncRemoveAllPendingInterests()
const RegisteredPrefixId * registerPrefix(const Name &prefix, shared_ptr< InterestFilterRecord > filter, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, uint64_t flags, const nfd::CommandOptions &options)
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
void processIncomingInterest(shared_ptr< const Interest > interest)
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
bool satisfyPendingInterests(const Data &data)
std::list< shared_ptr< InterestFilterRecord > > InterestFilterTable
ControlParameters & setName(const Name &name)
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
void asyncRemovePendingInterest(const PendingInterestId *pendingInterestId)
Interest was received from this app via Face::expressInterest API.
ContainerWithOnEmptySignal< shared_ptr< PendingInterest > > PendingInterestTable
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.
ContainerWithOnEmptySignal< shared_ptr< RegisteredPrefix > > RegisteredPrefixTable
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
void dispatchInterest(PendingInterest &entry, const Interest &interest)
void onEmptyPitOrNoRegisteredPrefixes()
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
optional< lp::Nack > nackPendingInterests(const lp::Nack &nack)
void afterPrefixRegistered(shared_ptr< RegisteredPrefix > registeredPrefix, const RegisterPrefixSuccessCallback &onSuccess)