blob: 282d1df4bcbfde55525454c3352eef37ecfba413 [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
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&
71 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070072
73 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070074 */
75 const Name&
76 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070077
Junxiao Shi4846f372016-04-05 13:39:30 -070078public: // in-record
79 /** \return collection of in-records
80 */
Junxiao Shi66f91f82014-05-10 17:28:58 -070081 const InRecordCollection&
82 getInRecords() const;
83
Junxiao Shi4846f372016-04-05 13:39:30 -070084 /** \retval true There is at least one in-record.
85 * This implies some downstream is waiting for Data or Nack.
86 * \retval false There is no in-record.
87 * This implies the entry is new or has been satisfied or Nacked.
88 */
89 bool
90 hasInRecords() const;
91
92 InRecordCollection::iterator
93 in_begin();
94
95 InRecordCollection::const_iterator
96 in_begin() const;
97
98 InRecordCollection::iterator
99 in_end();
100
101 InRecordCollection::const_iterator
102 in_end() const;
103
104 /** \brief get the in-record for \p face
105 * \return an iterator to the in-record, or .in_end() if it does not exist
106 */
107 InRecordCollection::iterator
108 getInRecord(const Face& face);
109
110 /** \brief insert or update an in-record
111 * \return an iterator to the new or updated in-record
Junxiao Shicbba04c2014-01-26 14:21:22 -0700112 */
113 InRecordCollection::iterator
114 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700115
Junxiao Shi4846f372016-04-05 13:39:30 -0700116 /** \brief delete the in-record for \p face if it exists
Junxiao Shi66f91f82014-05-10 17:28:58 -0700117 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700118 void
119 deleteInRecord(const Face& face);
120
Junxiao Shi4846f372016-04-05 13:39:30 -0700121 /** \brief delete all in-records
122 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700123 void
Junxiao Shi4846f372016-04-05 13:39:30 -0700124 clearInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700125
Junxiao Shi4846f372016-04-05 13:39:30 -0700126public: // out-record
127 /** \return collection of in-records
128 */
Junxiao Shi66f91f82014-05-10 17:28:58 -0700129 const OutRecordCollection&
130 getOutRecords() const;
131
Junxiao Shi4846f372016-04-05 13:39:30 -0700132 /** \retval true There is at least one out-record.
133 * This implies the Interest has been forwarded to some upstream,
134 * and they haven't returned Data, but may have returned Nacks.
135 * \retval false There is no out-record.
136 * This implies the Interest has not been forwarded.
Junxiao Shicbba04c2014-01-26 14:21:22 -0700137 */
Junxiao Shi4846f372016-04-05 13:39:30 -0700138 bool
139 hasOutRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700140
Junxiao Shi4846f372016-04-05 13:39:30 -0700141 OutRecordCollection::iterator
142 out_begin();
143
144 OutRecordCollection::const_iterator
145 out_begin() const;
146
147 OutRecordCollection::iterator
148 out_end();
149
150 OutRecordCollection::const_iterator
151 out_end() const;
152
153 /** \brief get the out-record for \p face
154 * \return an iterator to the out-record, or .out_end() if it does not exist
Junxiao Shi66f91f82014-05-10 17:28:58 -0700155 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700156 OutRecordCollection::iterator
157 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700158
Junxiao Shi4846f372016-04-05 13:39:30 -0700159 /** \brief insert or update an out-record
160 * \return an iterator to the new or updated out-record
161 */
162 OutRecordCollection::iterator
163 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
164
165 /** \brief delete the out-record for \p face if it exists
166 */
Junxiao Shicbba04c2014-01-26 14:21:22 -0700167 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700168 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700169
Junxiao Shid3c792f2014-01-30 00:46:13 -0700170public:
Junxiao Shi4846f372016-04-05 13:39:30 -0700171 /** \brief unsatisfy timer
172 *
173 * This timer is used in forwarding pipelines to delete the entry
174 * when it expires without being satisfied.
175 * It fires when the last InterestLifetime among in-records expires.
176 *
177 * Either this or the straggler timer should be set at all times,
178 * except when this entry is being processed in a pipeline.
179 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700180 scheduler::EventId m_unsatisfyTimer;
Junxiao Shi4846f372016-04-05 13:39:30 -0700181
182 /** \brief straggler timer
183 *
184 * This timer is used in forwarding pipelines to delete the entry when it has been satisfied
185 * and is no longer needed for measurement collection purpose.
186 *
187 * Either this or the unsatisfy timer should be set at all times,
188 * except when this entry is being processed in a pipeline.
189 */
Junxiao Shi1e46be32015-01-08 20:18:05 -0700190 scheduler::EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700191
192private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700193 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700194 InRecordCollection m_inRecords;
195 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700196
Junxiao Shib184e532016-05-26 18:09:57 +0000197 weak_ptr<name_tree::Entry> m_nameTreeEntry;
HangZhangcb4fc832014-03-11 16:57:11 +0800198
199 friend class nfd::NameTree;
200 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700201};
202
203inline const Interest&
204Entry::getInterest() const
205{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700206 return *m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700207}
208
Junxiao Shi4846f372016-04-05 13:39:30 -0700209inline const Name&
210Entry::getName() const
211{
212 return m_interest->getName();
213}
214
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700215inline const InRecordCollection&
216Entry::getInRecords() const
217{
218 return m_inRecords;
219}
220
Junxiao Shi4846f372016-04-05 13:39:30 -0700221inline bool
222Entry::hasInRecords() const
223{
224 return !m_inRecords.empty();
225}
226
227inline InRecordCollection::iterator
228Entry::in_begin()
229{
230 return m_inRecords.begin();
231}
232
233inline InRecordCollection::const_iterator
234Entry::in_begin() const
235{
236 return m_inRecords.begin();
237}
238
239inline InRecordCollection::iterator
240Entry::in_end()
241{
242 return m_inRecords.end();
243}
244
245inline InRecordCollection::const_iterator
246Entry::in_end() const
247{
248 return m_inRecords.end();
249}
250
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700251inline const OutRecordCollection&
252Entry::getOutRecords() const
253{
254 return m_outRecords;
255}
256
Junxiao Shi4846f372016-04-05 13:39:30 -0700257inline bool
258Entry::hasOutRecords() const
259{
260 return !m_outRecords.empty();
261}
262
263inline OutRecordCollection::iterator
264Entry::out_begin()
265{
266 return m_outRecords.begin();
267}
268
269inline OutRecordCollection::const_iterator
270Entry::out_begin() const
271{
272 return m_outRecords.begin();
273}
274
275inline OutRecordCollection::iterator
276Entry::out_end()
277{
278 return m_outRecords.end();
279}
280
281inline OutRecordCollection::const_iterator
282Entry::out_end() const
283{
284 return m_outRecords.end();
285}
286
Junxiao Shicbba04c2014-01-26 14:21:22 -0700287} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800288} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700289
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700290#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP