NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 
110  void
111  addOrUpdateNextHop(Entry& entry, Face& face, uint64_t cost);
112 
113  enum class RemoveNextHopResult {
114  NO_SUCH_NEXTHOP,
115  NEXTHOP_REMOVED,
116  FIB_ENTRY_REMOVED
117  };
118 
122  removeNextHop(Entry& entry, const Face& face);
123 
124 public: // enumeration
125  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
126  typedef boost::range_iterator<Range>::type const_iterator;
127 
133  const_iterator
134  begin() const
135  {
136  return this->getRange().begin();
137  }
138 
142  const_iterator
143  end() const
144  {
145  return this->getRange().end();
146  }
147 
148 public: // signal
152 
153 private:
156  template<typename K>
157  const Entry&
158  findLongestPrefixMatchImpl(const K& key) const;
159 
160  void
161  erase(name_tree::Entry* nte, bool canDeleteNte = true);
162 
163  Range
164  getRange() const;
165 
166 private:
167  NameTree& m_nameTree;
168  size_t m_nItems = 0;
169 
175  static const unique_ptr<Entry> s_emptyEntry;
176 };
177 
178 } // namespace fib
179 
180 using fib::Fib;
181 
182 } // namespace nfd
183 
184 #endif // NFD_DAEMON_TABLE_FIB_HPP
represents a FIB entry
Definition: fib-entry.hpp:53
const_iterator end() const
Definition: fib.hpp:143
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
Definition: fib.hpp:88
provides a lightweight signal / event system
Definition: signal.hpp:52
Represents a Measurements entry.
ndn Face
Definition: face-impl.hpp:42
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
An Interest table entry.
Definition: pit-entry.hpp:58
Represents the Forwarding Information Base (FIB)
Definition: fib.hpp:47
signal::Signal< Fib, Name, NextHop > afterNewNextHop
signals on Fib entry nexthop creation
Definition: fib.hpp:151
const_iterator begin() const
Definition: fib.hpp:134
Represents an absolute name.
Definition: name.hpp:41
boost::range_iterator< Range >::type const_iterator
Definition: fib.hpp:126
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:36
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
RemoveNextHopResult
Definition: fib.hpp:113
size_t size() const
Definition: fib.hpp:54
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
Definition: fib.hpp:125
An entry in the name tree.
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition: name-tree.hpp:51