Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_PIT_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_PIT_ENTRY_HPP |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | |
| 29 | #include "pit-in-record.hpp" |
| 30 | #include "pit-out-record.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 31 | #include "core/scheduler.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | c0822fa | 2018-05-10 21:54:10 -0400 | [diff] [blame] | 33 | #include <list> |
| 34 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 35 | namespace nfd { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 36 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 37 | namespace name_tree { |
| 38 | class Entry; |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 39 | } // namespace name_tree |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 40 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 41 | namespace pit { |
| 42 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 43 | /** \brief an unordered collection of in-records |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 44 | */ |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 45 | typedef std::list<InRecord> InRecordCollection; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 47 | /** \brief an unordered collection of out-records |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 48 | */ |
| 49 | typedef std::list<OutRecord> OutRecordCollection; |
| 50 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 51 | /** \brief an Interest table entry |
| 52 | * |
| 53 | * An Interest table entry represents either a pending Interest or a recently satisfied Interest. |
| 54 | * Each entry contains a collection of in-records, a collection of out-records, |
| 55 | * and two timers used in forwarding pipelines. |
| 56 | * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost, |
| 57 | * which allows forwarding strategy to store arbitrary information on them. |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 58 | */ |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 59 | class Entry : public StrategyInfoHost, noncopyable |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 60 | { |
| 61 | public: |
| 62 | explicit |
| 63 | Entry(const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 64 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 65 | /** \return the representative Interest of the PIT entry |
| 66 | * \note Every Interest in in-records and out-records should have same Name and Selectors |
| 67 | * as the representative Interest. |
| 68 | * \todo #3162 require Link field to match the representative Interest |
| 69 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 70 | const Interest& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 71 | getInterest() const |
| 72 | { |
| 73 | return *m_interest; |
| 74 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 75 | |
| 76 | /** \return Interest Name |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 77 | */ |
| 78 | const Name& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 79 | getName() const |
| 80 | { |
| 81 | return m_interest->getName(); |
| 82 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 84 | /** \return whether interest matches this entry |
| 85 | * \param interest the Interest |
| 86 | * \param nEqualNameComps number of initial name components guaranteed to be equal |
| 87 | */ |
| 88 | bool |
| 89 | canMatch(const Interest& interest, size_t nEqualNameComps = 0) const; |
| 90 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 91 | public: // in-record |
| 92 | /** \return collection of in-records |
| 93 | */ |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 94 | const InRecordCollection& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 95 | getInRecords() const |
| 96 | { |
| 97 | return m_inRecords; |
| 98 | } |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 99 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 100 | /** \retval true There is at least one in-record. |
| 101 | * This implies some downstream is waiting for Data or Nack. |
| 102 | * \retval false There is no in-record. |
| 103 | * This implies the entry is new or has been satisfied or Nacked. |
| 104 | */ |
| 105 | bool |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 106 | hasInRecords() const |
| 107 | { |
| 108 | return !m_inRecords.empty(); |
| 109 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 110 | |
| 111 | InRecordCollection::iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 112 | in_begin() |
| 113 | { |
| 114 | return m_inRecords.begin(); |
| 115 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 116 | |
| 117 | InRecordCollection::const_iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 118 | in_begin() const |
| 119 | { |
| 120 | return m_inRecords.begin(); |
| 121 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 122 | |
| 123 | InRecordCollection::iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 124 | in_end() |
| 125 | { |
| 126 | return m_inRecords.end(); |
| 127 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 128 | |
| 129 | InRecordCollection::const_iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 130 | in_end() const |
| 131 | { |
| 132 | return m_inRecords.end(); |
| 133 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 134 | |
| 135 | /** \brief get the in-record for \p face |
| 136 | * \return an iterator to the in-record, or .in_end() if it does not exist |
| 137 | */ |
| 138 | InRecordCollection::iterator |
| 139 | getInRecord(const Face& face); |
| 140 | |
| 141 | /** \brief insert or update an in-record |
| 142 | * \return an iterator to the new or updated in-record |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 143 | */ |
| 144 | InRecordCollection::iterator |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 145 | insertOrUpdateInRecord(Face& face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 146 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 147 | /** \brief delete the in-record for \p face if it exists |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 148 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 149 | void |
| 150 | deleteInRecord(const Face& face); |
| 151 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 152 | /** \brief delete all in-records |
| 153 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 154 | void |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 155 | clearInRecords(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 156 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 157 | public: // out-record |
| 158 | /** \return collection of in-records |
| 159 | */ |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 160 | const OutRecordCollection& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 161 | getOutRecords() const |
| 162 | { |
| 163 | return m_outRecords; |
| 164 | } |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 165 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 166 | /** \retval true There is at least one out-record. |
| 167 | * This implies the Interest has been forwarded to some upstream, |
| 168 | * and they haven't returned Data, but may have returned Nacks. |
| 169 | * \retval false There is no out-record. |
| 170 | * This implies the Interest has not been forwarded. |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 171 | */ |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 172 | bool |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 173 | hasOutRecords() const |
| 174 | { |
| 175 | return !m_outRecords.empty(); |
| 176 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 177 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 178 | OutRecordCollection::iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 179 | out_begin() |
| 180 | { |
| 181 | return m_outRecords.begin(); |
| 182 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 183 | |
| 184 | OutRecordCollection::const_iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 185 | out_begin() const |
| 186 | { |
| 187 | return m_outRecords.begin(); |
| 188 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 189 | |
| 190 | OutRecordCollection::iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 191 | out_end() |
| 192 | { |
| 193 | return m_outRecords.end(); |
| 194 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 195 | |
| 196 | OutRecordCollection::const_iterator |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 197 | out_end() const |
| 198 | { |
| 199 | return m_outRecords.end(); |
| 200 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 201 | |
| 202 | /** \brief get the out-record for \p face |
| 203 | * \return an iterator to the out-record, or .out_end() if it does not exist |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 204 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 205 | OutRecordCollection::iterator |
| 206 | getOutRecord(const Face& face); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 207 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 208 | /** \brief insert or update an out-record |
| 209 | * \return an iterator to the new or updated out-record |
| 210 | */ |
| 211 | OutRecordCollection::iterator |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 212 | insertOrUpdateOutRecord(Face& face, const Interest& interest); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 213 | |
| 214 | /** \brief delete the out-record for \p face if it exists |
| 215 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 216 | void |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 217 | deleteOutRecord(const Face& face); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 218 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 219 | public: |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 220 | /** \brief expiry timer |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 221 | * |
| 222 | * This timer is used in forwarding pipelines to delete the entry |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 223 | */ |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 224 | scheduler::EventId expiryTimer; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 225 | |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 226 | /** \brief indicate if PIT entry is satisfied |
| 227 | */ |
| 228 | bool isSatisfied; |
| 229 | |
| 230 | /** \brief Data freshness period |
| 231 | * \note This field is meaningful only if isSatisfied is true |
| 232 | */ |
| 233 | time::milliseconds dataFreshnessPeriod; |
| 234 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 235 | private: |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 236 | shared_ptr<const Interest> m_interest; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 237 | InRecordCollection m_inRecords; |
| 238 | OutRecordCollection m_outRecords; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 239 | |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 240 | name_tree::Entry* m_nameTreeEntry; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 241 | |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 242 | friend class name_tree::Entry; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 245 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 246 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 247 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 248 | #endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP |