blob: d0e358772181d01f0976eb14dbd41efc2d1c1494 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiee5a4442014-07-27 17:13:43 -07003 * 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 * 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
29#include "common.hpp"
30#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 {
36
37class NameTree;
38
39namespace name_tree {
40
Haowei Yuane1079fc2014-03-08 14:41:25 -060041// Forward declarations
HYuana9b85752014-02-26 02:32:30 -060042class Node;
43class Entry;
44
45/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060046 * \brief Name Tree Node Class
HYuana9b85752014-02-26 02:32:30 -060047 */
48class Node
49{
50public:
51 Node();
52
53 ~Node();
54
55public:
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 Yuane1079fc2014-03-08 14:41:25 -060063 * \brief Name Tree Entry Class
HYuana9b85752014-02-26 02:32:30 -060064 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070065class Entry : public enable_shared_from_this<Entry>, noncopyable
HYuana9b85752014-02-26 02:32:30 -060066{
HYuana9b85752014-02-26 02:32:30 -060067public:
68 explicit
69 Entry(const Name& prefix);
70
71 ~Entry();
72
73 const Name&
74 getPrefix() const;
75
76 void
Haowei Yuanf52dac72014-03-24 23:35:03 -050077 setHash(size_t hash);
HYuana9b85752014-02-26 02:32:30 -060078
Haowei Yuanf52dac72014-03-24 23:35:03 -050079 size_t
HYuana9b85752014-02-26 02:32:30 -060080 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 Yuane1079fc2014-03-08 14:41:25 -060090
91 bool
92 hasChildren() const;
93
Junxiao Shi40631842014-03-01 13:52:37 -070094 bool
95 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060096
Junxiao Shiee5a4442014-07-27 17:13:43 -070097public: // attached table entries
HYuana9b85752014-02-26 02:32:30 -060098 void
Junxiao Shiefceadc2014-03-09 18:52:57 -070099 setFibEntry(shared_ptr<fib::Entry> fibEntry);
HYuana9b85752014-02-26 02:32:30 -0600100
101 shared_ptr<fib::Entry>
102 getFibEntry() const;
103
HYuana9b85752014-02-26 02:32:30 -0600104 void
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700105 insertPitEntry(shared_ptr<pit::Entry> pitEntry);
106
107 void
108 erasePitEntry(shared_ptr<pit::Entry> pitEntry);
HYuana9b85752014-02-26 02:32:30 -0600109
Haowei Yuane1079fc2014-03-08 14:41:25 -0600110 bool
111 hasPitEntries() const;
112
Junxiao Shie349ea12014-03-12 01:32:42 -0700113 const std::vector<shared_ptr<pit::Entry> >&
114 getPitEntries() const;
115
HYuana9b85752014-02-26 02:32:30 -0600116 void
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700117 setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry);
HYuana9b85752014-02-26 02:32:30 -0600118
119 shared_ptr<measurements::Entry>
120 getMeasurementsEntry() const;
121
Junxiao Shibb5105f2014-03-03 12:06:45 -0700122 void
123 setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry);
124
125 shared_ptr<strategy_choice::Entry>
126 getStrategyChoiceEntry() const;
127
HYuana9b85752014-02-26 02:32:30 -0600128private:
Haowei Yuanf52dac72014-03-24 23:35:03 -0500129 // 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;
HYuana9b85752014-02-26 02:32:30 -0600133 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 Shibb5105f2014-03-03 12:06:45 -0700139 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600140
141 // get the Name Tree Node that is associated with this Name Tree Entry
142 Node* m_node;
Haowei Yuanf52dac72014-03-24 23:35:03 -0500143
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700144 // Make private members accessible by Name Tree
145 friend class nfd::NameTree;
HYuana9b85752014-02-26 02:32:30 -0600146};
147
148inline const Name&
149Entry::getPrefix() const
150{
151 return m_prefix;
152}
153
Haowei Yuanf52dac72014-03-24 23:35:03 -0500154inline size_t
HYuana9b85752014-02-26 02:32:30 -0600155Entry::getHash() const
156{
157 return m_hash;
158}
159
Haowei Yuanf52dac72014-03-24 23:35:03 -0500160inline void
161Entry::setHash(size_t hash)
162{
163 m_hash = hash;
164}
165
HYuana9b85752014-02-26 02:32:30 -0600166inline shared_ptr<Entry>
167Entry::getParent() const
168{
169 return m_parent;
170}
171
Haowei Yuanf52dac72014-03-24 23:35:03 -0500172inline void
173Entry::setParent(shared_ptr<Entry> parent)
174{
175 m_parent = parent;
176}
177
HYuana9b85752014-02-26 02:32:30 -0600178inline std::vector<shared_ptr<name_tree::Entry> >&
179Entry::getChildren()
180{
181 return m_children;
182}
183
Junxiao Shi40631842014-03-01 13:52:37 -0700184inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600185Entry::hasChildren() const
186{
187 return !m_children.empty();
188}
189
HYuana9b85752014-02-26 02:32:30 -0600190inline shared_ptr<fib::Entry>
191Entry::getFibEntry() const
192{
193 return m_fibEntry;
194}
195
Haowei Yuane1079fc2014-03-08 14:41:25 -0600196inline bool
197Entry::hasPitEntries() const
198{
199 return !m_pitEntries.empty();
200}
201
Junxiao Shie349ea12014-03-12 01:32:42 -0700202inline const std::vector<shared_ptr<pit::Entry> >&
203Entry::getPitEntries() const
204{
205 return m_pitEntries;
206}
207
HYuana9b85752014-02-26 02:32:30 -0600208inline shared_ptr<measurements::Entry>
209Entry::getMeasurementsEntry() const
210{
211 return m_measurementsEntry;
212}
213
Junxiao Shibb5105f2014-03-03 12:06:45 -0700214inline shared_ptr<strategy_choice::Entry>
215Entry::getStrategyChoiceEntry() const
216{
217 return m_strategyChoiceEntry;
218}
219
HYuana9b85752014-02-26 02:32:30 -0600220} // namespace name_tree
221} // namespace nfd
222
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700223#endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP