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