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