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 | |
| 35 | class NameTree; |
| 36 | |
| 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& |
| 71 | getInterest() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 72 | |
| 73 | /** \return Interest Name |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 74 | */ |
| 75 | const Name& |
| 76 | getName() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 77 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 78 | public: // in-record |
| 79 | /** \return collection of in-records |
| 80 | */ |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 81 | const InRecordCollection& |
| 82 | getInRecords() const; |
| 83 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 84 | /** \retval true There is at least one in-record. |
| 85 | * This implies some downstream is waiting for Data or Nack. |
| 86 | * \retval false There is no in-record. |
| 87 | * This implies the entry is new or has been satisfied or Nacked. |
| 88 | */ |
| 89 | bool |
| 90 | hasInRecords() const; |
| 91 | |
| 92 | InRecordCollection::iterator |
| 93 | in_begin(); |
| 94 | |
| 95 | InRecordCollection::const_iterator |
| 96 | in_begin() const; |
| 97 | |
| 98 | InRecordCollection::iterator |
| 99 | in_end(); |
| 100 | |
| 101 | InRecordCollection::const_iterator |
| 102 | in_end() const; |
| 103 | |
| 104 | /** \brief get the in-record for \p face |
| 105 | * \return an iterator to the in-record, or .in_end() if it does not exist |
| 106 | */ |
| 107 | InRecordCollection::iterator |
| 108 | getInRecord(const Face& face); |
| 109 | |
| 110 | /** \brief insert or update an in-record |
| 111 | * \return an iterator to the new or updated in-record |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 112 | */ |
| 113 | InRecordCollection::iterator |
| 114 | insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 115 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 116 | /** \brief delete the in-record for \p face if it exists |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 117 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 118 | void |
| 119 | deleteInRecord(const Face& face); |
| 120 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 121 | /** \brief delete all in-records |
| 122 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 123 | void |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 124 | clearInRecords(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 125 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 126 | public: // out-record |
| 127 | /** \return collection of in-records |
| 128 | */ |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 129 | const OutRecordCollection& |
| 130 | getOutRecords() const; |
| 131 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 132 | /** \retval true There is at least one out-record. |
| 133 | * This implies the Interest has been forwarded to some upstream, |
| 134 | * and they haven't returned Data, but may have returned Nacks. |
| 135 | * \retval false There is no out-record. |
| 136 | * This implies the Interest has not been forwarded. |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 137 | */ |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 138 | bool |
| 139 | hasOutRecords() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 140 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 141 | OutRecordCollection::iterator |
| 142 | out_begin(); |
| 143 | |
| 144 | OutRecordCollection::const_iterator |
| 145 | out_begin() const; |
| 146 | |
| 147 | OutRecordCollection::iterator |
| 148 | out_end(); |
| 149 | |
| 150 | OutRecordCollection::const_iterator |
| 151 | out_end() const; |
| 152 | |
| 153 | /** \brief get the out-record for \p face |
| 154 | * \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] | 155 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 156 | OutRecordCollection::iterator |
| 157 | getOutRecord(const Face& face); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 158 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 159 | /** \brief insert or update an out-record |
| 160 | * \return an iterator to the new or updated out-record |
| 161 | */ |
| 162 | OutRecordCollection::iterator |
| 163 | insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest); |
| 164 | |
| 165 | /** \brief delete the out-record for \p face if it exists |
| 166 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 167 | void |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 168 | deleteOutRecord(const Face& face); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 169 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 170 | public: |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 171 | /** \brief unsatisfy timer |
| 172 | * |
| 173 | * This timer is used in forwarding pipelines to delete the entry |
| 174 | * when it expires without being satisfied. |
| 175 | * It fires when the last InterestLifetime among in-records expires. |
| 176 | * |
| 177 | * Either this or the straggler timer should be set at all times, |
| 178 | * except when this entry is being processed in a pipeline. |
| 179 | */ |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 180 | scheduler::EventId m_unsatisfyTimer; |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 181 | |
| 182 | /** \brief straggler timer |
| 183 | * |
| 184 | * This timer is used in forwarding pipelines to delete the entry when it has been satisfied |
| 185 | * and is no longer needed for measurement collection purpose. |
| 186 | * |
| 187 | * Either this or the unsatisfy timer should be set at all times, |
| 188 | * except when this entry is being processed in a pipeline. |
| 189 | */ |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 190 | scheduler::EventId m_stragglerTimer; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 191 | |
| 192 | private: |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 193 | shared_ptr<const Interest> m_interest; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 194 | InRecordCollection m_inRecords; |
| 195 | OutRecordCollection m_outRecords; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 196 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 197 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 198 | |
| 199 | friend class nfd::NameTree; |
| 200 | friend class nfd::name_tree::Entry; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | inline const Interest& |
| 204 | Entry::getInterest() const |
| 205 | { |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 206 | return *m_interest; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 209 | inline const Name& |
| 210 | Entry::getName() const |
| 211 | { |
| 212 | return m_interest->getName(); |
| 213 | } |
| 214 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 215 | inline const InRecordCollection& |
| 216 | Entry::getInRecords() const |
| 217 | { |
| 218 | return m_inRecords; |
| 219 | } |
| 220 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 221 | inline bool |
| 222 | Entry::hasInRecords() const |
| 223 | { |
| 224 | return !m_inRecords.empty(); |
| 225 | } |
| 226 | |
| 227 | inline InRecordCollection::iterator |
| 228 | Entry::in_begin() |
| 229 | { |
| 230 | return m_inRecords.begin(); |
| 231 | } |
| 232 | |
| 233 | inline InRecordCollection::const_iterator |
| 234 | Entry::in_begin() const |
| 235 | { |
| 236 | return m_inRecords.begin(); |
| 237 | } |
| 238 | |
| 239 | inline InRecordCollection::iterator |
| 240 | Entry::in_end() |
| 241 | { |
| 242 | return m_inRecords.end(); |
| 243 | } |
| 244 | |
| 245 | inline InRecordCollection::const_iterator |
| 246 | Entry::in_end() const |
| 247 | { |
| 248 | return m_inRecords.end(); |
| 249 | } |
| 250 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 251 | inline const OutRecordCollection& |
| 252 | Entry::getOutRecords() const |
| 253 | { |
| 254 | return m_outRecords; |
| 255 | } |
| 256 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame^] | 257 | inline bool |
| 258 | Entry::hasOutRecords() const |
| 259 | { |
| 260 | return !m_outRecords.empty(); |
| 261 | } |
| 262 | |
| 263 | inline OutRecordCollection::iterator |
| 264 | Entry::out_begin() |
| 265 | { |
| 266 | return m_outRecords.begin(); |
| 267 | } |
| 268 | |
| 269 | inline OutRecordCollection::const_iterator |
| 270 | Entry::out_begin() const |
| 271 | { |
| 272 | return m_outRecords.begin(); |
| 273 | } |
| 274 | |
| 275 | inline OutRecordCollection::iterator |
| 276 | Entry::out_end() |
| 277 | { |
| 278 | return m_outRecords.end(); |
| 279 | } |
| 280 | |
| 281 | inline OutRecordCollection::const_iterator |
| 282 | Entry::out_end() const |
| 283 | { |
| 284 | return m_outRecords.end(); |
| 285 | } |
| 286 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 287 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 288 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 289 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 290 | #endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP |