blob: 2e49824004e1216ed6a5018d60f9becefd605424 [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/*
3 * Copyright (c) 2014-2018, 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
Junxiao Shi4846f372016-04-05 13:39:30 -070043/** \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
Junxiao Shi4846f372016-04-05 13:39:30 -070047/** \brief an unordered collection of out-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 */
49typedef std::list<OutRecord> OutRecordCollection;
50
Junxiao Shi4846f372016-04-05 13:39:30 -070051/** \brief an Interest table entry
52 *
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
135 /** \brief get the in-record for \p face
136 * \return an iterator to the in-record, or .in_end() if it does not exist
137 */
138 InRecordCollection::iterator
139 getInRecord(const Face& face);
140
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
Junxiao Shi9cff7792016-08-01 21:45:11 +0000145 insertOrUpdateInRecord(Face& face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700146
Junxiao Shi4846f372016-04-05 13:39:30 -0700147 /** \brief delete the in-record for \p face if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700148 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700149 void
150 deleteInRecord(const Face& face);
151
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
202 /** \brief get the out-record for \p face
203 * \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
206 getOutRecord(const Face& face);
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
Junxiao Shi9cff7792016-08-01 21:45:11 +0000212 insertOrUpdateOutRecord(Face& face, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700213
214 /** \brief delete the out-record for \p face if it exists
215 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700216 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700217 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700218
Junxiao Shid3c792f2014-01-30 00:46:13 -0700219public:
Teng Liang7003e0b2018-03-03 16:03:30 -0700220 /** \brief expiry timer
Junxiao Shi4846f372016-04-05 13:39:30 -0700221 *
222 * This timer is used in forwarding pipelines to delete the entry
Junxiao Shi4846f372016-04-05 13:39:30 -0700223 */
Teng Liang7003e0b2018-03-03 16:03:30 -0700224 scheduler::EventId expiryTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700225
Teng Liang6f09ab62018-03-01 20:04:08 -0700226 /** \brief indicate if PIT entry is satisfied
227 */
228 bool isSatisfied;
229
230 /** \brief Data freshness period
231 * \note This field is meaningful only if isSatisfied is true
232 */
233 time::milliseconds dataFreshnessPeriod;
234
Junxiao Shicbba04c2014-01-26 14:21:22 -0700235private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700236 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700237 InRecordCollection m_inRecords;
238 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700239
Junxiao Shi340d5532016-08-13 04:00:35 +0000240 name_tree::Entry* m_nameTreeEntry;
HangZhangcb4fc832014-03-11 16:57:11 +0800241
Junxiao Shi340d5532016-08-13 04:00:35 +0000242 friend class name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700243};
244
Junxiao Shicbba04c2014-01-26 14:21:22 -0700245} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800246} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700247
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700248#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP