blob: 82ed272adb1d2a3db010188d6bf32b4a529477d7 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Teng Liang6f09ab62018-03-01 20:04:08 -07002/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Junxiao Shi1e46be32015-01-08 20:18:05 -07004 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_PIT_ENTRY_HPP
27#define NFD_DAEMON_TABLE_PIT_ENTRY_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070028
29#include "pit-in-record.hpp"
30#include "pit-out-record.hpp"
31
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050032#include <ndn-cxx/util/scheduler.hpp>
33
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040034#include <list>
35
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036namespace nfd::name_tree {
HangZhangcb4fc832014-03-11 16:57:11 +080037class Entry;
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040038} // namespace nfd::name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080039
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040040namespace nfd::pit {
Junxiao Shicbba04c2014-01-26 14:21:22 -070041
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040042/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040043 * \brief An unordered collection of in-records.
Junxiao Shicbba04c2014-01-26 14:21:22 -070044 */
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040045using InRecordCollection = std::list<InRecord>;
Junxiao Shicbba04c2014-01-26 14:21:22 -070046
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040047/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040048 * \brief An unordered collection of out-records.
Junxiao Shicbba04c2014-01-26 14:21:22 -070049 */
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040050using OutRecordCollection = std::list<OutRecord>;
Junxiao Shicbba04c2014-01-26 14:21:22 -070051
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040052/**
53 * \brief Represents an entry in the %Interest table (PIT).
Junxiao Shi4846f372016-04-05 13:39:30 -070054 *
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040055 * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
56 * Each entry contains a collection of in-records, a collection of out-records,
57 * and two timers used in forwarding pipelines.
58 * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
59 * which allows forwarding strategy to store arbitrary information on them.
60 *
61 * \sa Pit
Junxiao Shicbba04c2014-01-26 14:21:22 -070062 */
Junxiao Shi408a7002014-02-12 17:53:47 -070063class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070064{
65public:
66 explicit
67 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070068
Junxiao Shi4846f372016-04-05 13:39:30 -070069 /** \return the representative Interest of the PIT entry
70 * \note Every Interest in in-records and out-records should have same Name and Selectors
71 * as the representative Interest.
72 * \todo #3162 require Link field to match the representative Interest
73 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070074 const Interest&
Junxiao Shi340d5532016-08-13 04:00:35 +000075 getInterest() const
76 {
77 return *m_interest;
78 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070079
80 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070081 */
82 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000083 getName() const
84 {
85 return m_interest->getName();
86 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070087
Junxiao Shia2742922016-11-17 22:53:23 +000088 /** \return whether interest matches this entry
89 * \param interest the Interest
90 * \param nEqualNameComps number of initial name components guaranteed to be equal
91 */
92 bool
93 canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
94
Junxiao Shi4846f372016-04-05 13:39:30 -070095public: // in-record
96 /** \return collection of in-records
97 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070098 const InRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +000099 getInRecords() const
100 {
101 return m_inRecords;
102 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700103
Junxiao Shi4846f372016-04-05 13:39:30 -0700104 /** \retval true There is at least one in-record.
105 * This implies some downstream is waiting for Data or Nack.
106 * \retval false There is no in-record.
107 * This implies the entry is new or has been satisfied or Nacked.
108 */
109 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000110 hasInRecords() const
111 {
112 return !m_inRecords.empty();
113 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700114
115 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000116 in_begin()
117 {
118 return m_inRecords.begin();
119 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700120
121 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000122 in_begin() const
123 {
124 return m_inRecords.begin();
125 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700126
127 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000128 in_end()
129 {
130 return m_inRecords.end();
131 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700132
133 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000134 in_end() const
135 {
136 return m_inRecords.end();
137 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700138
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400139 /** \brief Get the in-record for \p face.
Davide Pesavento50a6af32019-02-21 00:04:40 -0500140 * \return an iterator to the in-record, or in_end() if it does not exist
Junxiao Shi4846f372016-04-05 13:39:30 -0700141 */
142 InRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000143 getInRecord(const Face& face);
Junxiao Shi4846f372016-04-05 13:39:30 -0700144
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400145 /** \brief Insert or update an in-record.
Junxiao Shi4846f372016-04-05 13:39:30 -0700146 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700147 */
148 InRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000149 insertOrUpdateInRecord(Face& face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700150
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400151 /** \brief Delete the in-record for \p face if it exists.
Junxiao Shi66f91f82014-05-10 17:28:58 -0700152 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700153 void
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000154 deleteInRecord(const Face& face);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700155
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400156 /** \brief Delete all in-records.
Junxiao Shi4846f372016-04-05 13:39:30 -0700157 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700158 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700159 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700160
Junxiao Shi4846f372016-04-05 13:39:30 -0700161public: // out-record
162 /** \return collection of in-records
163 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700164 const OutRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +0000165 getOutRecords() const
166 {
167 return m_outRecords;
168 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700169
Junxiao Shi4846f372016-04-05 13:39:30 -0700170 /** \retval true There is at least one out-record.
171 * This implies the Interest has been forwarded to some upstream,
172 * and they haven't returned Data, but may have returned Nacks.
173 * \retval false There is no out-record.
174 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700175 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700176 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000177 hasOutRecords() const
178 {
179 return !m_outRecords.empty();
180 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700181
Junxiao Shi4846f372016-04-05 13:39:30 -0700182 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000183 out_begin()
184 {
185 return m_outRecords.begin();
186 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700187
188 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000189 out_begin() const
190 {
191 return m_outRecords.begin();
192 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700193
194 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000195 out_end()
196 {
197 return m_outRecords.end();
198 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700199
200 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000201 out_end() const
202 {
203 return m_outRecords.end();
204 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700205
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400206 /** \brief Get the out-record for \p face.
Davide Pesavento50a6af32019-02-21 00:04:40 -0500207 * \return an iterator to the out-record, or out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700208 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700209 OutRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000210 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700211
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400212 /** \brief Insert or update an out-record.
Junxiao Shi4846f372016-04-05 13:39:30 -0700213 * \return an iterator to the new or updated out-record
214 */
215 OutRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000216 insertOrUpdateOutRecord(Face& face, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700217
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400218 /** \brief Delete the out-record for \p face if it exists.
Junxiao Shi4846f372016-04-05 13:39:30 -0700219 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700220 void
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000221 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700222
Junxiao Shid3c792f2014-01-30 00:46:13 -0700223public:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400224 /** \brief Expiry timer.
Junxiao Shi4846f372016-04-05 13:39:30 -0700225 *
226 * This timer is used in forwarding pipelines to delete the entry
Junxiao Shi4846f372016-04-05 13:39:30 -0700227 */
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500228 ndn::scheduler::EventId expiryTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700229
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400230 /** \brief Indicates whether this PIT entry is satisfied.
Teng Liang6f09ab62018-03-01 20:04:08 -0700231 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500232 bool isSatisfied = false;
Teng Liang6f09ab62018-03-01 20:04:08 -0700233
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400234 /** \brief Data freshness period.
Teng Liang6f09ab62018-03-01 20:04:08 -0700235 * \note This field is meaningful only if isSatisfied is true
236 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500237 time::milliseconds dataFreshnessPeriod = 0_ms;
Teng Liang6f09ab62018-03-01 20:04:08 -0700238
Junxiao Shicbba04c2014-01-26 14:21:22 -0700239private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700240 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700241 InRecordCollection m_inRecords;
242 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700243
Davide Pesavento50a6af32019-02-21 00:04:40 -0500244 name_tree::Entry* m_nameTreeEntry = nullptr;
HangZhangcb4fc832014-03-11 16:57:11 +0800245
Davide Pesavento9a28c3f2022-06-11 21:50:01 -0400246 friend ::nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700247};
248
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400249} // namespace nfd::pit
Junxiao Shicbba04c2014-01-26 14:21:22 -0700250
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700251#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP