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*
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 
174 using measurements::Measurements;
175 
176 } // namespace nfd
177 
178 #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
name-tree.hpp
nfd::name_tree::Entry
An entry in the name tree.
Definition: name-tree-entry.hpp:42
nfd::measurements::AnyEntry::operator()
bool operator()(const Entry &) const
Definition: measurements.hpp:54
nfd::measurements::Measurements::size
size_t size() const
Definition: measurements.hpp:149
nfd::name_tree::NameTree
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:37
nfd::measurements::Measurements::Measurements
Measurements(NameTree &nameTree)
Definition: measurements.cpp:35
measurements-entry.hpp
nfd::measurements::EntryWithStrategyInfo
An EntryPredicate that accepts an entry if it has StrategyInfo of type T.
Definition: measurements.hpp:64
nfd::measurements::Measurements::get
Entry & get(const Name &name)
Find or insert an entry by name.
Definition: measurements.cpp:59
nfd::measurements::Measurements::getMaxDepth
static constexpr size_t getMaxDepth()
maximum depth of a Measurements entry
Definition: measurements.hpp:88
nfd::measurements::EntryPredicate
std::function< bool(const Entry &)> EntryPredicate
A predicate that accepts or rejects an entry.
Definition: measurements.hpp:46
nfd::measurements::Measurements::findExactMatch
Entry * findExactMatch(const Name &name) const
Perform an exact match.
Definition: measurements.cpp:120
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::measurements::Measurements::extendLifetime
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
Extend lifetime of an entry.
Definition: measurements.cpp:127
nfd::measurements::Measurements
The Measurements table.
Definition: measurements.hpp:80
nfd::pit::Entry
An Interest table entry.
Definition: pit-entry.hpp:59
nfd::measurements::Measurements::findLongestPrefixMatch
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
Perform a longest prefix match for name.
Definition: measurements.cpp:108
nfd::fib::Entry
represents a FIB entry
Definition: fib-entry.hpp:54
nfd::measurements::EntryWithStrategyInfo::operator()
bool operator()(const Entry &entry) const
Definition: measurements.hpp:67
nfd::measurements::Measurements::getParent
Entry * getParent(const Entry &child)
Find or insert a parent entry.
Definition: measurements.cpp:80
nfd::name_tree::NameTree::getMaxDepth
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition: name-tree.hpp:51
nfd::measurements::Entry
Represents a Measurements entry.
Definition: measurements-entry.hpp:42
ndn::name
Definition: name-component-types.hpp:33
nfd::measurements::AnyEntry
An EntryPredicate that accepts any entry.
Definition: measurements.hpp:51
nfd::StrategyInfoHost::getStrategyInfo
T * getStrategyInfo() const
Get a StrategyInfo item.
Definition: strategy-info-host.hpp:44
nfd::measurements::Measurements::getInitialLifetime
static time::nanoseconds getInitialLifetime()
Definition: measurements.hpp:136