Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 4 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |
| 27 | #define NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 28 | |
| 29 | #include "measurements.hpp" |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 30 | #include "strategy-choice.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | namespace fw { |
| 35 | class Strategy; |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 36 | } // namespace fw |
| 37 | |
| 38 | namespace measurements { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 39 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 40 | /** |
| 41 | * \brief Allows fw::Strategy to access the portion of Measurements table under its namespace. |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 42 | * |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 43 | * 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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 45 | */ |
| 46 | class MeasurementsAccessor : noncopyable |
| 47 | { |
| 48 | public: |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 49 | MeasurementsAccessor(Measurements& measurements, const StrategyChoice& strategyChoice, |
| 50 | const fw::Strategy& strategy); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 51 | |
| 52 | ~MeasurementsAccessor(); |
| 53 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 54 | /** \brief Find or insert a Measurements entry for \p name. |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 55 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 56 | Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 57 | get(const Name& name); |
| 58 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 59 | /** \brief Find or insert a Measurements entry for \p fibEntry->getPrefix(). |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 60 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 61 | Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 62 | get(const fib::Entry& fibEntry); |
| 63 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 64 | /** \brief Find or insert a Measurements entry for \p pitEntry->getName(). |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 65 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 66 | Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 67 | get(const pit::Entry& pitEntry); |
| 68 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 69 | /** \brief Find or insert a Measurements entry for child's parent. |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 70 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 71 | Entry* |
| 72 | getParent(const Entry& child); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 73 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 74 | /** \brief Perform a longest prefix match for \p name. |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 75 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 76 | Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 77 | findLongestPrefixMatch(const Name& name, |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 78 | const EntryPredicate& pred = AnyEntry()) const; |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 79 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 80 | /** \brief Perform a longest prefix match for \p pitEntry.getName(). |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 81 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 82 | Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 83 | findLongestPrefixMatch(const pit::Entry& pitEntry, |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 84 | const EntryPredicate& pred = AnyEntry()) const; |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 85 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 86 | /** \brief Perform an exact match. |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 87 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 88 | Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 89 | findExactMatch(const Name& name) const; |
| 90 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 91 | /** \brief Extend lifetime of an entry. |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 92 | * |
| 93 | * The entry will be kept until at least now()+lifetime. |
| 94 | */ |
| 95 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 96 | extendLifetime(Entry& entry, const time::nanoseconds& lifetime); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 97 | |
| 98 | private: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame^] | 99 | /** \brief Perform access control to Measurements entry. |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 100 | * \return entry if strategy has access to namespace, otherwise nullptr |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 101 | */ |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 102 | Entry* |
| 103 | filter(Entry* entry) const; |
| 104 | |
| 105 | Entry* |
| 106 | filter(Entry& entry) const; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 107 | |
| 108 | private: |
| 109 | Measurements& m_measurements; |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 110 | const StrategyChoice& m_strategyChoice; |
| 111 | const fw::Strategy* m_strategy; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 114 | inline Entry* |
| 115 | MeasurementsAccessor::filter(Entry& entry) const |
| 116 | { |
| 117 | return this->filter(&entry); |
| 118 | } |
| 119 | |
| 120 | inline Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 121 | MeasurementsAccessor::get(const Name& name) |
| 122 | { |
| 123 | return this->filter(m_measurements.get(name)); |
| 124 | } |
| 125 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 126 | inline Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 127 | MeasurementsAccessor::get(const fib::Entry& fibEntry) |
| 128 | { |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 129 | return this->filter(m_measurements.get(fibEntry)); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 132 | inline Entry* |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 133 | MeasurementsAccessor::get(const pit::Entry& pitEntry) |
| 134 | { |
| 135 | return this->filter(m_measurements.get(pitEntry)); |
| 136 | } |
| 137 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 138 | inline Entry* |
| 139 | MeasurementsAccessor::getParent(const Entry& child) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 140 | { |
| 141 | return this->filter(m_measurements.getParent(child)); |
| 142 | } |
| 143 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 144 | inline Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 145 | MeasurementsAccessor::findLongestPrefixMatch(const Name& name, |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 146 | const EntryPredicate& pred) const |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 147 | { |
| 148 | return this->filter(m_measurements.findLongestPrefixMatch(name, pred)); |
| 149 | } |
| 150 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 151 | inline Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 152 | MeasurementsAccessor::findLongestPrefixMatch(const pit::Entry& pitEntry, |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 153 | const EntryPredicate& pred) const |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 154 | { |
| 155 | return this->filter(m_measurements.findLongestPrefixMatch(pitEntry, pred)); |
| 156 | } |
| 157 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 158 | inline Entry* |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [diff] [blame] | 159 | MeasurementsAccessor::findExactMatch(const Name& name) const |
| 160 | { |
| 161 | return this->filter(m_measurements.findExactMatch(name)); |
| 162 | } |
| 163 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 164 | inline void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 165 | MeasurementsAccessor::extendLifetime(Entry& entry, const time::nanoseconds& lifetime) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 166 | { |
| 167 | m_measurements.extendLifetime(entry, lifetime); |
| 168 | } |
| 169 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 170 | } // namespace measurements |
| 171 | |
| 172 | using measurements::MeasurementsAccessor; |
| 173 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 174 | } // namespace nfd |
| 175 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 176 | #endif // NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |