blob: 420bb29f5718d947d637dd7e479e762bed4a40ad [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev28d586a2014-07-10 20:10:54 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * 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
Junxiao Shi651b75e2014-07-17 20:15:09 -070029#include "pit-nonce-list.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070030#include "pit-in-record.hpp"
31#include "pit-out-record.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070032#include "core/scheduler.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070033
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080035
36class NameTree;
37
38namespace name_tree {
39class Entry;
40}
41
Junxiao Shicbba04c2014-01-26 14:21:22 -070042namespace pit {
43
Junxiao Shi66f91f82014-05-10 17:28:58 -070044/** \brief represents an unordered collection of InRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070045 */
46typedef std::list< InRecord> InRecordCollection;
47
Junxiao Shi66f91f82014-05-10 17:28:58 -070048/** \brief represents an unordered collection of OutRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070049 */
50typedef std::list<OutRecord> OutRecordCollection;
51
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070052/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070053 */
Junxiao Shi408a7002014-02-12 17:53:47 -070054class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070055{
56public:
57 explicit
58 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070059
Junxiao Shicbba04c2014-01-26 14:21:22 -070060 const Interest&
61 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070062
63 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070064 */
65 const Name&
66 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070067
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070068 /** \brief decides whether Interest can be forwarded to face
69 *
70 * \return true if OutRecord of this face does not exist or has expired,
Junxiao Shi57f0f312014-03-16 11:52:20 -070071 * and there is an InRecord not of this face,
72 * and scope is not violated
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070073 */
74 bool
Junxiao Shi57f0f312014-03-16 11:52:20 -070075 canForwardTo(const Face& face) const;
76
77 /** \brief decides whether forwarding Interest to face would violate scope
78 *
79 * \return true if scope control would be violated
80 * \note canForwardTo has more comprehensive checks (including scope control)
81 * and should be used by most strategies. Outgoing Interest pipeline
82 * should only check scope because some strategy (eg. vehicular) needs
83 * to retransmit sooner than OutRecord expiry, or forward Interest
84 * back to incoming face
85 */
86 bool
87 violatesScope(const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070088
Junxiao Shid3c792f2014-01-30 00:46:13 -070089 /** \brief records a nonce
90 *
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070091 * \return true if nonce is new; false if nonce is seen before
Junxiao Shicbba04c2014-01-26 14:21:22 -070092 */
93 bool
Junxiao Shid3c792f2014-01-30 00:46:13 -070094 addNonce(uint32_t nonce);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070095
Junxiao Shi66f91f82014-05-10 17:28:58 -070096public: // InRecord
97 const InRecordCollection&
98 getInRecords() const;
99
100 /** \brief determines whether any InRecord is a local Face
101 *
102 * \return true if any InRecord is a local Face,
103 * false if all InRecords are non-local Faces
104 */
105 bool
106 hasLocalInRecord() const;
107
Junxiao Shicbba04c2014-01-26 14:21:22 -0700108 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700109 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700110 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700111 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700112 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700113 */
114 InRecordCollection::iterator
115 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700116
Junxiao Shi66f91f82014-05-10 17:28:58 -0700117 /** \brief get the InRecord for face
118 * \return an iterator to the InRecord, or .end if it does not exist
119 */
120 InRecordCollection::const_iterator
121 getInRecord(shared_ptr<Face> face) const;
122
Junxiao Shicbba04c2014-01-26 14:21:22 -0700123 /// deletes all InRecords
124 void
125 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700126
Junxiao Shi66f91f82014-05-10 17:28:58 -0700127public: // OutRecord
128 const OutRecordCollection&
129 getOutRecords() const;
130
Junxiao Shicbba04c2014-01-26 14:21:22 -0700131 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700133 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700134 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700135 */
136 OutRecordCollection::iterator
137 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700138
Junxiao Shi66f91f82014-05-10 17:28:58 -0700139 /** \brief get the OutRecord for face
140 * \return an iterator to the OutRecord, or .end if it does not exist
141 */
142 OutRecordCollection::const_iterator
143 getOutRecord(shared_ptr<Face> face) const;
144
Junxiao Shicbba04c2014-01-26 14:21:22 -0700145 /// deletes one OutRecord for face if exists
146 void
147 deleteOutRecord(shared_ptr<Face> face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700148
Junxiao Shi57f0f312014-03-16 11:52:20 -0700149 /** \return true if there is one or more unexpired OutRecords
150 */
151 bool
152 hasUnexpiredOutRecords() const;
153
Junxiao Shid3c792f2014-01-30 00:46:13 -0700154public:
155 EventId m_unsatisfyTimer;
156 EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700157
158private:
Junxiao Shi651b75e2014-07-17 20:15:09 -0700159 pit::NonceList m_nonceList;
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700160 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700161 InRecordCollection m_inRecords;
162 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700163
164 static const Name LOCALHOST_NAME;
165 static const Name LOCALHOP_NAME;
166
HangZhangcb4fc832014-03-11 16:57:11 +0800167 shared_ptr<name_tree::Entry> m_nameTreeEntry;
168
169 friend class nfd::NameTree;
170 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700171};
172
173inline const Interest&
174Entry::getInterest() const
175{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700176 return *m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700177}
178
179} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800180} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700181
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700182#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP