blob: 3f155985eb1e837b142d12463048fd437748e443 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi1e46be32015-01-08 20:18:05 -07003 * Copyright (c) 2014-2015, 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
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;
39}
40
Junxiao Shicbba04c2014-01-26 14:21:22 -070041namespace pit {
42
Junxiao Shi66f91f82014-05-10 17:28:58 -070043/** \brief represents an unordered collection of InRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070044 */
45typedef std::list< InRecord> InRecordCollection;
46
Junxiao Shi66f91f82014-05-10 17:28:58 -070047/** \brief represents an unordered collection of OutRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 */
49typedef std::list<OutRecord> OutRecordCollection;
50
Junxiao Shia110f262014-10-12 12:35:20 -070051/** \brief indicates where duplicate Nonces are found
52 */
53enum DuplicateNonceWhere {
54 DUPLICATE_NONCE_NONE = 0,
55 /// in-record of same face
56 DUPLICATE_NONCE_IN_SAME = (1 << 0),
57 /// in-record of other face
58 DUPLICATE_NONCE_IN_OTHER = (1 << 1),
59 /// out-record of same face
60 DUPLICATE_NONCE_OUT_SAME = (1 << 2),
61 /// out-record of other face
62 DUPLICATE_NONCE_OUT_OTHER = (1 << 3)
63};
64
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070065/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070066 */
Junxiao Shi408a7002014-02-12 17:53:47 -070067class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070068{
69public:
70 explicit
71 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070072
Junxiao Shicbba04c2014-01-26 14:21:22 -070073 const Interest&
74 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070075
76 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070077 */
78 const Name&
79 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070080
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070081 /** \brief decides whether Interest can be forwarded to face
82 *
83 * \return true if OutRecord of this face does not exist or has expired,
Junxiao Shi57f0f312014-03-16 11:52:20 -070084 * and there is an InRecord not of this face,
85 * and scope is not violated
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070086 */
87 bool
Junxiao Shi57f0f312014-03-16 11:52:20 -070088 canForwardTo(const Face& face) const;
89
90 /** \brief decides whether forwarding Interest to face would violate scope
91 *
92 * \return true if scope control would be violated
93 * \note canForwardTo has more comprehensive checks (including scope control)
94 * and should be used by most strategies. Outgoing Interest pipeline
95 * should only check scope because some strategy (eg. vehicular) needs
96 * to retransmit sooner than OutRecord expiry, or forward Interest
97 * back to incoming face
98 */
99 bool
100 violatesScope(const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700101
Junxiao Shia110f262014-10-12 12:35:20 -0700102 /** \brief finds where a duplicate Nonce appears
103 * \return OR'ed DuplicateNonceWhere
Junxiao Shicbba04c2014-01-26 14:21:22 -0700104 */
Junxiao Shia110f262014-10-12 12:35:20 -0700105 int
106 findNonce(uint32_t nonce, const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700107
Junxiao Shi66f91f82014-05-10 17:28:58 -0700108public: // InRecord
109 const InRecordCollection&
110 getInRecords() const;
111
112 /** \brief determines whether any InRecord is a local Face
113 *
114 * \return true if any InRecord is a local Face,
115 * false if all InRecords are non-local Faces
116 */
117 bool
118 hasLocalInRecord() const;
119
Junxiao Shicbba04c2014-01-26 14:21:22 -0700120 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700121 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700122 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700123 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700124 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700125 */
126 InRecordCollection::iterator
127 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700128
Junxiao Shi66f91f82014-05-10 17:28:58 -0700129 /** \brief get the InRecord for face
130 * \return an iterator to the InRecord, or .end if it does not exist
131 */
132 InRecordCollection::const_iterator
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700133 getInRecord(const Face& face) const;
Junxiao Shi66f91f82014-05-10 17:28:58 -0700134
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700135 /// deletes one InRecord for face if exists
136 void
137 deleteInRecord(const Face& face);
138
Junxiao Shicbba04c2014-01-26 14:21:22 -0700139 /// deletes all InRecords
140 void
141 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700142
Junxiao Shi66f91f82014-05-10 17:28:58 -0700143public: // OutRecord
144 const OutRecordCollection&
145 getOutRecords() const;
146
Junxiao Shicbba04c2014-01-26 14:21:22 -0700147 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700148 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700149 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700150 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700151 */
152 OutRecordCollection::iterator
153 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700154
Junxiao Shi66f91f82014-05-10 17:28:58 -0700155 /** \brief get the OutRecord for face
156 * \return an iterator to the OutRecord, or .end if it does not exist
157 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700158 OutRecordCollection::iterator
159 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700160
Junxiao Shicbba04c2014-01-26 14:21:22 -0700161 /// deletes one OutRecord for face if exists
162 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700163 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700164
Junxiao Shi57f0f312014-03-16 11:52:20 -0700165 /** \return true if there is one or more unexpired OutRecords
166 */
167 bool
168 hasUnexpiredOutRecords() const;
169
Junxiao Shid3c792f2014-01-30 00:46:13 -0700170public:
Junxiao Shi1e46be32015-01-08 20:18:05 -0700171 scheduler::EventId m_unsatisfyTimer;
172 scheduler::EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700173
174private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700175 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700176 InRecordCollection m_inRecords;
177 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700178
179 static const Name LOCALHOST_NAME;
180 static const Name LOCALHOP_NAME;
181
HangZhangcb4fc832014-03-11 16:57:11 +0800182 shared_ptr<name_tree::Entry> m_nameTreeEntry;
183
184 friend class nfd::NameTree;
185 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700186};
187
188inline const Interest&
189Entry::getInterest() const
190{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700191 return *m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700192}
193
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700194inline const InRecordCollection&
195Entry::getInRecords() const
196{
197 return m_inRecords;
198}
199
200inline const OutRecordCollection&
201Entry::getOutRecords() const
202{
203 return m_outRecords;
204}
205
Junxiao Shicbba04c2014-01-26 14:21:22 -0700206} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800207} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700208
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700209#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP