blob: e281bc7cf504eb2a1e52fe07ba4bf31fcc69f3b8 [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
25#ifndef NFD_TABLE_PIT_ENTRY_HPP
26#define NFD_TABLE_PIT_ENTRY_HPP
27
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
42/** \class InRecordCollection
43 * \brief represents an unordered collection of InRecords
44 */
45typedef std::list< InRecord> InRecordCollection;
46
47/** \class OutRecordCollection
48 * \brief represents an unordered collection of OutRecords
49 */
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 Shicbba04c2014-01-26 14:21:22 -070068 const InRecordCollection&
69 getInRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070070
Junxiao Shicbba04c2014-01-26 14:21:22 -070071 const OutRecordCollection&
72 getOutRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070073
Junxiao Shi11bd9c22014-03-13 20:44:13 -070074 /** \brief determines whether any InRecord is a local Face
75 *
76 * \return true if any InRecord is a local Face,
77 * false if all InRecords are non-local Faces
78 */
79 bool
80 hasLocalInRecord() const;
81
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070082 /** \brief decides whether Interest can be forwarded to face
83 *
84 * \return true if OutRecord of this face does not exist or has expired,
Junxiao Shi57f0f312014-03-16 11:52:20 -070085 * and there is an InRecord not of this face,
86 * and scope is not violated
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070087 */
88 bool
Junxiao Shi57f0f312014-03-16 11:52:20 -070089 canForwardTo(const Face& face) const;
90
91 /** \brief decides whether forwarding Interest to face would violate scope
92 *
93 * \return true if scope control would be violated
94 * \note canForwardTo has more comprehensive checks (including scope control)
95 * and should be used by most strategies. Outgoing Interest pipeline
96 * should only check scope because some strategy (eg. vehicular) needs
97 * to retransmit sooner than OutRecord expiry, or forward Interest
98 * back to incoming face
99 */
100 bool
101 violatesScope(const Face& face) const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700102
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 /** \brief records a nonce
104 *
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700105 * \return true if nonce is new; false if nonce is seen before
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106 */
107 bool
Junxiao Shid3c792f2014-01-30 00:46:13 -0700108 addNonce(uint32_t nonce);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700109
Junxiao Shicbba04c2014-01-26 14:21:22 -0700110 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700111 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700112 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700113 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700114 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700115 */
116 InRecordCollection::iterator
117 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700118
Junxiao Shicbba04c2014-01-26 14:21:22 -0700119 /// deletes all InRecords
120 void
121 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700122
Junxiao Shicbba04c2014-01-26 14:21:22 -0700123 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -0700124 *
Junxiao Shicbba04c2014-01-26 14:21:22 -0700125 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700126 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -0700127 */
128 OutRecordCollection::iterator
129 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700130
Junxiao Shicbba04c2014-01-26 14:21:22 -0700131 /// deletes one OutRecord for face if exists
132 void
133 deleteOutRecord(shared_ptr<Face> face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700134
Junxiao Shi57f0f312014-03-16 11:52:20 -0700135 /** \return true if there is one or more unexpired OutRecords
136 */
137 bool
138 hasUnexpiredOutRecords() const;
139
Junxiao Shid3c792f2014-01-30 00:46:13 -0700140public:
141 EventId m_unsatisfyTimer;
142 EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700143
144private:
145 std::set<uint32_t> m_nonces;
146 const Interest m_interest;
147 InRecordCollection m_inRecords;
148 OutRecordCollection m_outRecords;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700149
150 static const Name LOCALHOST_NAME;
151 static const Name LOCALHOP_NAME;
152
HangZhangcb4fc832014-03-11 16:57:11 +0800153 shared_ptr<name_tree::Entry> m_nameTreeEntry;
154
155 friend class nfd::NameTree;
156 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700157};
158
159inline const Interest&
160Entry::getInterest() const
161{
162 return m_interest;
163}
164
165} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800166} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700167
168#endif // NFD_TABLE_PIT_ENTRY_HPP