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-2018, 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 typedef std::function<bool(const Entry&)> EntryPredicate;
47 
50 class AnyEntry
51 {
52 public:
53  bool
54  operator()(const Entry& 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 
109  Entry&
110  get(const pit::Entry& pitEntry);
111 
116  Entry*
117  getParent(const Entry& child);
118 
121  Entry*
123  const EntryPredicate& pred = AnyEntry()) const;
124 
127  Entry*
128  findLongestPrefixMatch(const pit::Entry& pitEntry,
129  const EntryPredicate& pred = AnyEntry()) const;
130 
133  Entry*
134  findExactMatch(const Name& name) const;
135 
136  static time::nanoseconds
138 
143  void
144  extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
145 
146  size_t
147  size() const;
148 
149 private:
150  void
151  cleanup(Entry& entry);
152 
153  Entry&
154  get(name_tree::Entry& nte);
155 
158  template<typename K>
159  Entry*
160  findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;
161 
162 private:
163  NameTree& m_nameTree;
164  size_t m_nItems;
165 };
166 
167 inline time::nanoseconds
169 {
170  return 4_s;
171 }
172 
173 inline size_t
175 {
176  return m_nItems;
177 }
178 
179 } // namespace measurements
180 
182 
183 } // namespace nfd
184 
185 #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
Entry * findExactMatch(const Name &name) const
perform an exact match
Measurements(NameTree &nameTree)
represents a FIB entry
Definition: fib-entry.hpp:51
std::function< bool(const Entry &)> EntryPredicate
a predicate that accepts or rejects an entry
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
perform a longest prefix match for name
represents a Measurements entry
Entry * getParent(const Entry &child)
find or insert a parent entry
bool operator()(const Entry &entry) const
bool operator()(const Entry &entry) const
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:59
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
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:43
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:38
Entry & get(const Name &name)
find or insert an entry by name
static time::nanoseconds getInitialLifetime()
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:53