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 | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 2 | /* |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [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/>. |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -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_HPP |
| 27 | #define NFD_DAEMON_TABLE_PIT_HPP |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | |
| 29 | #include "pit-entry.hpp" |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 30 | #include "pit-iterator.hpp" |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 31 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 33 | namespace pit { |
| 34 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 35 | /** \class nfd::pit::DataMatchResult |
| 36 | * \brief An unordered iterable of all PIT entries matching Data. |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 37 | * |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 38 | * This type has the following member functions: |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 39 | * - `iterator<shared_ptr<Entry>> begin()` |
| 40 | * - `iterator<shared_ptr<Entry>> end()` |
| 41 | * - `size_t size() const` |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 42 | */ |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 43 | using DataMatchResult = std::vector<shared_ptr<Entry>>; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 44 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 45 | /** \brief Represents the Interest Table |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | */ |
| 47 | class Pit : noncopyable |
| 48 | { |
| 49 | public: |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 50 | explicit |
| 51 | Pit(NameTree& nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 52 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 53 | /** \return number of entries |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 54 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 55 | size_t |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 56 | size() const |
| 57 | { |
| 58 | return m_nItems; |
| 59 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 60 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 61 | /** \brief Finds a PIT entry for \p interest |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 62 | * \param interest the Interest |
| 63 | * \return an existing entry with same Name and Selectors; otherwise nullptr |
| 64 | */ |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 65 | shared_ptr<Entry> |
| 66 | find(const Interest& interest) const |
| 67 | { |
| 68 | return const_cast<Pit*>(this)->findOrInsert(interest, false).first; |
| 69 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 70 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 71 | /** \brief Inserts a PIT entry for \p interest |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 72 | * \param interest the Interest; must be created with make_shared |
| 73 | * \return a new or existing entry with same Name and Selectors, |
| 74 | * and true for new entry, false for existing entry |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 75 | */ |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 76 | std::pair<shared_ptr<Entry>, bool> |
| 77 | insert(const Interest& interest) |
| 78 | { |
| 79 | return this->findOrInsert(interest, true); |
| 80 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 81 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 82 | /** \brief Performs a Data match |
| 83 | * \return an iterable of all PIT entries matching \p data |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 84 | */ |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 85 | DataMatchResult |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 86 | findAllDataMatches(const Data& data) const; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 87 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 88 | /** \brief Deletes an entry |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 89 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 90 | void |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 91 | erase(Entry* entry) |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 92 | { |
| 93 | this->erase(entry, true); |
| 94 | } |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 95 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 96 | /** \brief Deletes all in-records and out-records for \p face |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 97 | */ |
| 98 | void |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 99 | deleteInOutRecordsByFace(Entry* entry, const Face& face); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 101 | public: // enumeration |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 102 | typedef Iterator const_iterator; |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 103 | |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 104 | /** \return an iterator to the beginning |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 105 | * \note Iteration order is implementation-defined. |
| 106 | * \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 107 | * is inserted or erased during iteration. |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 108 | */ |
| 109 | const_iterator |
| 110 | begin() const; |
| 111 | |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 112 | /** \return an iterator to the end |
| 113 | * \sa begin() |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 114 | */ |
| 115 | const_iterator |
Junxiao Shi | 3248205 | 2016-08-15 02:05:17 +0000 | [diff] [blame] | 116 | end() const |
| 117 | { |
| 118 | return Iterator(); |
| 119 | } |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 120 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 121 | private: |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 122 | void |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 123 | erase(Entry* pitEntry, bool canDeleteNte); |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 124 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 125 | /** \brief Finds or inserts a PIT entry for \p interest |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 126 | * \param interest the Interest; must be created with make_shared if allowInsert |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 127 | * \param allowInsert whether inserting a new entry is allowed |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 128 | * \return if allowInsert, a new or existing entry with same Name+Selectors, |
| 129 | * and true for new entry, false for existing entry; |
| 130 | * if not allowInsert, an existing entry with same Name+Selectors and false, |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 131 | * or `{nullptr, true}` if there's no existing entry |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 132 | */ |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 133 | std::pair<shared_ptr<Entry>, bool> |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 134 | findOrInsert(const Interest& interest, bool allowInsert); |
| 135 | |
| 136 | private: |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 137 | NameTree& m_nameTree; |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 138 | size_t m_nItems = 0; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 141 | } // namespace pit |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 142 | |
Junxiao Shi | 09cf13c | 2016-08-15 02:05:00 +0000 | [diff] [blame] | 143 | using pit::Pit; |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 144 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 145 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 147 | #endif // NFD_DAEMON_TABLE_PIT_HPP |