pit.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, 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_PIT_HPP
27 #define NFD_DAEMON_TABLE_PIT_HPP
28 
29 #include "name-tree.hpp"
30 #include "pit-entry.hpp"
31 
32 namespace nfd {
33 namespace pit {
34 
38 using DataMatchResult = std::vector<shared_ptr<Entry>>;
39 
43 class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
44 {
45 public:
51  explicit
52  Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0)
53  : m_ntIt(ntIt)
54  , m_iPitEntry(iPitEntry)
55  {
56  }
57 
58  const Entry&
59  operator*() const noexcept
60  {
61  BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
62  BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
63  return *m_ntIt->getPitEntries()[m_iPitEntry];
64  }
65 
66  Iterator&
67  operator++();
68 
69  friend bool
70  operator==(const Iterator& lhs, const Iterator& rhs) noexcept
71  {
72  return lhs.m_ntIt == rhs.m_ntIt &&
73  lhs.m_iPitEntry == rhs.m_iPitEntry;
74  }
75 
76 private:
78  size_t m_iPitEntry;
79 };
80 
84 class Pit : noncopyable
85 {
86 public:
87  explicit
88  Pit(NameTree& nameTree);
89 
93  size_t
94  size() const
95  {
96  return m_nItems;
97  }
98 
103  shared_ptr<Entry>
104  find(const Interest& interest) const
105  {
106  return const_cast<Pit*>(this)->findOrInsert(interest, false).first;
107  }
108 
114  std::pair<shared_ptr<Entry>, bool>
115  insert(const Interest& interest)
116  {
117  return this->findOrInsert(interest, true);
118  }
119 
124  findAllDataMatches(const Data& data) const;
125 
128  void
129  erase(Entry* entry)
130  {
131  this->erase(entry, true);
132  }
133 
136  void
137  deleteInOutRecords(Entry* entry, const Face& face);
138 
139 public: // enumeration
141 
148  begin() const;
149 
154  end() const
155  {
156  return Iterator();
157  }
158 
159 private:
160  void
161  erase(Entry* pitEntry, bool canDeleteNte);
162 
171  std::pair<shared_ptr<Entry>, bool>
172  findOrInsert(const Interest& interest, bool allowInsert);
173 
174 private:
175  NameTree& m_nameTree;
176  size_t m_nItems = 0;
177 };
178 
179 } // namespace pit
180 
181 using pit::Pit;
182 
183 } // namespace nfd
184 
185 #endif // NFD_DAEMON_TABLE_PIT_HPP
Generalization of a network interface.
Definition: face.hpp:118
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:37
Represents an entry in the Interest table (PIT).
Definition: pit-entry.hpp:197
PIT iterator.
Definition: pit.hpp:44
friend bool operator==(const Iterator &lhs, const Iterator &rhs) noexcept
Definition: pit.hpp:70
const Entry & operator*() const noexcept
Definition: pit.hpp:59
Iterator & operator++()
Definition: pit.cpp:31
Iterator(const NameTree::const_iterator &ntIt={}, size_t iPitEntry=0)
Constructor.
Definition: pit.hpp:52
NFD's Interest Table.
Definition: pit.hpp:85
std::pair< shared_ptr< Entry >, bool > insert(const Interest &interest)
Inserts a PIT entry for interest.
Definition: pit.hpp:115
const_iterator begin() const
Definition: pit.cpp:142
size_t size() const
Returns the number of entries.
Definition: pit.hpp:94
Pit(NameTree &nameTree)
Definition: pit.cpp:44
shared_ptr< Entry > find(const Interest &interest) const
Finds a PIT entry for interest.
Definition: pit.hpp:104
const_iterator end() const
Definition: pit.hpp:154
DataMatchResult findAllDataMatches(const Data &data) const
Performs a Data match.
Definition: pit.cpp:99
void deleteInOutRecords(Entry *entry, const Face &face)
Deletes in-records and out-records for face.
Definition: pit.cpp:128
void erase(Entry *entry)
Deletes an entry.
Definition: pit.hpp:129
std::vector< shared_ptr< Entry > > DataMatchResult
An unordered iterable of all PIT entries matching a Data packet.
Definition: pit.hpp:38
-status-http-server
Definition: common.hpp:71