NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
name-tree.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_NAME_TREE_HPP
27 #define NFD_DAEMON_TABLE_NAME_TREE_HPP
28 
29 #include "name-tree-iterator.hpp"
30 
31 #include "core/fib-max-depth.hpp"
32 
33 namespace nfd {
34 namespace name_tree {
35 
38 class NameTree : noncopyable
39 {
40 public:
41  explicit
42  NameTree(size_t nBuckets = 1024);
43 
44 public: // information
52  static constexpr size_t
54  {
55  return FIB_MAX_DEPTH;
56  }
57 
60  size_t
61  size() const
62  {
63  return m_ht.size();
64  }
65 
68  size_t
69  getNBuckets() const
70  {
71  return m_ht.getNBuckets();
72  }
73 
77  template<typename EntryT>
78  Entry*
79  getEntry(const EntryT& tableEntry) const
80  {
81  return Entry::get(tableEntry);
82  }
83 
84 public: // mutation
94  Entry&
95  lookup(const Name& name, size_t prefixLen);
96 
99  Entry&
100  lookup(const Name& name)
101  {
102  return this->lookup(name, name.size());
103  }
104 
109  Entry&
110  lookup(const fib::Entry& fibEntry);
111 
117  Entry&
118  lookup(const pit::Entry& pitEntry);
119 
124  Entry&
125  lookup(const measurements::Entry& measurementsEntry);
126 
131  Entry&
132  lookup(const strategy_choice::Entry& strategyChoiceEntry);
133 
144  size_t
145  eraseIfEmpty(Entry* entry, bool canEraseAncestors = true);
146 
147 public: // matching
151  Entry*
152  findExactMatch(const Name& name, size_t prefixLen = std::numeric_limits<size_t>::max()) const;
153 
159  Entry*
161  const EntrySelector& entrySelector = AnyEntry()) const;
162 
167  Entry*
168  findLongestPrefixMatch(const Entry& entry,
169  const EntrySelector& entrySelector = AnyEntry()) const;
170 
177  template<typename EntryT>
178  Entry*
179  findLongestPrefixMatch(const EntryT& tableEntry,
180  const EntrySelector& entrySelector = AnyEntry()) const
181  {
182  const Entry* nte = this->getEntry(tableEntry);
183  BOOST_ASSERT(nte != nullptr);
184  return this->findLongestPrefixMatch(*nte, entrySelector);
185  }
186 
192  Entry*
193  findLongestPrefixMatch(const pit::Entry& pitEntry,
194  const EntrySelector& entrySelector = AnyEntry()) const;
195 
215  Range
216  findAllMatches(const Name& name,
217  const EntrySelector& entrySelector = AnyEntry()) const;
218 
219 public: // enumeration
221 
236  Range
237  fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const;
238 
256  Range
257  partialEnumerate(const Name& prefix,
258  const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const;
259 
264  begin() const
265  {
266  return fullEnumerate().begin();
267  }
268 
273  end() const
274  {
275  return Iterator();
276  }
277 
278 private:
279  Hashtable m_ht;
280 
281  friend class EnumerationImpl;
282 };
283 
284 } // namespace name_tree
285 
286 using name_tree::NameTree;
287 
288 } // namespace nfd
289 
290 #endif // NFD_DAEMON_TABLE_NAME_TREE_HPP
represents a FIB entry
Definition: fib-entry.hpp:51
const_iterator end() const
Definition: name-tree.hpp:273
an EntrySelector that accepts every Entry
an EntrySubTreeSelector that accepts every Entry and its children
a hashtable for fast exact name lookup
Entry & lookup(const Name &name, size_t prefixLen)
find or insert an entry by name
Definition: name-tree.cpp:44
Entry * findLongestPrefixMatch(const Name &name, const EntrySelector &entrySelector=AnyEntry()) const
longest prefix matching
Definition: name-tree.cpp:162
Entry & lookup(const Name &name)
equivalent to lookup(name, name.size())
Definition: name-tree.hpp:100
represents a Measurements entry
Range partialEnumerate(const Name &prefix, const EntrySubTreeSelector &entrySubTreeSelector=AnyEntrySubTree()) const
enumerate all entries under a prefix
Definition: name-tree.cpp:232
Range findAllMatches(const Name &name, const EntrySelector &entrySelector=AnyEntry()) const
all-prefixes match lookup
Definition: name-tree.cpp:213
Entry * findLongestPrefixMatch(const EntryT &tableEntry, const EntrySelector &entrySelector=AnyEntry()) const
equivalent to findLongestPrefixMatch(getEntry(tableEntry)->getName(), entrySelector)
Definition: name-tree.hpp:179
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:59
Entry * getEntry(const EntryT &tableEntry) const
Definition: name-tree.hpp:79
static Entry * get(const ENTRY &tableEntry)
Represents an absolute name.
Definition: name.hpp:43
represents a Strategy Choice entry
Range fullEnumerate(const EntrySelector &entrySelector=AnyEntry()) const
enumerate all entries
Definition: name-tree.cpp:226
static const int FIB_MAX_DEPTH
Maximum number of components in a FIB entry prefix.
NameTree(size_t nBuckets=1024)
Definition: name-tree.cpp:38
size_t eraseIfEmpty(Entry *entry, bool canEraseAncestors=true)
delete the entry if it is empty
Definition: name-tree.cpp:123
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:38
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
std::function< std::pair< bool, bool >(const Entry &)> EntrySubTreeSelector
a predicate to accept or reject an Entry and its children
size_t getNBuckets() const
Definition: name-tree.hpp:69
size_t size() const
Definition: name-tree.hpp:61
Entry * findExactMatch(const Name &name, size_t prefixLen=std::numeric_limits< size_t >::max()) const
exact match lookup
Definition: name-tree.cpp:150
std::function< bool(const Entry &)> EntrySelector
a predicate to accept or reject an Entry in find operations
const_iterator begin() const
Definition: name-tree.hpp:264
enumeration operation implementation
an entry in the name tree
static constexpr size_t getMaxDepth()
maximum depth of the name tree
Definition: name-tree.hpp:53