pit-entry.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_ENTRY_HPP
27 #define NFD_DAEMON_TABLE_PIT_ENTRY_HPP
28 
29 #include "strategy-info-host.hpp"
30 
31 #include <ndn-cxx/util/scheduler.hpp>
32 
33 #include <list>
34 
35 namespace nfd {
36 
37 namespace face {
38 class Face;
39 } // namespace face
40 using face::Face;
41 
42 namespace name_tree {
43 class Entry;
44 } // namespace name_tree
45 
46 namespace pit {
47 
54 {
55 public:
56  explicit
58  : m_face(face)
59  {
60  }
61 
62  Face&
63  getFace() const noexcept
64  {
65  return m_face;
66  }
67 
68  Interest::Nonce
69  getLastNonce() const noexcept
70  {
71  return m_lastNonce;
72  }
73 
74  time::steady_clock::time_point
75  getLastRenewed() const noexcept
76  {
77  return m_lastRenewed;
78  }
79 
84  time::steady_clock::time_point
85  getExpiry() const noexcept
86  {
87  return m_expiry;
88  }
89 
93  void
94  update(const Interest& interest);
95 
96 private:
97  Face& m_face;
98  Interest::Nonce m_lastNonce{0, 0, 0, 0};
99  time::steady_clock::time_point m_lastRenewed = time::steady_clock::time_point::min();
100  time::steady_clock::time_point m_expiry = time::steady_clock::time_point::min();
101 };
102 
106 class InRecord : public FaceRecord
107 {
108 public:
110 
111  const Interest&
112  getInterest() const noexcept
113  {
114  BOOST_ASSERT(m_interest != nullptr);
115  return *m_interest;
116  }
117 
118  void
119  update(const Interest& interest);
120 
121 private:
122  shared_ptr<const Interest> m_interest;
123 };
124 
128 class OutRecord : public FaceRecord
129 {
130 public:
132 
139  const lp::NackHeader*
140  getIncomingNack() const noexcept
141  {
142  return m_incomingNack.get();
143  }
144 
155  bool
156  setIncomingNack(const lp::Nack& nack);
157 
165  void
166  clearIncomingNack() noexcept
167  {
168  m_incomingNack.reset();
169  }
170 
171 private:
172  unique_ptr<lp::NackHeader> m_incomingNack;
173 };
174 
178 using InRecordCollection = std::list<InRecord>;
179 
183 using OutRecordCollection = std::list<OutRecord>;
184 
196 class Entry : public StrategyInfoHost, noncopyable
197 {
198 public:
199  explicit
200  Entry(const Interest& interest);
201 
207  const Interest&
208  getInterest() const
209  {
210  return *m_interest;
211  }
212 
215  const Name&
216  getName() const
217  {
218  return m_interest->getName();
219  }
220 
225  bool
226  canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
227 
228 public: // in-record
232  const InRecordCollection&
233  getInRecords() const noexcept
234  {
235  return m_inRecords;
236  }
237 
243  bool
244  hasInRecords() const noexcept
245  {
246  return !m_inRecords.empty();
247  }
248 
249  InRecordCollection::iterator
250  in_begin() noexcept
251  {
252  return m_inRecords.begin();
253  }
254 
255  InRecordCollection::const_iterator
256  in_begin() const noexcept
257  {
258  return m_inRecords.begin();
259  }
260 
261  InRecordCollection::iterator
262  in_end() noexcept
263  {
264  return m_inRecords.end();
265  }
266 
267  InRecordCollection::const_iterator
268  in_end() const noexcept
269  {
270  return m_inRecords.end();
271  }
272 
277  InRecordCollection::iterator
278  findInRecord(const Face& face) noexcept;
279 
284  InRecordCollection::iterator
285  insertOrUpdateInRecord(Face& face, const Interest& interest);
286 
291  void
292  deleteInRecord(InRecordCollection::const_iterator pos)
293  {
294  m_inRecords.erase(pos);
295  }
296 
300  void
301  clearInRecords() noexcept
302  {
303  m_inRecords.clear();
304  }
305 
306 public: // out-record
310  const OutRecordCollection&
311  getOutRecords() const noexcept
312  {
313  return m_outRecords;
314  }
315 
322  bool
323  hasOutRecords() const noexcept
324  {
325  return !m_outRecords.empty();
326  }
327 
328  OutRecordCollection::iterator
329  out_begin() noexcept
330  {
331  return m_outRecords.begin();
332  }
333 
334  OutRecordCollection::const_iterator
335  out_begin() const noexcept
336  {
337  return m_outRecords.begin();
338  }
339 
340  OutRecordCollection::iterator
341  out_end() noexcept
342  {
343  return m_outRecords.end();
344  }
345 
346  OutRecordCollection::const_iterator
347  out_end() const noexcept
348  {
349  return m_outRecords.end();
350  }
351 
356  OutRecordCollection::iterator
357  findOutRecord(const Face& face) noexcept;
358 
363  OutRecordCollection::iterator
364  insertOrUpdateOutRecord(Face& face, const Interest& interest);
365 
369  void
370  deleteOutRecord(const Face& face);
371 
372 public:
377  ndn::scheduler::EventId expiryTimer;
378 
381  bool isSatisfied = false;
382 
386  time::milliseconds dataFreshnessPeriod = 0_ms;
387 
388 private:
389  shared_ptr<const Interest> m_interest;
390  InRecordCollection m_inRecords;
391  OutRecordCollection m_outRecords;
392 
393  name_tree::Entry* m_nameTreeEntry = nullptr;
394 
395  friend ::nfd::name_tree::Entry;
396 };
397 
398 } // namespace pit
399 } // namespace nfd
400 
401 #endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP
Base class for an entity onto which StrategyInfo items may be placed.
Generalization of a network interface.
Definition: face.hpp:118
An entry in the name tree.
Represents an entry in the Interest table (PIT).
Definition: pit-entry.hpp:197
time::milliseconds dataFreshnessPeriod
Data freshness period.
Definition: pit-entry.hpp:386
bool canMatch(const Interest &interest, size_t nEqualNameComps=0) const
Definition: pit-entry.cpp:68
InRecordCollection::const_iterator in_end() const noexcept
Definition: pit-entry.hpp:268
InRecordCollection::iterator in_begin() noexcept
Definition: pit-entry.hpp:250
const Interest & getInterest() const
Definition: pit-entry.hpp:208
const OutRecordCollection & getOutRecords() const noexcept
Returns the collection of out-records.
Definition: pit-entry.hpp:311
OutRecordCollection::const_iterator out_end() const noexcept
Definition: pit-entry.hpp:347
OutRecordCollection::iterator out_begin() noexcept
Definition: pit-entry.hpp:329
void deleteInRecord(InRecordCollection::const_iterator pos)
Removes the in-record at position pos.
Definition: pit-entry.hpp:292
Entry(const Interest &interest)
Definition: pit-entry.cpp:62
void clearInRecords() noexcept
Removes all in-records.
Definition: pit-entry.hpp:301
const Name & getName() const
Definition: pit-entry.hpp:216
bool isSatisfied
Indicates whether this PIT entry is satisfied.
Definition: pit-entry.hpp:381
OutRecordCollection::iterator findOutRecord(const Face &face) noexcept
Get the out-record for face.
Definition: pit-entry.cpp:103
OutRecordCollection::iterator out_end() noexcept
Definition: pit-entry.hpp:341
const InRecordCollection & getInRecords() const noexcept
Returns the collection of in-records.
Definition: pit-entry.hpp:233
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, const Interest &interest)
Insert or update an out-record.
Definition: pit-entry.cpp:110
InRecordCollection::iterator in_end() noexcept
Definition: pit-entry.hpp:262
InRecordCollection::iterator findInRecord(const Face &face) noexcept
Get the in-record for face.
Definition: pit-entry.cpp:81
OutRecordCollection::const_iterator out_begin() const noexcept
Definition: pit-entry.hpp:335
ndn::scheduler::EventId expiryTimer
Expiry timer.
Definition: pit-entry.hpp:377
bool hasOutRecords() const noexcept
Definition: pit-entry.hpp:323
InRecordCollection::iterator insertOrUpdateInRecord(Face &face, const Interest &interest)
Insert or update an in-record.
Definition: pit-entry.cpp:88
InRecordCollection::const_iterator in_begin() const noexcept
Definition: pit-entry.hpp:256
bool hasInRecords() const noexcept
Definition: pit-entry.hpp:244
void deleteOutRecord(const Face &face)
Delete the out-record for face if it exists.
Definition: pit-entry.cpp:125
Contains information about an Interest on an incoming or outgoing face.
Definition: pit-entry.hpp:54
time::steady_clock::time_point getExpiry() const noexcept
Returns the time point at which this record expires.
Definition: pit-entry.hpp:85
void update(const Interest &interest)
Updates lastNonce, lastRenewed, expiry fields.
Definition: pit-entry.cpp:33
Face & getFace() const noexcept
Definition: pit-entry.hpp:63
time::steady_clock::time_point getLastRenewed() const noexcept
Definition: pit-entry.hpp:75
FaceRecord(Face &face)
Definition: pit-entry.hpp:57
Interest::Nonce getLastNonce() const noexcept
Definition: pit-entry.hpp:69
Contains information about an Interest from an incoming face.
Definition: pit-entry.hpp:107
const Interest & getInterest() const noexcept
Definition: pit-entry.hpp:112
void update(const Interest &interest)
Definition: pit-entry.cpp:45
Contains information about an Interest toward an outgoing face.
Definition: pit-entry.hpp:129
void clearIncomingNack() noexcept
Clears last Nack.
Definition: pit-entry.hpp:166
bool setIncomingNack(const lp::Nack &nack)
Sets a Nack received from getFace().
Definition: pit-entry.cpp:52
const lp::NackHeader * getIncomingNack() const noexcept
Returns the last Nack returned by getFace().
Definition: pit-entry.hpp:140
std::list< OutRecord > OutRecordCollection
An unordered collection of out-records.
Definition: pit-entry.hpp:183
std::list< InRecord > InRecordCollection
An unordered collection of in-records.
Definition: pit-entry.hpp:178
-status-http-server
Definition: common.hpp:71