Loading...
Searching...
No Matches
measurements.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, 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.
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/>.
24 */
25
26#ifndef NFD_DAEMON_TABLE_MEASUREMENTS_HPP
27#define NFD_DAEMON_TABLE_MEASUREMENTS_HPP
28
30#include "name-tree.hpp"
31
32#include <functional>
33
34namespace nfd {
35
36namespace fib {
37class Entry;
38} // namespace fib
39
40namespace pit {
41class Entry;
42} // namespace pit
43
44namespace measurements {
45
49using EntryPredicate = std::function<bool(const Entry&)>;
50
55{
56public:
57 constexpr bool
58 operator()(const Entry&) const noexcept
59 {
60 return true;
61 }
62};
63
67template<typename T>
69{
70public:
71 bool
72 operator()(const Entry& entry) const
73 {
74 return entry.getStrategyInfo<T>() != nullptr;
75 }
76};
77
85class Measurements : noncopyable
86{
87public:
88 explicit
89 Measurements(NameTree& nameTree);
90
93 static constexpr size_t
95 {
96 return NameTree::getMaxDepth();
97 }
98
104 Entry&
105 get(const Name& name);
106
109 Entry&
110 get(const fib::Entry& fibEntry);
111
114 Entry&
115 get(const pit::Entry& pitEntry);
116
121 Entry*
122 getParent(const Entry& child);
123
126 Entry*
127 findLongestPrefixMatch(const Name& name,
128 const EntryPredicate& pred = AnyEntry()) const;
129
132 Entry*
133 findLongestPrefixMatch(const pit::Entry& pitEntry,
134 const EntryPredicate& pred = AnyEntry()) const;
135
138 Entry*
139 findExactMatch(const Name& name) const;
140
141 static time::nanoseconds
143 {
144 return 4_s;
145 }
146
151 void
152 extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
153
154 size_t
155 size() const
156 {
157 return m_nItems;
158 }
159
160private:
161 void
162 cleanup(Entry& entry);
163
164 Entry&
165 get(name_tree::Entry& nte);
166
169 template<typename K>
170 Entry*
171 findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;
172
173private:
174 NameTree& m_nameTree;
175 size_t m_nItems = 0;
176};
177
178} // namespace measurements
179
180using measurements::Measurements;
181
182} // namespace nfd
183
184#endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
T * getStrategyInfo() const
Get a StrategyInfo item.
Represents an entry in the FIB.
Definition fib-entry.hpp:91
An EntryPredicate that accepts any entry.
constexpr bool operator()(const Entry &) const noexcept
Represents an entry in the Measurements table.
An EntryPredicate that accepts an entry if it has StrategyInfo of type T.
bool operator()(const Entry &entry) const
The Measurements table.
static constexpr size_t getMaxDepth()
Maximum depth of a Measurements entry.
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
Extend lifetime of an entry.
Entry * getParent(const Entry &child)
Find or insert a parent entry.
Entry & get(const Name &name)
Find or insert an entry by name.
Entry * findExactMatch(const Name &name) const
Perform an exact match.
static time::nanoseconds getInitialLifetime()
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
Perform a longest prefix match for name.
An entry in the name tree.
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition name-tree.hpp:37
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition name-tree.hpp:51
Represents an entry in the Interest table (PIT).
std::function< bool(const Entry &)> EntryPredicate
A predicate that accepts or rejects an entry.
-status-http-server
Definition common.hpp:71