22 #ifndef NDN_IMPL_FACE_IMPL_HPP 23 #define NDN_IMPL_FACE_IMPL_HPP 72 auto postOnEmptyPitOrNoRegisteredPrefixes = [
this] {
80 m_pendingInterestTable.
onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
81 m_registeredPrefixTable.
onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
94 const Interest& interest2 = *interest;
95 auto i = m_pendingInterestTable.
insert(make_shared<PendingInterest>(
96 std::move(interest), afterSatisfied, afterNacked, afterTimeout, ref(m_scheduler))).first;
100 shared_ptr<PendingInterest> entry = *i;
101 entry->setDeleter([
this, i] { m_pendingInterestTable.
erase(i); });
104 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest2);
105 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest2);
107 entry->recordForwarding();
108 m_face.m_transport->send(finishEncoding(std::move(lpPacket), interest2.
wireEncode(),
122 m_pendingInterestTable.
clear();
130 bool hasAppMatch =
false, hasForwarderMatch =
false;
131 for (
auto i = m_pendingInterestTable.
begin(); i != m_pendingInterestTable.
end(); ) {
132 shared_ptr<PendingInterest> entry = *i;
133 if (!entry->getInterest()->matchesData(data)) {
138 NDN_LOG_DEBUG(
" satisfying " << *entry->getInterest() <<
" from " << entry->getOrigin());
139 i = m_pendingInterestTable.
erase(i);
143 entry->invokeDataCallback(data);
146 hasForwarderMatch =
true;
150 return hasForwarderMatch || !hasAppMatch;
158 optional<lp::Nack> outNack;
159 for (
auto i = m_pendingInterestTable.
begin(); i != m_pendingInterestTable.
end(); ) {
160 shared_ptr<PendingInterest> entry = *i;
166 NDN_LOG_DEBUG(
" nacking " << *entry->getInterest() <<
" from " << entry->getOrigin());
168 optional<lp::Nack> outNack1 = entry->recordNack(nack);
175 entry->invokeNackCallback(*outNack1);
180 i = m_pendingInterestTable.
erase(i);
192 NDN_LOG_INFO(
"setting InterestFilter: " << interestFilterRecord->getFilter());
193 m_interestFilterTable.push_back(std::move(interestFilterRecord));
200 m_interestFilterTable.end(),
202 if (i != m_interestFilterTable.end()) {
203 NDN_LOG_INFO(
"unsetting InterestFilter: " << (*i)->getFilter());
204 m_interestFilterTable.erase(i);
211 const Interest& interest2 = *interest;
212 auto i = m_pendingInterestTable.
insert(make_shared<PendingInterest>(
213 std::move(interest), ref(m_scheduler))).first;
217 shared_ptr<PendingInterest> entry = *i;
218 entry->setDeleter([
this, i] { m_pendingInterestTable.
erase(i); });
226 for (
const auto& filter : m_interestFilterTable) {
227 if (filter->doesMatch(entry)) {
230 filter->invokeInterestCallback(interest);
240 if (!shouldSendToForwarder) {
247 addFieldFromTag<lp::CachePolicyField, lp::CachePolicyTag>(lpPacket, data);
248 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
250 m_face.m_transport->send(finishEncoding(std::move(lpPacket), data.
wireEncode(),
267 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, *outNack);
269 const Interest& interest = outNack->getInterest();
270 m_face.m_transport->send(finishEncoding(std::move(lpPacket), interest.
wireEncode(),
275 const RegisteredPrefixId*
277 shared_ptr<InterestFilterRecord> filter,
284 auto record = make_shared<RegisteredPrefix>(prefix, filter, options);
293 NDN_LOG_INFO(
"register prefix failed: " << record->getPrefix());
294 onFailure(record->getPrefix(), resp.getText());
298 return reinterpret_cast<const RegisteredPrefixId*>(record.get());
305 NDN_LOG_INFO(
"registered prefix: " << registeredPrefix->getPrefix());
306 m_registeredPrefixTable.
insert(registeredPrefix);
308 if (registeredPrefix->getFilter() !=
nullptr) {
310 m_interestFilterTable.push_back(registeredPrefix->getFilter());
313 if (onSuccess !=
nullptr) {
314 onSuccess(registeredPrefix->getPrefix());
323 auto i = std::find_if(m_registeredPrefixTable.
begin(),
324 m_registeredPrefixTable.
end(),
326 if (i != m_registeredPrefixTable.
end()) {
328 const shared_ptr<InterestFilterRecord>& filter = record.
getFilter();
330 if (filter !=
nullptr) {
332 m_interestFilterTable.remove(filter);
343 NDN_LOG_INFO(
"unregister prefix failed: " << params.getName());
344 onFailure(resp.getText());
349 if (onFailure !=
nullptr) {
350 onFailure(
"Unrecognized PrefixId");
361 NDN_LOG_INFO(
"unregistered prefix: " << (*item)->getPrefix());
362 m_registeredPrefixTable.
erase(item);
364 if (onSuccess !=
nullptr) {
373 if (!m_face.m_transport->isConnected())
374 m_face.m_transport->connect([=] (
const Block& wire) { m_face.onReceiveElement(wire); });
376 if (wantResume && !m_face.m_transport->isReceiving()) {
377 m_face.m_transport->resume();
384 if (m_pendingInterestTable.
empty() && m_registeredPrefixTable.
empty()) {
385 m_face.m_transport->pause();
401 if (!lpPacket.empty()) {
403 wire = lpPacket.wireEncode();
415 util::Scheduler m_scheduler;
416 util::scheduler::ScopedEventId m_processEventsTimeoutEvent;
427 #endif // NDN_IMPL_FACE_IMPL_HPP iterator erase(iterator item)
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getName() const
Get name.
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
void dispatchInterest(PendingInterest &entry, const Interest &interest)
const shared_ptr< InterestFilterRecord > & getFilter() const
ContainerWithOnEmptySignal< shared_ptr< RegisteredPrefix > > RegisteredPrefixTable
represents parameters in a ControlCommand request or response
implementation detail of Face
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
void asyncPutNack(const lp::Nack &nack)
void asyncExpressInterest(shared_ptr< const Interest > interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
DummyIoService & getIoService()
#define NDN_LOG_DEBUG(expression)
bool matchesInterest(const Interest &other) const
Check if Interest matches other interest.
ContainerWithOnEmptySignal< shared_ptr< PendingInterest > > PendingInterestTable
ControlParameters & setFlags(uint64_t flags)
Represents a TLV element of NDN packet format.
Represents an Interest packet.
Functor to match PendingInterestId.
const NackHeader & getHeader() const
void asyncRemovePendingInterest(const PendingInterestId *pendingInterestId)
void asyncPutData(const Data &data)
stores information about a prefix registered in NDN forwarder
void asyncRemoveAllPendingInterests()
EventId scheduleEvent(time::nanoseconds after, const EventCallback &callback)
Schedule a one-time event after the specified delay.
void processIncomingInterest(shared_ptr< const Interest > interest)
const nfd::CommandOptions & getCommandOptions() const
const Name & getPrefix() const
void asyncUnsetInterestFilter(const InterestFilterId *interestFilterId)
represents a Network Nack
Table::const_iterator iterator
void onEmptyPitOrNoRegisteredPrefixes()
void recordForwarding()
Record that the Interest has been forwarded to one destination.
size_t size() const
Get size of encoded wire, including Type-Length-Value.
void finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, const UnregisterPrefixSuccessCallback &onSuccess)
contains options for ControlCommand execution
std::pair< iterator, bool > insert(const value_type &value)
Provide a communication channel with local or remote NDN forwarder.
Functor to match InterestFilterId.
#define NDN_LOG_INFO(expression)
void ensureConnected(bool wantResume)
Buffer::const_iterator begin() const
Get begin iterator of encoded wire.
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
std::list< shared_ptr< InterestFilterRecord > > InterestFilterTable
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
util::Signal< ContainerWithOnEmptySignal< T > > onEmpty
Signal to be fired when container becomes empty.
Represents an absolute name.
Buffer::const_iterator end() const
Get end iterator of encoded wire.
represents a rib/unregister command
represents a rib/register command
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
bool satisfyPendingInterests(const Data &data)
void afterPrefixRegistered(shared_ptr< RegisteredPrefix > registeredPrefix, const RegisterPrefixSuccessCallback &onSuccess)
ControlParameters & setName(const Name &name)
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Prepend wire encoding to encoder in NDN Packet Format v0.2.
optional< lp::Nack > nackPendingInterests(const lp::Nack &nack)
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
#define NDN_LOG_INIT(name)
declare a log module
Functor to match RegisteredPrefixId.
Interest was received from this app via Face::expressInterest API.
void remove_if(Predicate p)
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.
Stores a pending Interest and associated callbacks.
void asyncUnregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
void asyncSetInterestFilter(shared_ptr< InterestFilterRecord > interestFilterRecord)
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
Exception thrown when attempting to send a packet over size limit.
const RegisteredPrefixId * registerPrefix(const Name &prefix, shared_ptr< InterestFilterRecord > filter, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, uint64_t flags, const nfd::CommandOptions &options)
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
const Name & getName() const