fib.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_FIB_HPP
27 #define NFD_DAEMON_TABLE_FIB_HPP
28 
29 #include "fib-entry.hpp"
30 #include "name-tree.hpp"
31 
32 #include <boost/range/adaptor/transformed.hpp>
33 
34 namespace nfd {
35 
36 namespace measurements {
37 class Entry;
38 } // namespace measurements
39 namespace pit {
40 class Entry;
41 } // namespace pit
42 
43 namespace fib {
44 
47 class Fib : noncopyable
48 {
49 public:
50  explicit
51  Fib(NameTree& nameTree);
52 
53  size_t
54  size() const
55  {
56  return m_nItems;
57  }
58 
59 public: // lookup
62  const Entry&
63  findLongestPrefixMatch(const Name& prefix) const;
64 
69  const Entry&
70  findLongestPrefixMatch(const pit::Entry& pitEntry) const;
71 
76  const Entry&
77  findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
78 
81  Entry*
82  findExactMatch(const Name& prefix);
83 
84 public: // mutation
87  static constexpr size_t
89  {
90  return NameTree::getMaxDepth();
91  }
92 
97  std::pair<Entry*, bool>
98  insert(const Name& prefix);
99 
100  void
101  erase(const Name& prefix);
102 
103  void
104  erase(const Entry& entry);
105 
108  void
109  removeNextHop(Entry& entry, const Face& face, EndpointId endpointId);
110 
113  void
114  removeNextHopByFace(Entry& entry, const Face& face);
115 
116 public: // enumeration
117  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
118  typedef boost::range_iterator<Range>::type const_iterator;
119 
125  const_iterator
126  begin() const
127  {
128  return this->getRange().begin();
129  }
130 
134  const_iterator
135  end() const
136  {
137  return this->getRange().end();
138  }
139 
140 private:
143  template<typename K>
144  const Entry&
145  findLongestPrefixMatchImpl(const K& key) const;
146 
147  void
148  erase(name_tree::Entry* nte, bool canDeleteNte = true);
149 
152  void
153  eraseIfEmpty(Entry& entry);
154 
155  Range
156  getRange() const;
157 
158 private:
159  NameTree& m_nameTree;
160  size_t m_nItems = 0;
161 
167  static const unique_ptr<Entry> s_emptyEntry;
168 };
169 
170 } // namespace fib
171 
172 using fib::Fib;
173 
174 } // namespace nfd
175 
176 #endif // NFD_DAEMON_TABLE_FIB_HPP
size_t size() const
Definition: fib.hpp:54
Represents a Measurements entry.
represents a FIB entry
Definition: fib-entry.hpp:51
Represents the Forwarding Information Base (FIB)
Definition: fib.hpp:47
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
Definition: fib.hpp:117
An Interest table entry.
Definition: pit-entry.hpp:58
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:38
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
const_iterator begin() const
Definition: fib.hpp:126
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
Definition: fib.hpp:88
const_iterator end() const
Definition: fib.hpp:135
An entry in the name tree.
boost::range_iterator< Range >::type const_iterator
Definition: fib.hpp:118
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries