blob: 8100b8ee81c85dad0b338e00385448c97c19f6e9 [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"
31
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040032#include <list>
33
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080035
HangZhangcb4fc832014-03-11 16:57:11 +080036namespace name_tree {
37class Entry;
Junxiao Shifef73e42016-03-29 14:15:05 -070038} // namespace name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080039
Junxiao Shicbba04c2014-01-26 14:21:22 -070040namespace pit {
41
Davide Pesavento50a6af32019-02-21 00:04:40 -050042/** \brief An unordered collection of in-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070043 */
Junxiao Shi4846f372016-04-05 13:39:30 -070044typedef std::list<InRecord> InRecordCollection;
Junxiao Shicbba04c2014-01-26 14:21:22 -070045
Davide Pesavento50a6af32019-02-21 00:04:40 -050046/** \brief An unordered collection of out-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070047 */
48typedef std::list<OutRecord> OutRecordCollection;
49
Davide Pesavento50a6af32019-02-21 00:04:40 -050050/** \brief An Interest table entry
Junxiao Shi4846f372016-04-05 13:39:30 -070051 *
52 * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
53 * Each entry contains a collection of in-records, a collection of out-records,
54 * and two timers used in forwarding pipelines.
55 * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
56 * which allows forwarding strategy to store arbitrary information on them.
Junxiao Shicbba04c2014-01-26 14:21:22 -070057 */
Junxiao Shi408a7002014-02-12 17:53:47 -070058class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070059{
60public:
61 explicit
62 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070063
Junxiao Shi4846f372016-04-05 13:39:30 -070064 /** \return the representative Interest of the PIT entry
65 * \note Every Interest in in-records and out-records should have same Name and Selectors
66 * as the representative Interest.
67 * \todo #3162 require Link field to match the representative Interest
68 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070069 const Interest&
Junxiao Shi340d5532016-08-13 04:00:35 +000070 getInterest() const
71 {
72 return *m_interest;
73 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070074
75 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070076 */
77 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000078 getName() const
79 {
80 return m_interest->getName();
81 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070082
Junxiao Shia2742922016-11-17 22:53:23 +000083 /** \return whether interest matches this entry
84 * \param interest the Interest
85 * \param nEqualNameComps number of initial name components guaranteed to be equal
86 */
87 bool
88 canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
89
Junxiao Shi4846f372016-04-05 13:39:30 -070090public: // in-record
91 /** \return collection of in-records
92 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070093 const InRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +000094 getInRecords() const
95 {
96 return m_inRecords;
97 }
Junxiao Shi66f91f82014-05-10 17:28:58 -070098
Junxiao Shi4846f372016-04-05 13:39:30 -070099 /** \retval true There is at least one in-record.
100 * This implies some downstream is waiting for Data or Nack.
101 * \retval false There is no in-record.
102 * This implies the entry is new or has been satisfied or Nacked.
103 */
104 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000105 hasInRecords() const
106 {
107 return !m_inRecords.empty();
108 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700109
110 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000111 in_begin()
112 {
113 return m_inRecords.begin();
114 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700115
116 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000117 in_begin() const
118 {
119 return m_inRecords.begin();
120 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700121
122 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000123 in_end()
124 {
125 return m_inRecords.end();
126 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700127
128 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000129 in_end() const
130 {
131 return m_inRecords.end();
132 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700133
ashiqopud3ae85d2019-02-17 02:29:55 +0000134 /** \brief get the in-record for \p face and \p endpointId
Davide Pesavento50a6af32019-02-21 00:04:40 -0500135 * \return an iterator to the in-record, or in_end() if it does not exist
Junxiao Shi4846f372016-04-05 13:39:30 -0700136 */
137 InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000138 getInRecord(const Face& face, EndpointId endpointId);
Junxiao Shi4846f372016-04-05 13:39:30 -0700139
140 /** \brief insert or update an in-record
141 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700142 */
143 InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000144 insertOrUpdateInRecord(Face& face, EndpointId endpointId, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700145
ashiqopud3ae85d2019-02-17 02:29:55 +0000146 /** \brief delete the in-record for \p face and \p endpointId if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700147 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700148 void
ashiqopu77d0bfd2019-02-20 20:37:31 +0000149 deleteInRecord(const Face& face, EndpointId endpointId);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700150
Junxiao Shi4846f372016-04-05 13:39:30 -0700151 /** \brief delete all in-records
152 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700153 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700154 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700155
Junxiao Shi4846f372016-04-05 13:39:30 -0700156public: // out-record
157 /** \return collection of in-records
158 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700159 const OutRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +0000160 getOutRecords() const
161 {
162 return m_outRecords;
163 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700164
Junxiao Shi4846f372016-04-05 13:39:30 -0700165 /** \retval true There is at least one out-record.
166 * This implies the Interest has been forwarded to some upstream,
167 * and they haven't returned Data, but may have returned Nacks.
168 * \retval false There is no out-record.
169 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700170 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700171 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000172 hasOutRecords() const
173 {
174 return !m_outRecords.empty();
175 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700176
Junxiao Shi4846f372016-04-05 13:39:30 -0700177 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000178 out_begin()
179 {
180 return m_outRecords.begin();
181 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700182
183 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000184 out_begin() const
185 {
186 return m_outRecords.begin();
187 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700188
189 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000190 out_end()
191 {
192 return m_outRecords.end();
193 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700194
195 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000196 out_end() const
197 {
198 return m_outRecords.end();
199 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700200
ashiqopud3ae85d2019-02-17 02:29:55 +0000201 /** \brief get the out-record for \p face and \p endpointId
Davide Pesavento50a6af32019-02-21 00:04:40 -0500202 * \return an iterator to the out-record, or out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700203 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700204 OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000205 getOutRecord(const Face& face, EndpointId endpointId);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700206
Junxiao Shi4846f372016-04-05 13:39:30 -0700207 /** \brief insert or update an out-record
208 * \return an iterator to the new or updated out-record
209 */
210 OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000211 insertOrUpdateOutRecord(Face& face, EndpointId endpointId, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700212
ashiqopud3ae85d2019-02-17 02:29:55 +0000213 /** \brief delete the out-record for \p face and \p endpointId if it exists
Junxiao Shi4846f372016-04-05 13:39:30 -0700214 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700215 void
ashiqopu77d0bfd2019-02-20 20:37:31 +0000216 deleteOutRecord(const Face& face, EndpointId endpointId);
ashiqopud3ae85d2019-02-17 02:29:55 +0000217
218public: // cleanup
219 /** \brief delete all in-records and out-records for \p face if it exists
220 */
221 void
222 deleteInOutRecordsByFace(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700223
Junxiao Shid3c792f2014-01-30 00:46:13 -0700224public:
Davide Pesavento50a6af32019-02-21 00:04:40 -0500225 /** \brief Expiry timer
Junxiao Shi4846f372016-04-05 13:39:30 -0700226 *
227 * This timer is used in forwarding pipelines to delete the entry
Junxiao Shi4846f372016-04-05 13:39:30 -0700228 */
Teng Liang7003e0b2018-03-03 16:03:30 -0700229 scheduler::EventId expiryTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700230
Davide Pesavento50a6af32019-02-21 00:04:40 -0500231 /** \brief Indicates whether this PIT entry is satisfied
Teng Liang6f09ab62018-03-01 20:04:08 -0700232 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500233 bool isSatisfied = false;
Teng Liang6f09ab62018-03-01 20:04:08 -0700234
235 /** \brief Data freshness period
236 * \note This field is meaningful only if isSatisfied is true
237 */
Davide Pesavento50a6af32019-02-21 00:04:40 -0500238 time::milliseconds dataFreshnessPeriod = 0_ms;
Teng Liang6f09ab62018-03-01 20:04:08 -0700239
Junxiao Shicbba04c2014-01-26 14:21:22 -0700240private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700241 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700242 InRecordCollection m_inRecords;
243 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700244
Davide Pesavento50a6af32019-02-21 00:04:40 -0500245 name_tree::Entry* m_nameTreeEntry = nullptr;
HangZhangcb4fc832014-03-11 16:57:11 +0800246
Junxiao Shi340d5532016-08-13 04:00:35 +0000247 friend class name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700248};
249
Junxiao Shicbba04c2014-01-26 14:21:22 -0700250} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800251} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700252
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700253#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP