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