measurements.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
75 class Measurements : noncopyable
76 {
77 public:
78  explicit
79  Measurements(NameTree& nametree);
80 
83  Entry&
84  get(const Name& name);
85 
88  Entry&
89  get(const fib::Entry& fibEntry);
90 
93  Entry&
94  get(const pit::Entry& pitEntry);
95 
99  Entry*
100  getParent(const Entry& child);
101 
104  Entry*
105  findLongestPrefixMatch(const Name& name,
106  const EntryPredicate& pred = AnyEntry()) const;
107 
110  Entry*
111  findLongestPrefixMatch(const pit::Entry& pitEntry,
112  const EntryPredicate& pred = AnyEntry()) const;
113 
116  Entry*
117  findExactMatch(const Name& name) const;
118 
119  static time::nanoseconds
120  getInitialLifetime();
121 
126  void
127  extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
128 
129  size_t
130  size() const;
131 
132 private:
133  void
134  cleanup(Entry& entry);
135 
136  Entry&
137  get(name_tree::Entry& nte);
138 
141  template<typename K>
142  Entry*
143  findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;
144 
145 private:
146  NameTree& m_nameTree;
147  size_t m_nItems;
148 };
149 
150 inline time::nanoseconds
151 Measurements::getInitialLifetime()
152 {
153  return time::seconds(4);
154 }
155 
156 inline size_t
157 Measurements::size() const
158 {
159  return m_nItems;
160 }
161 
162 } // namespace measurements
163 
165 
166 } // namespace nfd
167 
168 #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
represents a Measurements entry
represents a FIB entry
Definition: fib-entry.hpp:51
std::function< bool(const Entry &)> EntryPredicate
a predicate that accepts or rejects an entry
an EntryPredicate that accepts an entry if it has StrategyInfo of type T
bool operator()(const Entry &entry) const
represents the Measurements table
an Interest table entry
Definition: pit-entry.hpp:57
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
an entry in the name tree
T * getStrategyInfo() const
get a StrategyInfo item
an EntryPredicate that accepts any entry
bool operator()(const Entry &entry) const