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-2021 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_CXX_IMPL_INTEREST_FILTER_RECORD_HPP
23 #define NDN_CXX_IMPL_INTEREST_FILTER_RECORD_HPP
24 
27 
28 namespace ndn {
29 
33 class InterestFilterRecord : public detail::RecordBase<InterestFilterRecord>
34 {
35 public:
42  InterestFilterRecord(const InterestFilter& filter, const InterestCallback& callback)
43  : m_filter(filter)
44  , m_interestCallback(callback)
45  {
46  }
47 
48  const InterestFilter&
49  getFilter() const
50  {
51  return m_filter;
52  }
53 
58  bool
59  doesMatch(const PendingInterest& entry) const
60  {
61  return (entry.getOrigin() == PendingInterestOrigin::FORWARDER || m_filter.allowsLoopback()) &&
62  m_filter.doesMatch(entry.getInterest()->getName());
63  }
64 
69  void
70  invokeInterestCallback(const Interest& interest) const
71  {
72  if (m_interestCallback != nullptr) {
73  m_interestCallback(m_filter, interest);
74  }
75  }
76 
77 private:
78  InterestFilter m_filter;
79  InterestCallback m_interestCallback;
80 };
81 
82 } // namespace ndn
83 
84 #endif // NDN_CXX_IMPL_INTEREST_FILTER_RECORD_HPP
void invokeInterestCallback(const Interest &interest) const
invokes the InterestCallback
Copyright (c) 2011-2015 Regents of the University of California.
InterestFilterRecord(const InterestFilter &filter, const InterestCallback &callback)
Construct an Interest filter record.
shared_ptr< const Interest > getInterest() const
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
const InterestFilter & getFilter() const
NDN_CXX_NODISCARD bool allowsLoopback() const
Get whether Interest loopback is allowed.
Associates an InterestFilter with an Interest callback.
bool doesMatch(const PendingInterest &entry) const
Check if Interest name matches the filter.
Represents an Interest packet.
Definition: interest.hpp:48
bool doesMatch(const Name &name) const
Check if specified Interest name matches the filter.
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when an incoming Interest matches the specified InterestFilter.
Definition: face.hpp:65
Interest was received from the forwarder via Transport.
PendingInterestOrigin getOrigin() const
Stores a pending Interest and associated callbacks.
Template of PendingInterest, RegisteredPrefix, and InterestFilterRecord.