NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2019, 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 
46 using EntryPredicate = std::function<bool(const Entry&)>;
47 
50 class AnyEntry
51 {
52 public:
53  bool
54  operator()(const Entry&) const
55  {
56  return true;
57  }
58 };
59 
62 template<typename T>
64 {
65 public:
66  bool
67  operator()(const Entry& entry) const
68  {
69  return entry.getStrategyInfo<T>() != nullptr;
70  }
71 };
72 
79 class Measurements : noncopyable
80 {
81 public:
82  explicit
83  Measurements(NameTree& nameTree);
84 
87  static constexpr size_t
89  {
90  return NameTree::getMaxDepth();
91  }
92 
98  Entry&
99  get(const Name& name);
100 
103  Entry&
104  get(const fib::Entry& fibEntry);
105 
108  Entry&
109  get(const pit::Entry& pitEntry);
110 
115  Entry*
116  getParent(const Entry& child);
117 
120  Entry*
121  findLongestPrefixMatch(const Name& name,
122  const EntryPredicate& pred = AnyEntry()) const;
123 
126  Entry*
127  findLongestPrefixMatch(const pit::Entry& pitEntry,
128  const EntryPredicate& pred = AnyEntry()) const;
129 
132  Entry*
133  findExactMatch(const Name& name) const;
134 
135  static time::nanoseconds
137  {
138  return 4_s;
139  }
140 
145  void
146  extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
147 
148  size_t
149  size() const
150  {
151  return m_nItems;
152  }
153 
154 private:
155  void
156  cleanup(Entry& entry);
157 
158  Entry&
159  get(name_tree::Entry& nte);
160 
163  template<typename K>
164  Entry*
165  findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;
166 
167 private:
168  NameTree& m_nameTree;
169  size_t m_nItems = 0;
170 };
171 
172 } // namespace measurements
173 
175 
176 } // namespace nfd
177 
178 #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
represents a FIB entry
Definition: fib-entry.hpp:53
bool operator()(const Entry &) const
static time::nanoseconds getInitialLifetime()
Represents a Measurements entry.
std::function< bool(const Entry &)> EntryPredicate
A predicate that accepts or rejects an entry.
bool operator()(const Entry &entry) const
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
An Interest table entry.
Definition: pit-entry.hpp:58
An EntryPredicate that accepts an entry if it has StrategyInfo of type T.
static constexpr size_t getMaxDepth()
maximum depth of a Measurements entry
The Measurements table.
An EntryPredicate that accepts any entry.
Represents an absolute name.
Definition: name.hpp:41
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:36
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
An entry in the name tree.
T * getStrategyInfo() const
Get a StrategyInfo item.
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition: name-tree.hpp:51