blob: 31a2f048fac9508768eed9304a450203741b7120 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifef73e42016-03-29 14:15:05 -07003 * Copyright (c) 2014-2016, 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
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080034
HangZhangcb4fc832014-03-11 16:57:11 +080035namespace name_tree {
36class Entry;
Junxiao Shifef73e42016-03-29 14:15:05 -070037} // namespace name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080038
Junxiao Shicbba04c2014-01-26 14:21:22 -070039namespace pit {
40
Junxiao Shi4846f372016-04-05 13:39:30 -070041/** \brief an unordered collection of in-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070042 */
Junxiao Shi4846f372016-04-05 13:39:30 -070043typedef std::list<InRecord> InRecordCollection;
Junxiao Shicbba04c2014-01-26 14:21:22 -070044
Junxiao Shi4846f372016-04-05 13:39:30 -070045/** \brief an unordered collection of out-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 */
47typedef std::list<OutRecord> OutRecordCollection;
48
Junxiao Shi4846f372016-04-05 13:39:30 -070049/** \brief an Interest table entry
50 *
51 * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
52 * Each entry contains a collection of in-records, a collection of out-records,
53 * and two timers used in forwarding pipelines.
54 * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
55 * which allows forwarding strategy to store arbitrary information on them.
Junxiao Shicbba04c2014-01-26 14:21:22 -070056 */
Junxiao Shi408a7002014-02-12 17:53:47 -070057class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070058{
59public:
60 explicit
61 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070062
Junxiao Shi4846f372016-04-05 13:39:30 -070063 /** \return the representative Interest of the PIT entry
64 * \note Every Interest in in-records and out-records should have same Name and Selectors
65 * as the representative Interest.
66 * \todo #3162 require Link field to match the representative Interest
67 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070068 const Interest&
Junxiao Shi340d5532016-08-13 04:00:35 +000069 getInterest() const
70 {
71 return *m_interest;
72 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070073
74 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070075 */
76 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000077 getName() const
78 {
79 return m_interest->getName();
80 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070081
Junxiao Shia2742922016-11-17 22:53:23 +000082 /** \return whether interest matches this entry
83 * \param interest the Interest
84 * \param nEqualNameComps number of initial name components guaranteed to be equal
85 */
86 bool
87 canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
88
Junxiao Shi4846f372016-04-05 13:39:30 -070089public: // in-record
90 /** \return collection of in-records
91 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070092 const InRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +000093 getInRecords() const
94 {
95 return m_inRecords;
96 }
Junxiao Shi66f91f82014-05-10 17:28:58 -070097
Junxiao Shi4846f372016-04-05 13:39:30 -070098 /** \retval true There is at least one in-record.
99 * This implies some downstream is waiting for Data or Nack.
100 * \retval false There is no in-record.
101 * This implies the entry is new or has been satisfied or Nacked.
102 */
103 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000104 hasInRecords() const
105 {
106 return !m_inRecords.empty();
107 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700108
109 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000110 in_begin()
111 {
112 return m_inRecords.begin();
113 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700114
115 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000116 in_begin() const
117 {
118 return m_inRecords.begin();
119 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700120
121 InRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000122 in_end()
123 {
124 return m_inRecords.end();
125 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700126
127 InRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000128 in_end() const
129 {
130 return m_inRecords.end();
131 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700132
133 /** \brief get the in-record for \p face
134 * \return an iterator to the in-record, or .in_end() if it does not exist
135 */
136 InRecordCollection::iterator
137 getInRecord(const Face& face);
138
139 /** \brief insert or update an in-record
140 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700141 */
142 InRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +0000143 insertOrUpdateInRecord(Face& face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700144
Junxiao Shi4846f372016-04-05 13:39:30 -0700145 /** \brief delete the in-record for \p face if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700146 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700147 void
148 deleteInRecord(const Face& face);
149
Junxiao Shi4846f372016-04-05 13:39:30 -0700150 /** \brief delete all in-records
151 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700152 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700153 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700154
Junxiao Shi4846f372016-04-05 13:39:30 -0700155public: // out-record
156 /** \return collection of in-records
157 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700158 const OutRecordCollection&
Junxiao Shi340d5532016-08-13 04:00:35 +0000159 getOutRecords() const
160 {
161 return m_outRecords;
162 }
Junxiao Shi66f91f82014-05-10 17:28:58 -0700163
Junxiao Shi4846f372016-04-05 13:39:30 -0700164 /** \retval true There is at least one out-record.
165 * This implies the Interest has been forwarded to some upstream,
166 * and they haven't returned Data, but may have returned Nacks.
167 * \retval false There is no out-record.
168 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700169 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700170 bool
Junxiao Shi340d5532016-08-13 04:00:35 +0000171 hasOutRecords() const
172 {
173 return !m_outRecords.empty();
174 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700175
Junxiao Shi4846f372016-04-05 13:39:30 -0700176 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000177 out_begin()
178 {
179 return m_outRecords.begin();
180 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700181
182 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000183 out_begin() const
184 {
185 return m_outRecords.begin();
186 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700187
188 OutRecordCollection::iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000189 out_end()
190 {
191 return m_outRecords.end();
192 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700193
194 OutRecordCollection::const_iterator
Junxiao Shi340d5532016-08-13 04:00:35 +0000195 out_end() const
196 {
197 return m_outRecords.end();
198 }
Junxiao Shi4846f372016-04-05 13:39:30 -0700199
200 /** \brief get the out-record for \p face
201 * \return an iterator to the out-record, or .out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700202 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700203 OutRecordCollection::iterator
204 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700205
Junxiao Shi4846f372016-04-05 13:39:30 -0700206 /** \brief insert or update an out-record
207 * \return an iterator to the new or updated out-record
208 */
209 OutRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +0000210 insertOrUpdateOutRecord(Face& face, const Interest& interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700211
212 /** \brief delete the out-record for \p face if it exists
213 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700214 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700215 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700216
Junxiao Shid3c792f2014-01-30 00:46:13 -0700217public:
Junxiao Shi4846f372016-04-05 13:39:30 -0700218 /** \brief unsatisfy timer
219 *
220 * This timer is used in forwarding pipelines to delete the entry
221 * when it expires without being satisfied.
222 * It fires when the last InterestLifetime among in-records expires.
223 *
224 * Either this or the straggler timer should be set at all times,
225 * except when this entry is being processed in a pipeline.
226 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700227 scheduler::EventId m_unsatisfyTimer;
Junxiao Shi4846f372016-04-05 13:39:30 -0700228
229 /** \brief straggler timer
230 *
231 * This timer is used in forwarding pipelines to delete the entry when it has been satisfied
232 * and is no longer needed for measurement collection purpose.
233 *
234 * Either this or the unsatisfy timer should be set at all times,
235 * except when this entry is being processed in a pipeline.
236 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700237 scheduler::EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700238
239private:
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
Junxiao Shi340d5532016-08-13 04:00:35 +0000244 name_tree::Entry* m_nameTreeEntry;
HangZhangcb4fc832014-03-11 16:57:11 +0800245
Junxiao Shi340d5532016-08-13 04:00:35 +0000246 friend class name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700247};
248
Junxiao Shicbba04c2014-01-26 14:21:22 -0700249} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800250} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700251
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700252#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP