blob: 6cf5bd612087d81a349274e04d062402d2e1b2f8 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
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 **/
HYuana9b85752014-02-26 02:32:30 -060024
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 Shibb5105f2014-03-03 12:06:45 -070034#include "table/strategy-choice-entry.hpp"
HYuana9b85752014-02-26 02:32:30 -060035
36namespace nfd {
37
38class NameTree;
39
40namespace name_tree {
41
Haowei Yuane1079fc2014-03-08 14:41:25 -060042// Forward declarations
HYuana9b85752014-02-26 02:32:30 -060043class Node;
44class Entry;
45
46/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060047 * \brief Name Tree Node Class
HYuana9b85752014-02-26 02:32:30 -060048 */
49class Node
50{
51public:
52 Node();
53
54 ~Node();
55
56public:
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 Yuane1079fc2014-03-08 14:41:25 -060064 * \brief Name Tree Entry Class
HYuana9b85752014-02-26 02:32:30 -060065 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070066class Entry : public enable_shared_from_this<Entry>, noncopyable
HYuana9b85752014-02-26 02:32:30 -060067{
68 // Make private members accessible by Name Tree
69 friend class nfd::NameTree;
70public:
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 Yuane1079fc2014-03-08 14:41:25 -060093
94 bool
95 hasChildren() const;
96
Junxiao Shi40631842014-03-01 13:52:37 -070097 bool
98 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060099
100 void
Junxiao Shiefceadc2014-03-09 18:52:57 -0700101 setFibEntry(shared_ptr<fib::Entry> fibEntry);
HYuana9b85752014-02-26 02:32:30 -0600102
103 shared_ptr<fib::Entry>
104 getFibEntry() const;
105
HYuana9b85752014-02-26 02:32:30 -0600106 void
107 insertPitEntry(shared_ptr<pit::Entry> pit);
108
Haowei Yuane1079fc2014-03-08 14:41:25 -0600109 bool
110 hasPitEntries() const;
111
HYuana9b85752014-02-26 02:32:30 -0600112 std::vector<shared_ptr<pit::Entry> >&
113 getPitEntries();
114
Junxiao Shie349ea12014-03-12 01:32:42 -0700115 const std::vector<shared_ptr<pit::Entry> >&
116 getPitEntries() const;
117
HYuana9b85752014-02-26 02:32:30 -0600118 /**
Haowei Yuane1079fc2014-03-08 14:41:25 -0600119 * \brief Erase a PIT Entry
120 * \details The address of this PIT Entry is required
HYuana9b85752014-02-26 02:32:30 -0600121 */
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 Shibb5105f2014-03-03 12:06:45 -0700131 void
132 setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry);
133
134 shared_ptr<strategy_choice::Entry>
135 getStrategyChoiceEntry() const;
136
HYuana9b85752014-02-26 02:32:30 -0600137private:
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 Shibb5105f2014-03-03 12:06:45 -0700145 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600146
147 // get the Name Tree Node that is associated with this Name Tree Entry
148 Node* m_node;
149};
150
151inline const Name&
152Entry::getPrefix() const
153{
154 return m_prefix;
155}
156
157inline uint32_t
158Entry::getHash() const
159{
160 return m_hash;
161}
162
163inline shared_ptr<Entry>
164Entry::getParent() const
165{
166 return m_parent;
167}
168
169inline std::vector<shared_ptr<name_tree::Entry> >&
170Entry::getChildren()
171{
172 return m_children;
173}
174
Junxiao Shi40631842014-03-01 13:52:37 -0700175inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600176Entry::hasChildren() const
177{
178 return !m_children.empty();
179}
180
181inline bool
Junxiao Shi40631842014-03-01 13:52:37 -0700182Entry::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
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
HYuana9b85752014-02-26 02:32:30 -0600202inline std::vector<shared_ptr<pit::Entry> >&
203Entry::getPitEntries()
204{
205 return m_pitEntries;
206}
207
Junxiao Shie349ea12014-03-12 01:32:42 -0700208inline const std::vector<shared_ptr<pit::Entry> >&
209Entry::getPitEntries() const
210{
211 return m_pitEntries;
212}
213
HYuana9b85752014-02-26 02:32:30 -0600214inline shared_ptr<measurements::Entry>
215Entry::getMeasurementsEntry() const
216{
217 return m_measurementsEntry;
218}
219
Junxiao Shibb5105f2014-03-03 12:06:45 -0700220inline shared_ptr<strategy_choice::Entry>
221Entry::getStrategyChoiceEntry() const
222{
223 return m_strategyChoiceEntry;
224}
225
HYuana9b85752014-02-26 02:32:30 -0600226} // namespace name_tree
227} // namespace nfd
228
229#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP