blob: b0641d0a73d06823023a012843d5765ecf21fe55 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shib184e532016-05-26 18:09:57 +00003 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shiee5a4442014-07-27 17:13:43 -070024 */
HYuana9b85752014-02-26 02:32:30 -060025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
27#define NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
HYuana9b85752014-02-26 02:32:30 -060028
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
HYuana9b85752014-02-26 02:32:30 -060030#include "table/fib-entry.hpp"
31#include "table/pit-entry.hpp"
32#include "table/measurements-entry.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070033#include "table/strategy-choice-entry.hpp"
HYuana9b85752014-02-26 02:32:30 -060034
35namespace nfd {
HYuana9b85752014-02-26 02:32:30 -060036namespace name_tree {
37
HYuana9b85752014-02-26 02:32:30 -060038class Node;
39class Entry;
Junxiao Shi2570f3e2016-07-27 02:48:29 +000040class NameTree;
HYuana9b85752014-02-26 02:32:30 -060041
42/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060043 * \brief Name Tree Node Class
HYuana9b85752014-02-26 02:32:30 -060044 */
45class Node
46{
47public:
48 Node();
49
50 ~Node();
51
52public:
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 Yuane1079fc2014-03-08 14:41:25 -060060 * \brief Name Tree Entry Class
HYuana9b85752014-02-26 02:32:30 -060061 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070062class Entry : public enable_shared_from_this<Entry>, noncopyable
HYuana9b85752014-02-26 02:32:30 -060063{
HYuana9b85752014-02-26 02:32:30 -060064public:
65 explicit
66 Entry(const Name& prefix);
67
HYuana9b85752014-02-26 02:32:30 -060068 const Name&
69 getPrefix() const;
70
71 void
Haowei Yuanf52dac72014-03-24 23:35:03 -050072 setHash(size_t hash);
HYuana9b85752014-02-26 02:32:30 -060073
Haowei Yuanf52dac72014-03-24 23:35:03 -050074 size_t
HYuana9b85752014-02-26 02:32:30 -060075 getHash() const;
76
77 void
78 setParent(shared_ptr<Entry> parent);
79
80 shared_ptr<Entry>
81 getParent() const;
82
Junxiao Shi2570f3e2016-07-27 02:48:29 +000083 std::vector<shared_ptr<Entry>>&
HYuana9b85752014-02-26 02:32:30 -060084 getChildren();
Haowei Yuane1079fc2014-03-08 14:41:25 -060085
86 bool
87 hasChildren() const;
88
Junxiao Shi40631842014-03-01 13:52:37 -070089 bool
90 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060091
Junxiao Shiee5a4442014-07-27 17:13:43 -070092public: // attached table entries
HYuana9b85752014-02-26 02:32:30 -060093 void
Junxiao Shia6de4292016-07-12 02:08:10 +000094 setFibEntry(unique_ptr<fib::Entry> fibEntry);
HYuana9b85752014-02-26 02:32:30 -060095
Junxiao Shia6de4292016-07-12 02:08:10 +000096 fib::Entry*
HYuana9b85752014-02-26 02:32:30 -060097 getFibEntry() const;
98
HYuana9b85752014-02-26 02:32:30 -060099 void
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700100 insertPitEntry(shared_ptr<pit::Entry> pitEntry);
101
102 void
103 erasePitEntry(shared_ptr<pit::Entry> pitEntry);
HYuana9b85752014-02-26 02:32:30 -0600104
Haowei Yuane1079fc2014-03-08 14:41:25 -0600105 bool
106 hasPitEntries() const;
107
Junxiao Shib184e532016-05-26 18:09:57 +0000108 const std::vector<shared_ptr<pit::Entry>>&
Junxiao Shie349ea12014-03-12 01:32:42 -0700109 getPitEntries() const;
110
HYuana9b85752014-02-26 02:32:30 -0600111 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000112 setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry);
HYuana9b85752014-02-26 02:32:30 -0600113
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000114 measurements::Entry*
HYuana9b85752014-02-26 02:32:30 -0600115 getMeasurementsEntry() const;
116
Junxiao Shibb5105f2014-03-03 12:06:45 -0700117 void
Junxiao Shiff10da62016-07-13 17:57:43 +0000118 setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700119
Junxiao Shiff10da62016-07-13 17:57:43 +0000120 strategy_choice::Entry*
Junxiao Shibb5105f2014-03-03 12:06:45 -0700121 getStrategyChoiceEntry() const;
122
HYuana9b85752014-02-26 02:32:30 -0600123private:
Haowei Yuanf52dac72014-03-24 23:35:03 -0500124 // 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;
HYuana9b85752014-02-26 02:32:30 -0600128 Name m_prefix;
129 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
Junxiao Shi029401f2016-08-05 12:55:14 +0000130 std::vector<shared_ptr<Entry>> m_children; // Children pointers.
Junxiao Shia6de4292016-07-12 02:08:10 +0000131 unique_ptr<fib::Entry> m_fibEntry;
Junxiao Shi029401f2016-08-05 12:55:14 +0000132 std::vector<shared_ptr<pit::Entry>> m_pitEntries;
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000133 unique_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shiff10da62016-07-13 17:57:43 +0000134 unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600135
136 // get the Name Tree Node that is associated with this Name Tree Entry
137 Node* m_node;
Haowei Yuanf52dac72014-03-24 23:35:03 -0500138
Junxiao Shi029401f2016-08-05 12:55:14 +0000139 friend class NameTree;
140 friend class FullEnumerationImpl;
141 friend class PartialEnumerationImpl;
142 friend class PrefixMatchImpl;
HYuana9b85752014-02-26 02:32:30 -0600143};
144
145inline const Name&
146Entry::getPrefix() const
147{
148 return m_prefix;
149}
150
Haowei Yuanf52dac72014-03-24 23:35:03 -0500151inline size_t
HYuana9b85752014-02-26 02:32:30 -0600152Entry::getHash() const
153{
154 return m_hash;
155}
156
Haowei Yuanf52dac72014-03-24 23:35:03 -0500157inline void
158Entry::setHash(size_t hash)
159{
160 m_hash = hash;
161}
162
HYuana9b85752014-02-26 02:32:30 -0600163inline shared_ptr<Entry>
164Entry::getParent() const
165{
166 return m_parent;
167}
168
Haowei Yuanf52dac72014-03-24 23:35:03 -0500169inline void
170Entry::setParent(shared_ptr<Entry> parent)
171{
172 m_parent = parent;
173}
174
Junxiao Shi029401f2016-08-05 12:55:14 +0000175inline std::vector<shared_ptr<name_tree::Entry>>&
HYuana9b85752014-02-26 02:32:30 -0600176Entry::getChildren()
177{
178 return m_children;
179}
180
Junxiao Shi40631842014-03-01 13:52:37 -0700181inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600182Entry::hasChildren() const
183{
184 return !m_children.empty();
185}
186
Junxiao Shia6de4292016-07-12 02:08:10 +0000187inline fib::Entry*
HYuana9b85752014-02-26 02:32:30 -0600188Entry::getFibEntry() const
189{
Junxiao Shia6de4292016-07-12 02:08:10 +0000190 return m_fibEntry.get();
HYuana9b85752014-02-26 02:32:30 -0600191}
192
Haowei Yuane1079fc2014-03-08 14:41:25 -0600193inline bool
194Entry::hasPitEntries() const
195{
196 return !m_pitEntries.empty();
197}
198
Junxiao Shib184e532016-05-26 18:09:57 +0000199inline const std::vector<shared_ptr<pit::Entry>>&
Junxiao Shie349ea12014-03-12 01:32:42 -0700200Entry::getPitEntries() const
201{
202 return m_pitEntries;
203}
204
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000205inline measurements::Entry*
HYuana9b85752014-02-26 02:32:30 -0600206Entry::getMeasurementsEntry() const
207{
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000208 return m_measurementsEntry.get();
HYuana9b85752014-02-26 02:32:30 -0600209}
210
Junxiao Shiff10da62016-07-13 17:57:43 +0000211inline strategy_choice::Entry*
Junxiao Shibb5105f2014-03-03 12:06:45 -0700212Entry::getStrategyChoiceEntry() const
213{
Junxiao Shiff10da62016-07-13 17:57:43 +0000214 return m_strategyChoiceEntry.get();
Junxiao Shibb5105f2014-03-03 12:06:45 -0700215}
216
HYuana9b85752014-02-26 02:32:30 -0600217} // namespace name_tree
218} // namespace nfd
219
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700220#endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP