blob: b7f83a35690c3cd5579aa1b72d799210ddf4c5dc [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
spirosmastorakis704430c2016-04-29 14:54:48 -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;
spirosmastorakis704430c2016-04-29 14:54:48 -070039} // namespace name_tree
40
41class Pit;
HangZhangcb4fc832014-03-11 16:57:11 +080042
Junxiao Shicbba04c2014-01-26 14:21:22 -070043namespace pit {
44
Junxiao Shi66f91f82014-05-10 17:28:58 -070045/** \brief represents an unordered collection of InRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 */
47typedef std::list< InRecord> InRecordCollection;
48
Junxiao Shi66f91f82014-05-10 17:28:58 -070049/** \brief represents an unordered collection of OutRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070050 */
51typedef std::list<OutRecord> OutRecordCollection;
52
Junxiao Shia110f262014-10-12 12:35:20 -070053/** \brief indicates where duplicate Nonces are found
54 */
55enum DuplicateNonceWhere {
56 DUPLICATE_NONCE_NONE = 0,
57 /// in-record of same face
58 DUPLICATE_NONCE_IN_SAME = (1 << 0),
59 /// in-record of other face
60 DUPLICATE_NONCE_IN_OTHER = (1 << 1),
61 /// out-record of same face
62 DUPLICATE_NONCE_OUT_SAME = (1 << 2),
63 /// out-record of other face
64 DUPLICATE_NONCE_OUT_OTHER = (1 << 3)
65};
66
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070067/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070068 */
Junxiao Shi408a7002014-02-12 17:53:47 -070069class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070070{
71public:
72 explicit
73 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070074
Junxiao Shicbba04c2014-01-26 14:21:22 -070075 const Interest&
76 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070077
78 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070079 */
80 const Name&
81 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070082
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070083 /** \brief decides whether Interest can be forwarded to face
84 *
85 * \return true if OutRecord of this face does not exist or has expired,
Junxiao Shi57f0f312014-03-16 11:52:20 -070086 * and there is an InRecord not of this face,
87 * and scope is not violated
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070088 */
89 bool
Junxiao Shi57f0f312014-03-16 11:52:20 -070090 canForwardTo(const Face& face) const;
91
92 /** \brief decides whether forwarding Interest to face would violate scope
93 *
94 * \return true if scope control would be violated
95 * \note canForwardTo has more comprehensive checks (including scope control)
96 * and should be used by most strategies. Outgoing Interest pipeline
97 * should only check scope because some strategy (eg. vehicular) needs
98 * to retransmit sooner than OutRecord expiry, or forward Interest
99 * back to incoming face
100 */
101 bool
102 violatesScope(const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700103
Junxiao Shia110f262014-10-12 12:35:20 -0700104 /** \brief finds where a duplicate Nonce appears
105 * \return OR'ed DuplicateNonceWhere
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106 */
Junxiao Shia110f262014-10-12 12:35:20 -0700107 int
108 findNonce(uint32_t nonce, const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700109
Junxiao Shi66f91f82014-05-10 17:28:58 -0700110public: // InRecord
111 const InRecordCollection&
112 getInRecords() const;
113
114 /** \brief determines whether any InRecord is a local Face
115 *
116 * \return true if any InRecord is a local Face,
117 * false if all InRecords are non-local Faces
118 */
119 bool
120 hasLocalInRecord() const;
121
Junxiao Shicbba04c2014-01-26 14:21:22 -0700122 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700123 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700124 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700126 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700127 */
128 InRecordCollection::iterator
129 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700130
Junxiao Shi66f91f82014-05-10 17:28:58 -0700131 /** \brief get the InRecord for face
132 * \return an iterator to the InRecord, or .end if it does not exist
133 */
134 InRecordCollection::const_iterator
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700135 getInRecord(const Face& face) const;
Junxiao Shi66f91f82014-05-10 17:28:58 -0700136
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700137 /// deletes one InRecord for face if exists
138 void
139 deleteInRecord(const Face& face);
140
Junxiao Shicbba04c2014-01-26 14:21:22 -0700141 /// deletes all InRecords
142 void
143 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700144
Junxiao Shi66f91f82014-05-10 17:28:58 -0700145public: // OutRecord
146 const OutRecordCollection&
147 getOutRecords() const;
148
Junxiao Shicbba04c2014-01-26 14:21:22 -0700149 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700150 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700151 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700152 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700153 */
154 OutRecordCollection::iterator
155 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700156
Junxiao Shi66f91f82014-05-10 17:28:58 -0700157 /** \brief get the OutRecord for face
158 * \return an iterator to the OutRecord, or .end if it does not exist
159 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700160 OutRecordCollection::iterator
161 getOutRecord(const Face& face);
Junxiao Shi66f91f82014-05-10 17:28:58 -0700162
Junxiao Shicbba04c2014-01-26 14:21:22 -0700163 /// deletes one OutRecord for face if exists
164 void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700165 deleteOutRecord(const Face& face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700166
Junxiao Shi57f0f312014-03-16 11:52:20 -0700167 /** \return true if there is one or more unexpired OutRecords
168 */
169 bool
170 hasUnexpiredOutRecords() const;
171
Junxiao Shid3c792f2014-01-30 00:46:13 -0700172public:
Junxiao Shi1e46be32015-01-08 20:18:05 -0700173 scheduler::EventId m_unsatisfyTimer;
174 scheduler::EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700175
176private:
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700177 shared_ptr<const Interest> m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700178 InRecordCollection m_inRecords;
179 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700180
181 static const Name LOCALHOST_NAME;
182 static const Name LOCALHOP_NAME;
183
HangZhangcb4fc832014-03-11 16:57:11 +0800184 shared_ptr<name_tree::Entry> m_nameTreeEntry;
185
186 friend class nfd::NameTree;
187 friend class nfd::name_tree::Entry;
spirosmastorakis704430c2016-04-29 14:54:48 -0700188 friend class nfd::Pit;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700189};
190
191inline const Interest&
192Entry::getInterest() const
193{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700194 return *m_interest;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700195}
196
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700197inline const InRecordCollection&
198Entry::getInRecords() const
199{
200 return m_inRecords;
201}
202
203inline const OutRecordCollection&
204Entry::getOutRecords() const
205{
206 return m_outRecords;
207}
208
Junxiao Shicbba04c2014-01-26 14:21:22 -0700209} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800210} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700211
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700212#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP