HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 24 | |
| 25 | // Name Tree Entry (i.e., Name Prefix Entry) |
| 26 | |
| 27 | #ifndef NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 28 | #define NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 29 | |
| 30 | #include "common.hpp" |
| 31 | #include "table/fib-entry.hpp" |
| 32 | #include "table/pit-entry.hpp" |
| 33 | #include "table/measurements-entry.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 34 | #include "table/strategy-choice-entry.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | |
| 38 | class NameTree; |
| 39 | |
| 40 | namespace name_tree { |
| 41 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 42 | // Forward declarations |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 43 | class Node; |
| 44 | class Entry; |
| 45 | |
| 46 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 47 | * \brief Name Tree Node Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 48 | */ |
| 49 | class Node |
| 50 | { |
| 51 | public: |
| 52 | Node(); |
| 53 | |
| 54 | ~Node(); |
| 55 | |
| 56 | public: |
| 57 | // variables are in public as this is just a data structure |
| 58 | shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry) |
| 59 | Node* m_prev; // Previous Name Tree Node (to resolve hash collision) |
| 60 | Node* m_next; // Next Name Tree Node (to resolve hash collision) |
| 61 | }; |
| 62 | |
| 63 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 64 | * \brief Name Tree Entry Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 65 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 66 | class Entry : public enable_shared_from_this<Entry>, noncopyable |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 67 | { |
| 68 | // Make private members accessible by Name Tree |
| 69 | friend class nfd::NameTree; |
| 70 | public: |
| 71 | explicit |
| 72 | Entry(const Name& prefix); |
| 73 | |
| 74 | ~Entry(); |
| 75 | |
| 76 | const Name& |
| 77 | getPrefix() const; |
| 78 | |
| 79 | void |
| 80 | setHash(uint32_t hash); |
| 81 | |
| 82 | uint32_t |
| 83 | getHash() const; |
| 84 | |
| 85 | void |
| 86 | setParent(shared_ptr<Entry> parent); |
| 87 | |
| 88 | shared_ptr<Entry> |
| 89 | getParent() const; |
| 90 | |
| 91 | std::vector<shared_ptr<Entry> >& |
| 92 | getChildren(); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 93 | |
| 94 | bool |
| 95 | hasChildren() const; |
| 96 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 97 | bool |
| 98 | isEmpty() const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 99 | |
| 100 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 101 | setFibEntry(shared_ptr<fib::Entry> fibEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 102 | |
| 103 | shared_ptr<fib::Entry> |
| 104 | getFibEntry() const; |
| 105 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 106 | void |
| 107 | insertPitEntry(shared_ptr<pit::Entry> pit); |
| 108 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 109 | bool |
| 110 | hasPitEntries() const; |
| 111 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 112 | std::vector<shared_ptr<pit::Entry> >& |
| 113 | getPitEntries(); |
| 114 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 115 | const std::vector<shared_ptr<pit::Entry> >& |
| 116 | getPitEntries() const; |
| 117 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 118 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 119 | * \brief Erase a PIT Entry |
| 120 | * \details The address of this PIT Entry is required |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 121 | */ |
| 122 | bool |
| 123 | erasePitEntry(shared_ptr<pit::Entry> pit); |
| 124 | |
| 125 | void |
| 126 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 127 | |
| 128 | shared_ptr<measurements::Entry> |
| 129 | getMeasurementsEntry() const; |
| 130 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 131 | void |
| 132 | setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry); |
| 133 | |
| 134 | shared_ptr<strategy_choice::Entry> |
| 135 | getStrategyChoiceEntry() const; |
| 136 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 137 | private: |
| 138 | uint32_t m_hash; |
| 139 | Name m_prefix; |
| 140 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 141 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 142 | shared_ptr<fib::Entry> m_fibEntry; |
| 143 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 144 | shared_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 145 | shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 146 | |
| 147 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 148 | Node* m_node; |
| 149 | }; |
| 150 | |
| 151 | inline const Name& |
| 152 | Entry::getPrefix() const |
| 153 | { |
| 154 | return m_prefix; |
| 155 | } |
| 156 | |
| 157 | inline uint32_t |
| 158 | Entry::getHash() const |
| 159 | { |
| 160 | return m_hash; |
| 161 | } |
| 162 | |
| 163 | inline shared_ptr<Entry> |
| 164 | Entry::getParent() const |
| 165 | { |
| 166 | return m_parent; |
| 167 | } |
| 168 | |
| 169 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 170 | Entry::getChildren() |
| 171 | { |
| 172 | return m_children; |
| 173 | } |
| 174 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 175 | inline bool |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 176 | Entry::hasChildren() const |
| 177 | { |
| 178 | return !m_children.empty(); |
| 179 | } |
| 180 | |
| 181 | inline bool |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 182 | Entry::isEmpty() const |
| 183 | { |
| 184 | return m_children.empty() && |
| 185 | !static_cast<bool>(m_fibEntry) && |
| 186 | m_pitEntries.empty() && |
| 187 | !static_cast<bool>(m_measurementsEntry); |
| 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 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 202 | inline std::vector<shared_ptr<pit::Entry> >& |
| 203 | Entry::getPitEntries() |
| 204 | { |
| 205 | return m_pitEntries; |
| 206 | } |
| 207 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 208 | inline const std::vector<shared_ptr<pit::Entry> >& |
| 209 | Entry::getPitEntries() const |
| 210 | { |
| 211 | return m_pitEntries; |
| 212 | } |
| 213 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 214 | inline shared_ptr<measurements::Entry> |
| 215 | Entry::getMeasurementsEntry() const |
| 216 | { |
| 217 | return m_measurementsEntry; |
| 218 | } |
| 219 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 220 | inline shared_ptr<strategy_choice::Entry> |
| 221 | Entry::getStrategyChoiceEntry() const |
| 222 | { |
| 223 | return m_strategyChoiceEntry; |
| 224 | } |
| 225 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 226 | } // namespace name_tree |
| 227 | } // namespace nfd |
| 228 | |
| 229 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |