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 | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 29 | #include "name-tree-hashtable.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 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 38 | /** \brief an entry in the name tree |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 39 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 40 | class Entry : public enable_shared_from_this<Entry>, noncopyable |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 41 | { |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 42 | public: |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 43 | Entry(const Name& prefix, Node* node); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 44 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 45 | const Name& |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 46 | getName() const |
| 47 | { |
| 48 | return m_name; |
| 49 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 50 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 51 | /// \deprecated |
| 52 | const Name& |
| 53 | getPrefix() const |
| 54 | { |
| 55 | return this->getName(); |
| 56 | } |
| 57 | |
| 58 | /** \return entry of getName().getPrefix(-1) |
| 59 | * \retval nullptr this entry is the root entry, i.e. getName() == Name() |
| 60 | */ |
| 61 | Entry* |
| 62 | getParent() const |
| 63 | { |
| 64 | return m_parent; |
| 65 | } |
| 66 | |
| 67 | /** \brief set parent of this entry |
| 68 | * \param entry entry of getName().getPrefix(-1) |
| 69 | * \pre getParent() == nullptr |
| 70 | * \post getParent() == &entry |
| 71 | * \post entry.getChildren() contains this |
| 72 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 73 | void |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 74 | setParent(Entry& entry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 75 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 76 | /** \brief unset parent of this entry |
| 77 | * \post getParent() == nullptr |
| 78 | * \post parent.getChildren() does not contain this |
| 79 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 80 | void |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 81 | unsetParent(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 82 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 83 | /** \retval true this entry has at least one child |
| 84 | * \retval false this entry has no children |
| 85 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 86 | bool |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 87 | hasChildren() const |
| 88 | { |
| 89 | return !this->getChildren().empty(); |
| 90 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 91 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 92 | /** \return children of this entry |
| 93 | */ |
| 94 | const std::vector<Entry*>& |
| 95 | getChildren() const |
| 96 | { |
| 97 | return m_children; |
| 98 | } |
| 99 | |
| 100 | /** \retval true this entry has no children and no table entries |
| 101 | * \retval false this entry has child or attached table entry |
| 102 | */ |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 103 | bool |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 104 | isEmpty() const |
| 105 | { |
| 106 | return !this->hasChildren() && !this->hasTableEntries(); |
| 107 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 108 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 109 | public: // attached table entries |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 110 | /** \retval true at least one table entries is attached |
| 111 | * \retval false no table entry is attached |
| 112 | */ |
| 113 | bool |
| 114 | hasTableEntries() const; |
| 115 | |
| 116 | fib::Entry* |
| 117 | getFibEntry() const |
| 118 | { |
| 119 | return m_fibEntry.get(); |
| 120 | } |
| 121 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 122 | void |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 123 | setFibEntry(unique_ptr<fib::Entry> fibEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 124 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 125 | bool |
| 126 | hasPitEntries() const |
| 127 | { |
| 128 | return !this->getPitEntries().empty(); |
| 129 | } |
| 130 | |
| 131 | const std::vector<shared_ptr<pit::Entry>>& |
| 132 | getPitEntries() const |
| 133 | { |
| 134 | return m_pitEntries; |
| 135 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 136 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 137 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 138 | insertPitEntry(shared_ptr<pit::Entry> pitEntry); |
| 139 | |
| 140 | void |
| 141 | erasePitEntry(shared_ptr<pit::Entry> pitEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 142 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 143 | measurements::Entry* |
| 144 | getMeasurementsEntry() const |
| 145 | { |
| 146 | return m_measurementsEntry.get(); |
| 147 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 148 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 149 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 150 | setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 151 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 152 | strategy_choice::Entry* |
| 153 | getStrategyChoiceEntry() const |
| 154 | { |
| 155 | return m_strategyChoiceEntry.get(); |
| 156 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 157 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 158 | void |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 159 | setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 160 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 161 | private: |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 162 | Name m_name; |
| 163 | Node* m_node; |
| 164 | Entry* m_parent; |
| 165 | std::vector<Entry*> m_children; |
| 166 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 167 | unique_ptr<fib::Entry> m_fibEntry; |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame] | 168 | std::vector<shared_ptr<pit::Entry>> m_pitEntries; |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 169 | unique_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 170 | unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 171 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame^] | 172 | friend Node* getNode(const Entry& entry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 173 | }; |
| 174 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 175 | } // namespace name_tree |
| 176 | } // namespace nfd |
| 177 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 178 | #endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP |