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-2022, 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 
29 #include "measurements-entry.hpp"
30 #include "name-tree.hpp"
31 
32 namespace nfd {
33 
34 namespace fib {
35 class Entry;
36 } // namespace fib
37 
38 namespace pit {
39 class Entry;
40 } // namespace pit
41 
42 namespace measurements {
43 
47 using EntryPredicate = std::function<bool(const Entry&)>;
48 
52 class AnyEntry
53 {
54 public:
55  constexpr bool
56  operator()(const Entry&) const noexcept
57  {
58  return true;
59  }
60 };
61 
65 template<typename T>
67 {
68 public:
69  bool
70  operator()(const Entry& entry) const
71  {
72  return entry.getStrategyInfo<T>() != nullptr;
73  }
74 };
75 
83 class Measurements : noncopyable
84 {
85 public:
86  explicit
87  Measurements(NameTree& nameTree);
88 
91  static constexpr size_t
93  {
94  return NameTree::getMaxDepth();
95  }
96 
102  Entry&
103  get(const Name& name);
104 
107  Entry&
108  get(const fib::Entry& fibEntry);
109 
112  Entry&
113  get(const pit::Entry& pitEntry);
114 
119  Entry*
120  getParent(const Entry& child);
121 
124  Entry*
125  findLongestPrefixMatch(const Name& name,
126  const EntryPredicate& pred = AnyEntry()) const;
127 
130  Entry*
131  findLongestPrefixMatch(const pit::Entry& pitEntry,
132  const EntryPredicate& pred = AnyEntry()) const;
133 
136  Entry*
137  findExactMatch(const Name& name) const;
138 
139  static time::nanoseconds
141  {
142  return 4_s;
143  }
144 
149  void
150  extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
151 
152  size_t
153  size() const
154  {
155  return m_nItems;
156  }
157 
158 private:
159  void
160  cleanup(Entry& entry);
161 
162  Entry&
163  get(name_tree::Entry& nte);
164 
167  template<typename K>
168  Entry*
169  findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;
170 
171 private:
172  NameTree& m_nameTree;
173  size_t m_nItems = 0;
174 };
175 
176 } // namespace measurements
177 
178 using measurements::Measurements;
179 
180 } // namespace nfd
181 
182 #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
T * getStrategyInfo() const
Get a StrategyInfo item.
Represents an entry in the FIB.
Definition: fib-entry.hpp:54
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.
Measurements(NameTree &nameTree)
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).
Definition: pit-entry.hpp:62
std::function< bool(const Entry &)> EntryPredicate
A predicate that accepts or rejects an entry.
Definition: common.hpp:77