blob: 244897bde22ed28d03c8ac988758fb73081a022e [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi80f9fcd2016-07-23 02:48:36 +00003 * Copyright (c) 2014-2016, 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
40/** \brief allows Strategy to access portion of Measurements table under its namespace
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000041 *
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 Shidbe71732014-02-21 22:23:28 -070044 */
45class MeasurementsAccessor : noncopyable
46{
47public:
Junxiao Shi35353962015-01-08 09:13:47 -070048 MeasurementsAccessor(Measurements& measurements, const StrategyChoice& strategyChoice,
49 const fw::Strategy& strategy);
Junxiao Shidbe71732014-02-21 22:23:28 -070050
51 ~MeasurementsAccessor();
52
Junxiao Shi35353962015-01-08 09:13:47 -070053 /** \brief find or insert a Measurements entry for \p name
Junxiao Shie368d992014-12-02 23:44:31 -070054 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000055 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070056 get(const Name& name);
57
Junxiao Shi35353962015-01-08 09:13:47 -070058 /** \brief find or insert a Measurements entry for \p fibEntry->getPrefix()
Junxiao Shie368d992014-12-02 23:44:31 -070059 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000060 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070061 get(const fib::Entry& fibEntry);
62
Junxiao Shi35353962015-01-08 09:13:47 -070063 /** \brief find or insert a Measurements entry for \p pitEntry->getName()
Junxiao Shie368d992014-12-02 23:44:31 -070064 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000065 Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -070066 get(const pit::Entry& pitEntry);
67
68 /** \brief find or insert a Measurements entry for child's parent
Junxiao Shidbe71732014-02-21 22:23:28 -070069 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000070 Entry*
71 getParent(const Entry& child);
Junxiao Shidbe71732014-02-21 22:23:28 -070072
Junxiao Shi35353962015-01-08 09:13:47 -070073 /** \brief perform a longest prefix match for \p name
74 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000075 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070076 findLongestPrefixMatch(const Name& name,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000077 const EntryPredicate& pred =
78 AnyEntry()) const;
Junxiao Shi35353962015-01-08 09:13:47 -070079
80 /** \brief perform a longest prefix match for \p pitEntry.getName()
81 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000082 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070083 findLongestPrefixMatch(const pit::Entry& pitEntry,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000084 const EntryPredicate& pred =
85 AnyEntry()) const;
Junxiao Shi35353962015-01-08 09:13:47 -070086
87 /** \brief perform an exact match
88 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000089 Entry*
Junxiao Shi35353962015-01-08 09:13:47 -070090 findExactMatch(const Name& name) const;
91
Junxiao Shidbe71732014-02-21 22:23:28 -070092 /** \brief extend lifetime of an entry
93 *
94 * The entry will be kept until at least now()+lifetime.
95 */
96 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +000097 extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
Junxiao Shidbe71732014-02-21 22:23:28 -070098
99private:
100 /** \brief perform access control to Measurements entry
Junxiao Shie368d992014-12-02 23:44:31 -0700101 * \return entry if strategy has access to namespace, otherwise nullptr
Junxiao Shidbe71732014-02-21 22:23:28 -0700102 */
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000103 Entry*
104 filter(Entry* entry) const;
105
106 Entry*
107 filter(Entry& entry) const;
Junxiao Shidbe71732014-02-21 22:23:28 -0700108
109private:
110 Measurements& m_measurements;
Junxiao Shi35353962015-01-08 09:13:47 -0700111 const StrategyChoice& m_strategyChoice;
112 const fw::Strategy* m_strategy;
Junxiao Shidbe71732014-02-21 22:23:28 -0700113};
114
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000115inline Entry*
116MeasurementsAccessor::filter(Entry& entry) const
117{
118 return this->filter(&entry);
119}
120
121inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700122MeasurementsAccessor::get(const Name& name)
123{
124 return this->filter(m_measurements.get(name));
125}
126
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000127inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700128MeasurementsAccessor::get(const fib::Entry& fibEntry)
129{
Junxiao Shi7bb01512014-03-05 21:34:09 -0700130 return this->filter(m_measurements.get(fibEntry));
Junxiao Shidbe71732014-02-21 22:23:28 -0700131}
132
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000133inline Entry*
Junxiao Shidbe71732014-02-21 22:23:28 -0700134MeasurementsAccessor::get(const pit::Entry& pitEntry)
135{
136 return this->filter(m_measurements.get(pitEntry));
137}
138
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000139inline Entry*
140MeasurementsAccessor::getParent(const Entry& child)
Junxiao Shidbe71732014-02-21 22:23:28 -0700141{
142 return this->filter(m_measurements.getParent(child));
143}
144
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000145inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700146MeasurementsAccessor::findLongestPrefixMatch(const Name& name,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000147 const EntryPredicate& pred) const
Junxiao Shi35353962015-01-08 09:13:47 -0700148{
149 return this->filter(m_measurements.findLongestPrefixMatch(name, pred));
150}
151
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000152inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700153MeasurementsAccessor::findLongestPrefixMatch(const pit::Entry& pitEntry,
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000154 const EntryPredicate& pred) const
Junxiao Shi35353962015-01-08 09:13:47 -0700155{
156 return this->filter(m_measurements.findLongestPrefixMatch(pitEntry, pred));
157}
158
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000159inline Entry*
Junxiao Shi35353962015-01-08 09:13:47 -0700160MeasurementsAccessor::findExactMatch(const Name& name) const
161{
162 return this->filter(m_measurements.findExactMatch(name));
163}
164
Junxiao Shidbe71732014-02-21 22:23:28 -0700165inline void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000166MeasurementsAccessor::extendLifetime(Entry& entry, const time::nanoseconds& lifetime)
Junxiao Shidbe71732014-02-21 22:23:28 -0700167{
168 m_measurements.extendLifetime(entry, lifetime);
169}
170
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000171} // namespace measurements
172
173using measurements::MeasurementsAccessor;
174
Junxiao Shidbe71732014-02-21 22:23:28 -0700175} // namespace nfd
176
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700177#endif // NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP