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