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