blob: 521671df35885a8295844da0dcb39be909e1942c [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shicbba04c2014-01-26 14:21:22 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_TABLE_PIT_ENTRY_HPP
26#define NFD_DAEMON_TABLE_PIT_ENTRY_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070027
28#include "pit-in-record.hpp"
29#include "pit-out-record.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070030#include "core/scheduler.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070031
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080032namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080033
34class NameTree;
35
36namespace name_tree {
37class Entry;
38}
39
Junxiao Shicbba04c2014-01-26 14:21:22 -070040namespace pit {
41
Junxiao Shi66f91f82014-05-10 17:28:58 -070042/** \brief represents an unordered collection of InRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070043 */
44typedef std::list< InRecord> InRecordCollection;
45
Junxiao Shi66f91f82014-05-10 17:28:58 -070046/** \brief represents an unordered collection of OutRecords
Junxiao Shicbba04c2014-01-26 14:21:22 -070047 */
48typedef std::list<OutRecord> OutRecordCollection;
49
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070050/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070051 */
Junxiao Shi408a7002014-02-12 17:53:47 -070052class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070053{
54public:
55 explicit
56 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070057
Junxiao Shicbba04c2014-01-26 14:21:22 -070058 const Interest&
59 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070060
61 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070062 */
63 const Name&
64 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070065
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070066 /** \brief decides whether Interest can be forwarded to face
67 *
68 * \return true if OutRecord of this face does not exist or has expired,
Junxiao Shi57f0f312014-03-16 11:52:20 -070069 * and there is an InRecord not of this face,
70 * and scope is not violated
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070071 */
72 bool
Junxiao Shi57f0f312014-03-16 11:52:20 -070073 canForwardTo(const Face& face) const;
74
75 /** \brief decides whether forwarding Interest to face would violate scope
76 *
77 * \return true if scope control would be violated
78 * \note canForwardTo has more comprehensive checks (including scope control)
79 * and should be used by most strategies. Outgoing Interest pipeline
80 * should only check scope because some strategy (eg. vehicular) needs
81 * to retransmit sooner than OutRecord expiry, or forward Interest
82 * back to incoming face
83 */
84 bool
85 violatesScope(const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070086
Junxiao Shid3c792f2014-01-30 00:46:13 -070087 /** \brief records a nonce
88 *
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070089 * \return true if nonce is new; false if nonce is seen before
Junxiao Shicbba04c2014-01-26 14:21:22 -070090 */
91 bool
Junxiao Shid3c792f2014-01-30 00:46:13 -070092 addNonce(uint32_t nonce);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070093
Junxiao Shi66f91f82014-05-10 17:28:58 -070094public: // InRecord
95 const InRecordCollection&
96 getInRecords() const;
97
98 /** \brief determines whether any InRecord is a local Face
99 *
100 * \return true if any InRecord is a local Face,
101 * false if all InRecords are non-local Faces
102 */
103 bool
104 hasLocalInRecord() const;
105
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700107 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700108 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700109 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700110 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700111 */
112 InRecordCollection::iterator
113 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700114
Junxiao Shi66f91f82014-05-10 17:28:58 -0700115 /** \brief get the InRecord for face
116 * \return an iterator to the InRecord, or .end if it does not exist
117 */
118 InRecordCollection::const_iterator
119 getInRecord(shared_ptr<Face> face) const;
120
Junxiao Shicbba04c2014-01-26 14:21:22 -0700121 /// deletes all InRecords
122 void
123 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700124
Junxiao Shi66f91f82014-05-10 17:28:58 -0700125public: // OutRecord
126 const OutRecordCollection&
127 getOutRecords() const;
128
Junxiao Shicbba04c2014-01-26 14:21:22 -0700129 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700130 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700131 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700132 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700133 */
134 OutRecordCollection::iterator
135 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700136
Junxiao Shi66f91f82014-05-10 17:28:58 -0700137 /** \brief get the OutRecord for face
138 * \return an iterator to the OutRecord, or .end if it does not exist
139 */
140 OutRecordCollection::const_iterator
141 getOutRecord(shared_ptr<Face> face) const;
142
Junxiao Shicbba04c2014-01-26 14:21:22 -0700143 /// deletes one OutRecord for face if exists
144 void
145 deleteOutRecord(shared_ptr<Face> face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700146
Junxiao Shi57f0f312014-03-16 11:52:20 -0700147 /** \return true if there is one or more unexpired OutRecords
148 */
149 bool
150 hasUnexpiredOutRecords() const;
151
Junxiao Shid3c792f2014-01-30 00:46:13 -0700152public:
153 EventId m_unsatisfyTimer;
154 EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700155
156private:
157 std::set<uint32_t> m_nonces;
158 const Interest m_interest;
159 InRecordCollection m_inRecords;
160 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700161
162 static const Name LOCALHOST_NAME;
163 static const Name LOCALHOP_NAME;
164
HangZhangcb4fc832014-03-11 16:57:11 +0800165 shared_ptr<name_tree::Entry> m_nameTreeEntry;
166
167 friend class nfd::NameTree;
168 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700169};
170
171inline const Interest&
172Entry::getInterest() const
173{
174 return m_interest;
175}
176
177} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800178} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700179
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700180#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP