NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
interest-filter-record.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_IMPL_INTEREST_FILTER_RECORD_HPP
23 #define NDN_IMPL_INTEREST_FILTER_RECORD_HPP
24 
26 
27 namespace ndn {
28 
32 class InterestFilterId;
33 
34 static_assert(sizeof(const InterestFilterId*) == sizeof(RecordId), "");
35 
39 class InterestFilterRecord : public RecordBase<InterestFilterRecord>
40 {
41 public:
49  const InterestCallback& interestCallback)
50  : m_filter(filter)
51  , m_interestCallback(interestCallback)
52  {
53  }
54 
55  const InterestFilter&
56  getFilter() const
57  {
58  return m_filter;
59  }
60 
65  bool
66  doesMatch(const PendingInterest& entry) const
67  {
68  return (entry.getOrigin() == PendingInterestOrigin::FORWARDER || m_filter.allowsLoopback()) &&
69  m_filter.doesMatch(entry.getInterest()->getName());
70  }
71 
76  void
77  invokeInterestCallback(const Interest& interest) const
78  {
79  if (m_interestCallback != nullptr) {
80  m_interestCallback(m_filter, interest);
81  }
82  }
83 
84 private:
85  InterestFilter m_filter;
86  InterestCallback m_interestCallback;
87 };
88 
89 } // namespace ndn
90 
91 #endif // NDN_IMPL_INTEREST_FILTER_RECORD_HPP
ndn::PendingInterestOrigin::FORWARDER
@ FORWARDER
Interest was received from the forwarder via Transport.
ndn::InterestFilterRecord::getFilter
const InterestFilter & getFilter() const
Definition: interest-filter-record.hpp:56
ndn::InterestFilterRecord
associates an InterestFilter with Interest callback
Definition: interest-filter-record.hpp:40
ndn::InterestFilterRecord::doesMatch
bool doesMatch(const PendingInterest &entry) const
Check if Interest name matches the filter.
Definition: interest-filter-record.hpp:66
ndn::RecordId
uintptr_t RecordId
Definition: record-container.hpp:32
ndn::InterestFilter::allowsLoopback
NDN_CXX_NODISCARD bool allowsLoopback() const
Get whether Interest loopback is allowed.
Definition: interest-filter.hpp:127
ndn::PendingInterest::getOrigin
PendingInterestOrigin getOrigin() const
Definition: pending-interest.hpp:105
ndn::InterestFilterRecord::InterestFilterRecord
InterestFilterRecord(const InterestFilter &filter, const InterestCallback &interestCallback)
Construct an Interest filter record.
Definition: interest-filter-record.hpp:48
ndn::InterestFilterRecord::invokeInterestCallback
void invokeInterestCallback(const Interest &interest) const
invokes the InterestCallback
Definition: interest-filter-record.hpp:77
ndn::PendingInterest
Stores a pending Interest and associated callbacks.
Definition: pending-interest.hpp:66
ndn::InterestFilter
declares the set of Interests a producer can serve, which starts with a name prefix,...
Definition: interest-filter.hpp:36
ndn::InterestCallback
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:64
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
ndn::InterestFilter::doesMatch
bool doesMatch(const Name &name) const
Check if specified Interest name matches the filter.
Definition: interest-filter.cpp:58
ndn::PendingInterest::getInterest
shared_ptr< const Interest > getInterest() const
Definition: pending-interest.hpp:99
ndn::RecordBase
Template of PendingInterest, RegisteredPrefix, and InterestFilterRecord.
Definition: record-container.hpp:42
pending-interest.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34