blob: f6125122974cd6baadb30857b375b085249f0927 [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 Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, 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 Pesaventoc0822fa2018-05-10 21:54:10 -040032#include <list>
33
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034namespace nfd::name_tree {
HangZhangcb4fc832014-03-11 16:57:11 +080035class Entry;
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036} // namespace nfd::name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080037
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040038namespace nfd::pit {
Junxiao Shicbba04c2014-01-26 14:21:22 -070039
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040040/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040041 * \brief An unordered collection of in-records.
Junxiao Shicbba04c2014-01-26 14:21:22 -070042 */
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040043using InRecordCollection = std::list<InRecord>;
Junxiao Shicbba04c2014-01-26 14:21:22 -070044
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040045/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040046 * \brief An unordered collection of out-records.
Junxiao Shicbba04c2014-01-26 14:21:22 -070047 */
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040048using OutRecordCollection = std::list<OutRecord>;
Junxiao Shicbba04c2014-01-26 14:21:22 -070049
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040050/**
51 * \brief Represents an entry in the %Interest table (PIT).
Junxiao Shi4846f372016-04-05 13:39:30 -070052 *
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040053 * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
54 * Each entry contains a collection of in-records, a collection of out-records,
55 * and two timers used in forwarding pipelines.
56 * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
57 * which allows forwarding strategy to store arbitrary information on them.
58 *
59 * \sa Pit
Junxiao Shicbba04c2014-01-26 14:21:22 -070060 */
Junxiao Shi408a7002014-02-12 17:53:47 -070061class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070062{
63public:
64 explicit
65 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070066
Junxiao Shi4846f372016-04-05 13:39:30 -070067 /** \return the representative Interest of the PIT entry
68 * \note Every Interest in in-records and out-records should have same Name and Selectors
69 * as the representative Interest.
70 * \todo #3162 require Link field to match the representative Interest
71 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070072 const Interest&
Junxiao Shi340d5532016-08-13 04:00:35 +000073 getInterest() const
74 {
75 return *m_interest;
76 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070077
78 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070079 */
80 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000081 getName() const
82 {
83 return m_interest->getName();
84 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070085
Junxiao Shia2742922016-11-17 22:53:23 +000086 /** \return whether interest matches this entry
87 * \param interest the Interest
88 * \param nEqualNameComps number of initial name components guaranteed to be equal
89 */
90 bool
91 canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
92
Junxiao Shi4846f372016-04-05 13:39:30 -070093public: // in-record
94 /** \return collection of in-records
95 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070096 const InRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +000097 getInRecords() const
98 {
99 return m_inRecords;
100 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700101
Junxiao Shi4846f372016-04-05 13:39:30 -0700102 /** \retval true There is at least one in-record.
103 * This implies some downstream is waiting for Data or Nack.
104 * \retval false There is no in-record.
105 * This implies the entry is new or has been satisfied or Nacked.
106 */
107 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000108 hasInRecords() const
109 {
110 return !m_inRecords.empty();
111 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700112
113 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000114 in_begin()
115 {
116 return m_inRecords.begin();
117 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700118
119 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000120 in_begin() const
121 {
122 return m_inRecords.begin();
123 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700124
125 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000126 in_end()
127 {
128 return m_inRecords.end();
129 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700130
131 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000132 in_end() const
133 {
134 return m_inRecords.end();
135 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700136
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400137 /** \brief Get the in-record for \p face.
Davide Pesavento50a6af32019-02-21 00:04:40 -0500138 * \return an iterator to the in-record, or in_end() if it does not exist
Junxiao Shi4846f372016-04-05 13:39:30 -0700139 */
140 InRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000141 getInRecord(const Face& face);
Junxiao Shi4846f372016-04-05 13:39:30 -0700142
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400143 /** \brief Insert or update an in-record.
Junxiao Shi4846f372016-04-05 13:39:30 -0700144 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700145 */
146 InRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000147 insertOrUpdateInRecord(Face& face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700148
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400149 /** \brief Delete the in-record for \p face if it exists.
Junxiao Shi66f91f82014-05-10 17:28:58 -0700150 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700151 void
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000152 deleteInRecord(const Face& face);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700153
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400154 /** \brief Delete all in-records.
Junxiao Shi4846f372016-04-05 13:39:30 -0700155 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700156 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700157 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700158
Junxiao Shi4846f372016-04-05 13:39:30 -0700159public: // out-record
160 /** \return collection of in-records
161 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700162 const OutRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +0000163 getOutRecords() const
164 {
165 return m_outRecords;
166 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700167
Junxiao Shi4846f372016-04-05 13:39:30 -0700168 /** \retval true There is at least one out-record.
169 * This implies the Interest has been forwarded to some upstream,
170 * and they haven't returned Data, but may have returned Nacks.
171 * \retval false There is no out-record.
172 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700173 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700174 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000175 hasOutRecords() const
176 {
177 return !m_outRecords.empty();
178 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700179
Junxiao Shi4846f372016-04-05 13:39:30 -0700180 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000181 out_begin()
182 {
183 return m_outRecords.begin();
184 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700185
186 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000187 out_begin() const
188 {
189 return m_outRecords.begin();
190 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700191
192 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000193 out_end()
194 {
195 return m_outRecords.end();
196 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700197
198 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000199 out_end() const
200 {
201 return m_outRecords.end();
202 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700203
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400204 /** \brief Get the out-record for \p face.
Davide Pesavento50a6af32019-02-21 00:04:40 -0500205 * \return an iterator to the out-record, or out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700206 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700207 OutRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000208 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700209
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400210 /** \brief Insert or update an out-record.
Junxiao Shi4846f372016-04-05 13:39:30 -0700211 * \return an iterator to the new or updated out-record
212 */
213 OutRecordCollection::iterator
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000214 insertOrUpdateOutRecord(Face& face, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700215
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400216 /** \brief Delete the out-record for \p face if it exists.
Junxiao Shi4846f372016-04-05 13:39:30 -0700217 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700218 void
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000219 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700220
Junxiao Shid3c792f2014-01-30 00:46:13 -0700221public:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400222 /** \brief Expiry timer.
Junxiao Shi4846f372016-04-05 13:39:30 -0700223 *
224 * This timer is used in forwarding pipelines to delete the entry
Junxiao Shi4846f372016-04-05 13:39:30 -0700225 */
Teng Liang7003e0b2018-03-03 16:03:30 -0700226 scheduler::EventId expiryTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700227
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400228 /** \brief Indicates whether this PIT entry is satisfied.
Teng Liang6f09ab62018-03-01 20:04:08 -0700229 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500230 bool isSatisfied = false;
Teng Liang6f09ab62018-03-01 20:04:08 -0700231
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400232 /** \brief Data freshness period.
Teng Liang6f09ab62018-03-01 20:04:08 -0700233 * \note This field is meaningful only if isSatisfied is true
234 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500235 time::milliseconds dataFreshnessPeriod = 0_ms;
Teng Liang6f09ab62018-03-01 20:04:08 -0700236
Junxiao Shicbba04c2014-01-26 14:21:22 -0700237private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700238 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700239 InRecordCollection m_inRecords;
240 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700241
Davide Pesavento50a6af32019-02-21 00:04:40 -0500242 name_tree::Entry* m_nameTreeEntry = nullptr;
HangZhangcb4fc832014-03-11 16:57:11 +0800243
Davide Pesavento9a28c3f2022-06-11 21:50:01 -0400244 friend ::nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700245};
246
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400247} // namespace nfd::pit
Junxiao Shicbba04c2014-01-26 14:21:22 -0700248
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700249#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP