blob: 9895bebcf8bdf5e57548273cbb7460fb43a4e801 [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -04002/*
3 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi35353962015-01-08 09:13:47 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shiee5a4442014-07-27 17:13:43 -070024 */
Junxiao Shidbe71732014-02-21 22:23:28 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
27#define NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
Junxiao Shidbe71732014-02-21 22:23:28 -070028
29#include "measurements.hpp"
Junxiao Shi7bb01512014-03-05 21:34:09 -070030#include "strategy-choice.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070031
32namespace nfd {
33
34namespace fw {
35class Strategy;
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000036} // namespace fw
37
38namespace measurements {
Junxiao Shidbe71732014-02-21 22:23:28 -070039
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040040/**
41 * \brief Allows fw::Strategy to access the portion of Measurements table under its namespace.
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000042 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040043 * All public methods have the same semantics as the corresponding methods on Measurements,
44 * but will return nullptr if the entry falls out of the strategy's authority.
Junxiao Shidbe71732014-02-21 22:23:28 -070045 */
46class MeasurementsAccessor : noncopyable
47{
48public:
Junxiao Shi35353962015-01-08 09:13:47 -070049 MeasurementsAccessor(Measurements& measurements, const StrategyChoice& strategyChoice,
50 const fw::Strategy& strategy);
Junxiao Shidbe71732014-02-21 22:23:28 -070051
52 ~MeasurementsAccessor();
53
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040054 /** \brief Find or insert a Measurements entry for \p name.
Junxiao Shie368d992014-12-02 23:44:31 -070055 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000056 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070057 get(const Name& name);
58
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040059 /** \brief Find or insert a Measurements entry for \p fibEntry->getPrefix().
Junxiao Shie368d992014-12-02 23:44:31 -070060 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000061 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070062 get(const fib::Entry& fibEntry);
63
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040064 /** \brief Find or insert a Measurements entry for \p pitEntry->getName().
Junxiao Shie368d992014-12-02 23:44:31 -070065 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000066 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070067 get(const pit::Entry& pitEntry);
68
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040069 /** \brief Find or insert a Measurements entry for child's parent.
Junxiao Shidbe71732014-02-21 22:23:28 -070070 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000071 Entry*
72 getParent(const Entry& child);
Junxiao Shidbe71732014-02-21 22:23:28 -070073
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040074 /** \brief Perform a longest prefix match for \p name.
Junxiao Shi35353962015-01-08 09:13:47 -070075 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000076 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070077 findLongestPrefixMatch(const Name& name,
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040078 const EntryPredicate& pred = AnyEntry()) const;
Junxiao Shi35353962015-01-08 09:13:47 -070079
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040080 /** \brief Perform a longest prefix match for \p pitEntry.getName().
Junxiao Shi35353962015-01-08 09:13:47 -070081 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000082 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070083 findLongestPrefixMatch(const pit::Entry& pitEntry,
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040084 const EntryPredicate& pred = AnyEntry()) const;
Junxiao Shi35353962015-01-08 09:13:47 -070085
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040086 /** \brief Perform an exact match.
Junxiao Shi35353962015-01-08 09:13:47 -070087 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000088 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070089 findExactMatch(const Name& name) const;
90
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040091 /** \brief Extend lifetime of an entry.
Junxiao Shidbe71732014-02-21 22:23:28 -070092 *
93 * The entry will be kept until at least now()+lifetime.
94 */
95 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000096 extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
Junxiao Shidbe71732014-02-21 22:23:28 -070097
98private:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040099 /** \brief Perform access control to Measurements entry.
Junxiao Shie368d992014-12-02 23:44:31 -0700100 * \return entry if strategy has access to namespace, otherwise nullptr
Junxiao Shidbe71732014-02-21 22:23:28 -0700101 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000102 Entry*
103 filter(Entry* entry) const;
104
105 Entry*
106 filter(Entry& entry) const;
Junxiao Shidbe71732014-02-21 22:23:28 -0700107
108private:
109 Measurements& m_measurements;
Junxiao Shi35353962015-01-08 09:13:47 -0700110 const StrategyChoice& m_strategyChoice;
111 const fw::Strategy* m_strategy;
Junxiao Shidbe71732014-02-21 22:23:28 -0700112};
113
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000114inline Entry*
115MeasurementsAccessor::filter(Entry& entry) const
116{
117 return this->filter(&entry);
118}
119
120inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700121MeasurementsAccessor::get(const Name& name)
122{
123 return this->filter(m_measurements.get(name));
124}
125
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000126inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700127MeasurementsAccessor::get(const fib::Entry& fibEntry)
128{
Junxiao Shi7bb01512014-03-05 21:34:09 -0700129 return this->filter(m_measurements.get(fibEntry));
Junxiao Shidbe71732014-02-21 22:23:28 -0700130}
131
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000132inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700133MeasurementsAccessor::get(const pit::Entry& pitEntry)
134{
135 return this->filter(m_measurements.get(pitEntry));
136}
137
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000138inline Entry*
139MeasurementsAccessor::getParent(const Entry& child)
Junxiao Shidbe71732014-02-21 22:23:28 -0700140{
141 return this->filter(m_measurements.getParent(child));
142}
143
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000144inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700145MeasurementsAccessor::findLongestPrefixMatch(const Name& name,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000146 const EntryPredicate& pred) const
Junxiao Shi35353962015-01-08 09:13:47 -0700147{
148 return this->filter(m_measurements.findLongestPrefixMatch(name, pred));
149}
150
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000151inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700152MeasurementsAccessor::findLongestPrefixMatch(const pit::Entry& pitEntry,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000153 const EntryPredicate& pred) const
Junxiao Shi35353962015-01-08 09:13:47 -0700154{
155 return this->filter(m_measurements.findLongestPrefixMatch(pitEntry, pred));
156}
157
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000158inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700159MeasurementsAccessor::findExactMatch(const Name& name) const
160{
161 return this->filter(m_measurements.findExactMatch(name));
162}
163
Junxiao Shidbe71732014-02-21 22:23:28 -0700164inline void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000165MeasurementsAccessor::extendLifetime(Entry& entry, const time::nanoseconds& lifetime)
Junxiao Shidbe71732014-02-21 22:23:28 -0700166{
167 m_measurements.extendLifetime(entry, lifetime);
168}
169
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000170} // namespace measurements
171
172using measurements::MeasurementsAccessor;
173
Junxiao Shidbe71732014-02-21 22:23:28 -0700174} // namespace nfd
175
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700176#endif // NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP