blob: 42334f0f870f544fc25b64e0461511eaf58772fc [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/*
ashiqopud3ae85d2019-02-17 02:29:55 +00003 * Copyright (c) 2014-2019, 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"
Junxiao Shid3c792f2014-01-30 00:46:13 -070031#include "core/scheduler.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070032
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040033#include <list>
34
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080035namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080036
HangZhangcb4fc832014-03-11 16:57:11 +080037namespace name_tree {
38class Entry;
Junxiao Shifef73e42016-03-29 14:15:05 -070039} // namespace name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080040
Junxiao Shicbba04c2014-01-26 14:21:22 -070041namespace pit {
42
Davide Pesavento50a6af32019-02-21 00:04:40 -050043/** \brief An unordered collection of in-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070044 */
Junxiao Shi4846f372016-04-05 13:39:30 -070045typedef std::list<InRecord> InRecordCollection;
Junxiao Shicbba04c2014-01-26 14:21:22 -070046
Davide Pesavento50a6af32019-02-21 00:04:40 -050047/** \brief An unordered collection of out-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 */
49typedef std::list<OutRecord> OutRecordCollection;
50
Davide Pesavento50a6af32019-02-21 00:04:40 -050051/** \brief An Interest table entry
Junxiao Shi4846f372016-04-05 13:39:30 -070052 *
53 * 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.
Junxiao Shicbba04c2014-01-26 14:21:22 -070058 */
Junxiao Shi408a7002014-02-12 17:53:47 -070059class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070060{
61public:
62 explicit
63 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070064
Junxiao Shi4846f372016-04-05 13:39:30 -070065 /** \return the representative Interest of the PIT entry
66 * \note Every Interest in in-records and out-records should have same Name and Selectors
67 * as the representative Interest.
68 * \todo #3162 require Link field to match the representative Interest
69 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070070 const Interest&
Junxiao Shi340d5532016-08-13 04:00:35 +000071 getInterest() const
72 {
73 return *m_interest;
74 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070075
76 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070077 */
78 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000079 getName() const
80 {
81 return m_interest->getName();
82 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070083
Junxiao Shia2742922016-11-17 22:53:23 +000084 /** \return whether interest matches this entry
85 * \param interest the Interest
86 * \param nEqualNameComps number of initial name components guaranteed to be equal
87 */
88 bool
89 canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
90
Junxiao Shi4846f372016-04-05 13:39:30 -070091public: // in-record
92 /** \return collection of in-records
93 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070094 const InRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +000095 getInRecords() const
96 {
97 return m_inRecords;
98 }
Junxiao Shi66f91f82014-05-10 17:28:58 -070099
Junxiao Shi4846f372016-04-05 13:39:30 -0700100 /** \retval true There is at least one in-record.
101 * This implies some downstream is waiting for Data or Nack.
102 * \retval false There is no in-record.
103 * This implies the entry is new or has been satisfied or Nacked.
104 */
105 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000106 hasInRecords() const
107 {
108 return !m_inRecords.empty();
109 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700110
111 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000112 in_begin()
113 {
114 return m_inRecords.begin();
115 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700116
117 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000118 in_begin() const
119 {
120 return m_inRecords.begin();
121 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700122
123 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000124 in_end()
125 {
126 return m_inRecords.end();
127 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700128
129 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000130 in_end() const
131 {
132 return m_inRecords.end();
133 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700134
ashiqopud3ae85d2019-02-17 02:29:55 +0000135 /** \brief get the in-record for \p face and \p endpointId
Davide Pesavento50a6af32019-02-21 00:04:40 -0500136 * \return an iterator to the in-record, or in_end() if it does not exist
Junxiao Shi4846f372016-04-05 13:39:30 -0700137 */
138 InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000139 getInRecord(const Face& face, EndpointId endpointId);
Junxiao Shi4846f372016-04-05 13:39:30 -0700140
141 /** \brief insert or update an in-record
142 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700143 */
144 InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000145 insertOrUpdateInRecord(Face& face, EndpointId endpointId, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700146
ashiqopud3ae85d2019-02-17 02:29:55 +0000147 /** \brief delete the in-record for \p face and \p endpointId if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700148 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700149 void
ashiqopu77d0bfd2019-02-20 20:37:31 +0000150 deleteInRecord(const Face& face, EndpointId endpointId);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700151
Junxiao Shi4846f372016-04-05 13:39:30 -0700152 /** \brief delete all in-records
153 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700154 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700155 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700156
Junxiao Shi4846f372016-04-05 13:39:30 -0700157public: // out-record
158 /** \return collection of in-records
159 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700160 const OutRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +0000161 getOutRecords() const
162 {
163 return m_outRecords;
164 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700165
Junxiao Shi4846f372016-04-05 13:39:30 -0700166 /** \retval true There is at least one out-record.
167 * This implies the Interest has been forwarded to some upstream,
168 * and they haven't returned Data, but may have returned Nacks.
169 * \retval false There is no out-record.
170 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700171 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700172 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000173 hasOutRecords() const
174 {
175 return !m_outRecords.empty();
176 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700177
Junxiao Shi4846f372016-04-05 13:39:30 -0700178 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000179 out_begin()
180 {
181 return m_outRecords.begin();
182 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700183
184 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000185 out_begin() const
186 {
187 return m_outRecords.begin();
188 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700189
190 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000191 out_end()
192 {
193 return m_outRecords.end();
194 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700195
196 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000197 out_end() const
198 {
199 return m_outRecords.end();
200 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700201
ashiqopud3ae85d2019-02-17 02:29:55 +0000202 /** \brief get the out-record for \p face and \p endpointId
Davide Pesavento50a6af32019-02-21 00:04:40 -0500203 * \return an iterator to the out-record, or out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700204 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700205 OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000206 getOutRecord(const Face& face, EndpointId endpointId);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700207
Junxiao Shi4846f372016-04-05 13:39:30 -0700208 /** \brief insert or update an out-record
209 * \return an iterator to the new or updated out-record
210 */
211 OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000212 insertOrUpdateOutRecord(Face& face, EndpointId endpointId, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700213
ashiqopud3ae85d2019-02-17 02:29:55 +0000214 /** \brief delete the out-record for \p face and \p endpointId if it exists
Junxiao Shi4846f372016-04-05 13:39:30 -0700215 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700216 void
ashiqopu77d0bfd2019-02-20 20:37:31 +0000217 deleteOutRecord(const Face& face, EndpointId endpointId);
ashiqopud3ae85d2019-02-17 02:29:55 +0000218
219public: // cleanup
220 /** \brief delete all in-records and out-records for \p face if it exists
221 */
222 void
223 deleteInOutRecordsByFace(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700224
Junxiao Shid3c792f2014-01-30 00:46:13 -0700225public:
Davide Pesavento50a6af32019-02-21 00:04:40 -0500226 /** \brief Expiry timer
Junxiao Shi4846f372016-04-05 13:39:30 -0700227 *
228 * This timer is used in forwarding pipelines to delete the entry
Junxiao Shi4846f372016-04-05 13:39:30 -0700229 */
Teng Liang7003e0b2018-03-03 16:03:30 -0700230 scheduler::EventId expiryTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700231
Davide Pesavento50a6af32019-02-21 00:04:40 -0500232 /** \brief Indicates whether this PIT entry is satisfied
Teng Liang6f09ab62018-03-01 20:04:08 -0700233 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500234 bool isSatisfied = false;
Teng Liang6f09ab62018-03-01 20:04:08 -0700235
236 /** \brief Data freshness period
237 * \note This field is meaningful only if isSatisfied is true
238 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500239 time::milliseconds dataFreshnessPeriod = 0_ms;
Teng Liang6f09ab62018-03-01 20:04:08 -0700240
Junxiao Shicbba04c2014-01-26 14:21:22 -0700241private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700242 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700243 InRecordCollection m_inRecords;
244 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700245
Davide Pesavento50a6af32019-02-21 00:04:40 -0500246 name_tree::Entry* m_nameTreeEntry = nullptr;
HangZhangcb4fc832014-03-11 16:57:11 +0800247
Junxiao Shi340d5532016-08-13 04:00:35 +0000248 friend class name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700249};
250
Junxiao Shicbba04c2014-01-26 14:21:22 -0700251} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800252} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700253
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700254#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP