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-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_FIB_HPP
27 #define NFD_DAEMON_TABLE_FIB_HPP
28 
29 #include "fib-entry.hpp"
30 #include "name-tree.hpp"
31 
32 #include "core/fib-max-depth.hpp"
33 
34 #include <boost/range/adaptor/transformed.hpp>
35 
36 namespace nfd {
37 
38 namespace measurements {
39 class Entry;
40 } // namespace measurements
41 namespace pit {
42 class Entry;
43 } // namespace pit
44 
45 namespace fib {
46 
49 class Fib : noncopyable
50 {
51 public:
52  explicit
53  Fib(NameTree& nameTree);
54 
55  size_t
56  size() const
57  {
58  return m_nItems;
59  }
60 
61 public: // lookup
64  const Entry&
65  findLongestPrefixMatch(const Name& prefix) const;
66 
71  const Entry&
72  findLongestPrefixMatch(const pit::Entry& pitEntry) const;
73 
78  const Entry&
79  findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
80 
83  Entry*
84  findExactMatch(const Name& prefix);
85 
86 public: // mutation
91  static constexpr size_t
93  {
94  static_assert(FIB_MAX_DEPTH == NameTree::getMaxDepth(), "");
95  return FIB_MAX_DEPTH;
96  }
97 
103  std::pair<Entry*, bool>
104  insert(const Name& prefix);
105 
106  void
107  erase(const Name& prefix);
108 
109  void
110  erase(const Entry& entry);
111 
114  void
115  removeNextHop(Entry& entry, const Face& face);
116 
117 public: // enumeration
118  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
119  typedef boost::range_iterator<Range>::type const_iterator;
120 
127  begin() const
128  {
129  return this->getRange().begin();
130  }
131 
136  end() const
137  {
138  return this->getRange().end();
139  }
140 
141 private:
144  template<typename K>
145  const Entry&
146  findLongestPrefixMatchImpl(const K& key) const;
147 
148  void
149  erase(name_tree::Entry* nte, bool canDeleteNte = true);
150 
151  Range
152  getRange() const;
153 
154 private:
155  NameTree& m_nameTree;
156  size_t m_nItems;
157 
163  static const unique_ptr<Entry> s_emptyEntry;
164 };
165 
166 } // namespace fib
167 
168 using fib::Fib;
169 
170 } // namespace nfd
171 
172 #endif // NFD_DAEMON_TABLE_FIB_HPP
std::pair< Entry *, bool > insert(const Name &prefix)
inserts a FIB entry for prefix
Definition: fib.cpp:90
Fib(NameTree &nameTree)
Definition: fib.cpp:44
Entry * findExactMatch(const Name &prefix)
performs an exact match lookup
Definition: fib.cpp:80
void erase(const Name &prefix)
Definition: fib.cpp:116
generalization of a network interface
Definition: face.hpp:67
represents a FIB entry
Definition: fib-entry.hpp:51
const_iterator end() const
Definition: fib.hpp:136
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
Definition: fib.hpp:92
const Entry & findLongestPrefixMatch(const Name &prefix) const
performs a longest prefix match
Definition: fib.cpp:62
represents a Measurements entry
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
represents the Forwarding Information Base (FIB)
Definition: fib.hpp:49
const_iterator begin() const
Definition: fib.hpp:127
Represents an absolute name.
Definition: name.hpp:42
boost::range_iterator< Range >::type const_iterator
Definition: fib.hpp:119
void removeNextHop(Entry &entry, const Face &face)
removes the NextHop record for face
Definition: fib.cpp:136
static const int FIB_MAX_DEPTH
Maximum number of components in a FIB entry prefix.
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
size_t size() const
Definition: fib.hpp:56
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
Definition: fib.hpp:118
an entry in the name tree
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
Definition: name-tree.hpp:54