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