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 "../mgmt/nfd/controller.hpp" 41 #include "../mgmt/nfd/command-options.hpp" 43 #include "../lp/packet.hpp" 44 #include "../lp/tags.hpp" 62 , m_processEventsTimeoutEvent(m_scheduler)
64 auto postOnEmptyPitOrNoRegisteredPrefixes = [
this] {
72 m_pendingInterestTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
73 m_registeredPrefixTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
85 auto entry = m_pendingInterestTable.insert(make_shared<PendingInterest>(
86 interest, afterSatisfied, afterNacked, afterTimeout, ref(m_scheduler))).first;
87 (*entry)->setDeleter([
this, entry] { m_pendingInterestTable.erase(entry); });
92 if (nextHopFaceIdTag !=
nullptr) {
97 if (congestionMarkTag !=
nullptr) {
102 interest->wireEncode().end()));
104 m_face.m_transport->send(packet.
wireEncode());
110 m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId));
116 m_pendingInterestTable.clear();
122 for (
auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) {
123 if ((*entry)->getInterest()->matchesData(data)) {
124 shared_ptr<PendingInterest> matchedEntry = *entry;
125 entry = m_pendingInterestTable.erase(entry);
126 matchedEntry->invokeDataCallback(data);
137 for (
auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) {
138 const Interest& pendingInterest = *(*entry)->getInterest();
140 shared_ptr<PendingInterest> matchedEntry = *entry;
141 entry = m_pendingInterestTable.erase(entry);
142 matchedEntry->invokeNackCallback(nack);
154 m_interestFilterTable.push_back(interestFilterRecord);
161 m_interestFilterTable.end(),
162 MatchInterestFilterId(interestFilterId));
163 if (i != m_interestFilterTable.end()) {
164 m_interestFilterTable.erase(i);
171 for (
const auto& filter : m_interestFilterTable) {
172 if (filter->doesMatch(interest.getName())) {
173 filter->invokeInterestCallback(interest);
182 m_face.m_transport->send(wire);
186 const RegisteredPrefixId*
188 shared_ptr<InterestFilterRecord> filter,
192 const nfd::CommandOptions& options)
198 auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options);
200 m_face.m_nfdController->start<nfd::RibRegisterCommand>(
203 [=] (
const nfd::ControlResponse& resp) { onFailure(prefixToRegister->getPrefix(), resp.getText()); },
206 return reinterpret_cast<const RegisteredPrefixId*
>(prefixToRegister.get());
213 m_registeredPrefixTable.insert(registeredPrefix);
215 if (registeredPrefix->getFilter() !=
nullptr) {
217 m_interestFilterTable.push_back(registeredPrefix->getFilter());
220 if (onSuccess !=
nullptr) {
221 onSuccess(registeredPrefix->getPrefix());
230 auto i = std::find_if(m_registeredPrefixTable.begin(),
231 m_registeredPrefixTable.end(),
232 MatchRegisteredPrefixId(registeredPrefixId));
233 if (i != m_registeredPrefixTable.end()) {
234 RegisteredPrefix& record = **i;
235 const shared_ptr<InterestFilterRecord>& filter = record.getFilter();
237 if (filter !=
nullptr) {
239 m_interestFilterTable.remove(filter);
243 params.
setName(record.getPrefix());
244 m_face.m_nfdController->start<nfd::RibUnregisterCommand>(
248 record.getCommandOptions());
251 if (onFailure !=
nullptr) {
252 onFailure(
"Unrecognized PrefixId");
263 m_registeredPrefixTable.erase(item);
265 if (onSuccess !=
nullptr) {
274 if (!m_face.m_transport->isConnected())
275 m_face.m_transport->connect(m_face.getIoService(),
276 [=] (
const Block& wire) { m_face.onReceiveElement(wire); });
278 if (wantResume && !m_face.m_transport->isReceiving()) {
279 m_face.m_transport->resume();
286 if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) {
287 m_face.m_transport->pause();
293 util::Scheduler m_scheduler;
294 util::scheduler::ScopedEventId m_processEventsTimeoutEvent;
296 PendingInterestTable m_pendingInterestTable;
297 InterestFilterTable m_interestFilterTable;
298 RegisteredPrefixTable m_registeredPrefixTable;
305 #endif // NDN_DETAIL_FACE_IMPL_HPP Copyright (c) 2011-2015 Regents of the University of California.
ContainerWithOnEmptySignal< shared_ptr< RegisteredPrefix > > RegisteredPrefixTable
void ensureConnected(bool wantResume)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
append packet to encoder
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
void nackPendingInterests(const lp::Nack &nack)
void asyncSend(const Block &wire)
ControlParameters & setFlags(uint64_t flags)
void asyncUnsetInterestFilter(const InterestFilterId *interestFilterId)
void asyncSetInterestFilter(shared_ptr< InterestFilterRecord > interestFilterRecord)
void asyncUnregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
represents a Network Nack
provides a tag type for simple types
Table::const_iterator iterator
void satisfyPendingInterests(const Data &data)
std::list< shared_ptr< InterestFilterRecord > > InterestFilterTable
void finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, const UnregisterPrefixSuccessCallback &onSuccess)
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)
void processInterestFilters(Interest &interest)
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.
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
ControlParameters & setName(const Name &name)
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
void asyncRemovePendingInterest(const PendingInterestId *pendingInterestId)
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
ContainerWithOnEmptySignal< shared_ptr< PendingInterest > > PendingInterestTable
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
void onEmptyPitOrNoRegisteredPrefixes()
void afterPrefixRegistered(shared_ptr< RegisteredPrefix > registeredPrefix, const RegisterPrefixSuccessCallback &onSuccess)