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-2022, 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 
40 namespace pit {
41 class Entry;
42 } // namespace pit
43 
44 namespace fib {
45 
50 class Fib : noncopyable
51 {
52 public:
53  explicit
54  Fib(NameTree& nameTree);
55 
56  size_t
57  size() const noexcept
58  {
59  return m_nItems;
60  }
61 
62 public: // lookup
65  const Entry&
66  findLongestPrefixMatch(const Name& prefix) const;
67 
72  const Entry&
73  findLongestPrefixMatch(const pit::Entry& pitEntry) const;
74 
79  const Entry&
80  findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
81 
84  Entry*
85  findExactMatch(const Name& prefix);
86 
87 public: // mutation
90  static constexpr size_t
92  {
93  return NameTree::getMaxDepth();
94  }
95 
100  std::pair<Entry*, bool>
101  insert(const Name& prefix);
102 
103  void
104  erase(const Name& prefix);
105 
106  void
107  erase(const Entry& entry);
108 
113  void
114  addOrUpdateNextHop(Entry& entry, Face& face, uint64_t cost);
115 
116  enum class RemoveNextHopResult {
120  };
121 
125  removeNextHop(Entry& entry, const Face& face);
126 
127 public: // enumeration
128  using Range = boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range>;
129  using const_iterator = boost::range_iterator<Range>::type;
130 
137  begin() const
138  {
139  return this->getRange().begin();
140  }
141 
146  end() const
147  {
148  return this->getRange().end();
149  }
150 
151 public: // signal
154  signal::Signal<Fib, Name, NextHop> afterNewNextHop;
155 
156 private:
159  template<typename K>
160  const Entry&
161  findLongestPrefixMatchImpl(const K& key) const;
162 
163  void
164  erase(name_tree::Entry* nte, bool canDeleteNte = true);
165 
166  Range
167  getRange() const;
168 
169 private:
170  NameTree& m_nameTree;
171  size_t m_nItems = 0;
172 
178  static const unique_ptr<Entry> s_emptyEntry;
179 };
180 
181 } // namespace fib
182 
183 using fib::Fib;
184 
185 } // namespace nfd
186 
187 #endif // NFD_DAEMON_TABLE_FIB_HPP
Generalization of a network interface.
Definition: face.hpp:118
Represents an entry in the FIB.
Definition: fib-entry.hpp:91
Represents the Forwarding Information Base (FIB).
Definition: fib.hpp:51
RemoveNextHopResult
Definition: fib.hpp:116
@ NEXTHOP_REMOVED
the nexthop is removed and the fib entry stays
@ FIB_ENTRY_REMOVED
the nexthop is removed and the fib entry is removed
@ NO_SUCH_NEXTHOP
the nexthop is not found
std::pair< Entry *, bool > insert(const Name &prefix)
Find or insert a FIB entry.
Definition: fib.cpp:85
Entry * findExactMatch(const Name &prefix)
Performs an exact match lookup.
Definition: fib.cpp:75
boost::range_iterator< Range >::type const_iterator
Definition: fib.hpp:129
const_iterator begin() const
Definition: fib.hpp:137
RemoveNextHopResult removeNextHop(Entry &entry, const Face &face)
Remove the NextHop record for face from entry.
Definition: fib.cpp:139
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
Definition: fib.hpp:128
signal::Signal< Fib, Name, NextHop > afterNewNextHop
Signals on Fib entry nexthop creation.
Definition: fib.hpp:154
void erase(const Name &prefix)
Definition: fib.cpp:111
const_iterator end() const
Definition: fib.hpp:146
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
Definition: fib.hpp:91
Fib(NameTree &nameTree)
Definition: fib.cpp:40
size_t size() const noexcept
Definition: fib.hpp:57
const Entry & findLongestPrefixMatch(const Name &prefix) const
Performs a longest prefix match.
Definition: fib.cpp:57
void addOrUpdateNextHop(Entry &entry, Face &face, uint64_t cost)
Add a NextHop record.
Definition: fib.cpp:131
Represents an entry in the Measurements table.
An entry in the name tree.
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:37
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition: name-tree.hpp:51
Represents an entry in the Interest table (PIT).
Definition: pit-entry.hpp:197
boost::iterator_range< Iterator > Range
A forward range of name tree entries.
-status-http-server
Definition: common.hpp:71