HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 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 | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 28 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 29 | #include "core/common.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 30 | #include "table/fib-entry.hpp" |
| 31 | #include "table/pit-entry.hpp" |
| 32 | #include "table/measurements-entry.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 33 | #include "table/strategy-choice-entry.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 36 | namespace name_tree { |
| 37 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 38 | class Node; |
| 39 | class Entry; |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 40 | class NameTree; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 41 | |
| 42 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 43 | * \brief Name Tree Node Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 44 | */ |
| 45 | class Node |
| 46 | { |
| 47 | public: |
| 48 | Node(); |
| 49 | |
| 50 | ~Node(); |
| 51 | |
| 52 | public: |
| 53 | // variables are in public as this is just a data structure |
| 54 | shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry) |
| 55 | Node* m_prev; // Previous Name Tree Node (to resolve hash collision) |
| 56 | Node* m_next; // Next Name Tree Node (to resolve hash collision) |
| 57 | }; |
| 58 | |
| 59 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 60 | * \brief Name Tree Entry Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 61 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 62 | class Entry : public enable_shared_from_this<Entry>, noncopyable |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 63 | { |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 64 | public: |
| 65 | explicit |
| 66 | Entry(const Name& prefix); |
| 67 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 68 | const Name& |
| 69 | getPrefix() const; |
| 70 | |
| 71 | void |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 72 | setHash(size_t hash); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 73 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 74 | size_t |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 75 | getHash() const; |
| 76 | |
| 77 | void |
| 78 | setParent(shared_ptr<Entry> parent); |
| 79 | |
| 80 | shared_ptr<Entry> |
| 81 | getParent() const; |
| 82 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 83 | std::vector<shared_ptr<Entry>>& |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 84 | getChildren(); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 85 | |
| 86 | bool |
| 87 | hasChildren() const; |
| 88 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 89 | bool |
| 90 | isEmpty() const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 91 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 92 | public: // attached table entries |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 93 | void |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 94 | setFibEntry(unique_ptr<fib::Entry> fibEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 95 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 96 | fib::Entry* |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 97 | getFibEntry() const; |
| 98 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 99 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 100 | insertPitEntry(shared_ptr<pit::Entry> pitEntry); |
| 101 | |
| 102 | void |
| 103 | erasePitEntry(shared_ptr<pit::Entry> pitEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 104 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 105 | bool |
| 106 | hasPitEntries() const; |
| 107 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 108 | const std::vector<shared_ptr<pit::Entry>>& |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 109 | getPitEntries() const; |
| 110 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 111 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 112 | setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 113 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 114 | measurements::Entry* |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 115 | getMeasurementsEntry() const; |
| 116 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 117 | void |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 118 | setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 119 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 120 | strategy_choice::Entry* |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 121 | getStrategyChoiceEntry() const; |
| 122 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 123 | private: |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 124 | // Benefits of storing m_hash |
| 125 | // 1. m_hash is compared before m_prefix is compared |
| 126 | // 2. fast hash table resize support |
| 127 | size_t m_hash; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 128 | Name m_prefix; |
| 129 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 130 | std::vector<shared_ptr<Entry>> m_children; // Children pointers. |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 131 | unique_ptr<fib::Entry> m_fibEntry; |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 132 | std::vector<shared_ptr<pit::Entry>> m_pitEntries; |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 133 | unique_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 134 | unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 135 | |
| 136 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 137 | Node* m_node; |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 138 | |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 139 | friend class NameTree; |
| 140 | friend class FullEnumerationImpl; |
| 141 | friend class PartialEnumerationImpl; |
| 142 | friend class PrefixMatchImpl; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | inline const Name& |
| 146 | Entry::getPrefix() const |
| 147 | { |
| 148 | return m_prefix; |
| 149 | } |
| 150 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 151 | inline size_t |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 152 | Entry::getHash() const |
| 153 | { |
| 154 | return m_hash; |
| 155 | } |
| 156 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 157 | inline void |
| 158 | Entry::setHash(size_t hash) |
| 159 | { |
| 160 | m_hash = hash; |
| 161 | } |
| 162 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 163 | inline shared_ptr<Entry> |
| 164 | Entry::getParent() const |
| 165 | { |
| 166 | return m_parent; |
| 167 | } |
| 168 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 169 | inline void |
| 170 | Entry::setParent(shared_ptr<Entry> parent) |
| 171 | { |
| 172 | m_parent = parent; |
| 173 | } |
| 174 | |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 175 | inline std::vector<shared_ptr<name_tree::Entry>>& |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 176 | Entry::getChildren() |
| 177 | { |
| 178 | return m_children; |
| 179 | } |
| 180 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 181 | inline bool |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 182 | Entry::hasChildren() const |
| 183 | { |
| 184 | return !m_children.empty(); |
| 185 | } |
| 186 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 187 | inline fib::Entry* |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 188 | Entry::getFibEntry() const |
| 189 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 190 | return m_fibEntry.get(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 191 | } |
| 192 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 193 | inline bool |
| 194 | Entry::hasPitEntries() const |
| 195 | { |
| 196 | return !m_pitEntries.empty(); |
| 197 | } |
| 198 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 199 | inline const std::vector<shared_ptr<pit::Entry>>& |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 200 | Entry::getPitEntries() const |
| 201 | { |
| 202 | return m_pitEntries; |
| 203 | } |
| 204 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 205 | inline measurements::Entry* |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 206 | Entry::getMeasurementsEntry() const |
| 207 | { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 208 | return m_measurementsEntry.get(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 211 | inline strategy_choice::Entry* |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 212 | Entry::getStrategyChoiceEntry() const |
| 213 | { |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 214 | return m_strategyChoiceEntry.get(); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 217 | } // namespace name_tree |
| 218 | } // namespace nfd |
| 219 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 220 | #endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP |