blob: e432c4e9a920aad9728a18a088799abae51fb77c [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
35class NameTree;
36
37namespace name_tree {
38class Entry;
Junxiao Shifef73e42016-03-29 14:15:05 -070039} // namespace name_tree
HangZhangcb4fc832014-03-11 16:57:11 +080040
spirosmastorakisff920302016-05-26 18:09:31 +000041class Pit;
42
Junxiao Shicbba04c2014-01-26 14:21:22 -070043namespace pit {
44
Junxiao Shi4846f372016-04-05 13:39:30 -070045/** \brief an unordered collection of in-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 */
Junxiao Shi4846f372016-04-05 13:39:30 -070047typedef std::list<InRecord> InRecordCollection;
Junxiao Shicbba04c2014-01-26 14:21:22 -070048
Junxiao Shi4846f372016-04-05 13:39:30 -070049/** \brief an unordered collection of out-records
Junxiao Shicbba04c2014-01-26 14:21:22 -070050 */
51typedef std::list<OutRecord> OutRecordCollection;
52
Junxiao Shi4846f372016-04-05 13:39:30 -070053/** \brief an Interest table entry
54 *
55 * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
56 * Each entry contains a collection of in-records, a collection of out-records,
57 * and two timers used in forwarding pipelines.
58 * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
59 * which allows forwarding strategy to store arbitrary information on them.
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&
73 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070074
75 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070076 */
77 const Name&
78 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070079
Junxiao Shi4846f372016-04-05 13:39:30 -070080public: // in-record
81 /** \return collection of in-records
82 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070083 const InRecordCollection&
84 getInRecords() const;
85
Junxiao Shi4846f372016-04-05 13:39:30 -070086 /** \retval true There is at least one in-record.
87 * This implies some downstream is waiting for Data or Nack.
88 * \retval false There is no in-record.
89 * This implies the entry is new or has been satisfied or Nacked.
90 */
91 bool
92 hasInRecords() const;
93
94 InRecordCollection::iterator
95 in_begin();
96
97 InRecordCollection::const_iterator
98 in_begin() const;
99
100 InRecordCollection::iterator
101 in_end();
102
103 InRecordCollection::const_iterator
104 in_end() const;
105
106 /** \brief get the in-record for \p face
107 * \return an iterator to the in-record, or .in_end() if it does not exist
108 */
109 InRecordCollection::iterator
110 getInRecord(const Face& face);
111
112 /** \brief insert or update an in-record
113 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700114 */
115 InRecordCollection::iterator
116 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700117
Junxiao Shi4846f372016-04-05 13:39:30 -0700118 /** \brief delete the in-record for \p face if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700119 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700120 void
121 deleteInRecord(const Face& face);
122
Junxiao Shi4846f372016-04-05 13:39:30 -0700123 /** \brief delete all in-records
124 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700125 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700126 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700127
Junxiao Shi4846f372016-04-05 13:39:30 -0700128public: // out-record
129 /** \return collection of in-records
130 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700131 const OutRecordCollection&
132 getOutRecords() const;
133
Junxiao Shi4846f372016-04-05 13:39:30 -0700134 /** \retval true There is at least one out-record.
135 * This implies the Interest has been forwarded to some upstream,
136 * and they haven't returned Data, but may have returned Nacks.
137 * \retval false There is no out-record.
138 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700139 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700140 bool
141 hasOutRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700142
Junxiao Shi4846f372016-04-05 13:39:30 -0700143 OutRecordCollection::iterator
144 out_begin();
145
146 OutRecordCollection::const_iterator
147 out_begin() const;
148
149 OutRecordCollection::iterator
150 out_end();
151
152 OutRecordCollection::const_iterator
153 out_end() const;
154
155 /** \brief get the out-record for \p face
156 * \return an iterator to the out-record, or .out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700157 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700158 OutRecordCollection::iterator
159 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700160
Junxiao Shi4846f372016-04-05 13:39:30 -0700161 /** \brief insert or update an out-record
162 * \return an iterator to the new or updated out-record
163 */
164 OutRecordCollection::iterator
165 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
166
167 /** \brief delete the out-record for \p face if it exists
168 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700169 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700170 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700171
Junxiao Shid3c792f2014-01-30 00:46:13 -0700172public:
Junxiao Shi4846f372016-04-05 13:39:30 -0700173 /** \brief unsatisfy timer
174 *
175 * This timer is used in forwarding pipelines to delete the entry
176 * when it expires without being satisfied.
177 * It fires when the last InterestLifetime among in-records expires.
178 *
179 * Either this or the straggler timer should be set at all times,
180 * except when this entry is being processed in a pipeline.
181 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700182 scheduler::EventId m_unsatisfyTimer;
Junxiao Shi4846f372016-04-05 13:39:30 -0700183
184 /** \brief straggler timer
185 *
186 * This timer is used in forwarding pipelines to delete the entry when it has been satisfied
187 * and is no longer needed for measurement collection purpose.
188 *
189 * Either this or the unsatisfy timer should be set at all times,
190 * except when this entry is being processed in a pipeline.
191 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700192 scheduler::EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700193
194private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700195 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700196 InRecordCollection m_inRecords;
197 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700198
HangZhangcb4fc832014-03-11 16:57:11 +0800199 shared_ptr<name_tree::Entry> m_nameTreeEntry;
200
201 friend class nfd::NameTree;
202 friend class nfd::name_tree::Entry;
spirosmastorakisff920302016-05-26 18:09:31 +0000203 friend class nfd::Pit;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700204};
205
206inline const Interest&
207Entry::getInterest() const
208{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700209 return *m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700210}
211
Junxiao Shi4846f372016-04-05 13:39:30 -0700212inline const Name&
213Entry::getName() const
214{
215 return m_interest->getName();
216}
217
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700218inline const InRecordCollection&
219Entry::getInRecords() const
220{
221 return m_inRecords;
222}
223
Junxiao Shi4846f372016-04-05 13:39:30 -0700224inline bool
225Entry::hasInRecords() const
226{
227 return !m_inRecords.empty();
228}
229
230inline InRecordCollection::iterator
231Entry::in_begin()
232{
233 return m_inRecords.begin();
234}
235
236inline InRecordCollection::const_iterator
237Entry::in_begin() const
238{
239 return m_inRecords.begin();
240}
241
242inline InRecordCollection::iterator
243Entry::in_end()
244{
245 return m_inRecords.end();
246}
247
248inline InRecordCollection::const_iterator
249Entry::in_end() const
250{
251 return m_inRecords.end();
252}
253
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700254inline const OutRecordCollection&
255Entry::getOutRecords() const
256{
257 return m_outRecords;
258}
259
Junxiao Shi4846f372016-04-05 13:39:30 -0700260inline bool
261Entry::hasOutRecords() const
262{
263 return !m_outRecords.empty();
264}
265
266inline OutRecordCollection::iterator
267Entry::out_begin()
268{
269 return m_outRecords.begin();
270}
271
272inline OutRecordCollection::const_iterator
273Entry::out_begin() const
274{
275 return m_outRecords.begin();
276}
277
278inline OutRecordCollection::iterator
279Entry::out_end()
280{
281 return m_outRecords.end();
282}
283
284inline OutRecordCollection::const_iterator
285Entry::out_end() const
286{
287 return m_outRecords.end();
288}
289
Junxiao Shicbba04c2014-01-26 14:21:22 -0700290} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800291} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700292
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700293#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP