blob: 0a0e05e7a6a285559ecfe2c8effe6665b04087fd [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{
HYuana9b85752014-02-26 02:32:30 -060068public:
69 explicit
70 Entry(const Name& prefix);
71
72 ~Entry();
73
74 const Name&
75 getPrefix() const;
76
77 void
78 setHash(uint32_t hash);
79
80 uint32_t
81 getHash() const;
82
83 void
84 setParent(shared_ptr<Entry> parent);
85
86 shared_ptr<Entry>
87 getParent() const;
88
89 std::vector<shared_ptr<Entry> >&
90 getChildren();
Haowei Yuane1079fc2014-03-08 14:41:25 -060091
92 bool
93 hasChildren() const;
94
Junxiao Shi40631842014-03-01 13:52:37 -070095 bool
96 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060097
98 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:
129 uint32_t m_hash;
130 Name m_prefix;
131 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
132 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
133 shared_ptr<fib::Entry> m_fibEntry;
134 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
135 shared_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700136 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600137
138 // get the Name Tree Node that is associated with this Name Tree Entry
139 Node* m_node;
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700140 // Make private members accessible by Name Tree
141 friend class nfd::NameTree;
HYuana9b85752014-02-26 02:32:30 -0600142};
143
144inline const Name&
145Entry::getPrefix() const
146{
147 return m_prefix;
148}
149
150inline uint32_t
151Entry::getHash() const
152{
153 return m_hash;
154}
155
156inline shared_ptr<Entry>
157Entry::getParent() const
158{
159 return m_parent;
160}
161
162inline std::vector<shared_ptr<name_tree::Entry> >&
163Entry::getChildren()
164{
165 return m_children;
166}
167
Junxiao Shi40631842014-03-01 13:52:37 -0700168inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600169Entry::hasChildren() const
170{
171 return !m_children.empty();
172}
173
174inline bool
Junxiao Shi40631842014-03-01 13:52:37 -0700175Entry::isEmpty() const
176{
177 return m_children.empty() &&
178 !static_cast<bool>(m_fibEntry) &&
179 m_pitEntries.empty() &&
180 !static_cast<bool>(m_measurementsEntry);
181}
182
HYuana9b85752014-02-26 02:32:30 -0600183inline shared_ptr<fib::Entry>
184Entry::getFibEntry() const
185{
186 return m_fibEntry;
187}
188
Haowei Yuane1079fc2014-03-08 14:41:25 -0600189inline bool
190Entry::hasPitEntries() const
191{
192 return !m_pitEntries.empty();
193}
194
Junxiao Shie349ea12014-03-12 01:32:42 -0700195inline const std::vector<shared_ptr<pit::Entry> >&
196Entry::getPitEntries() const
197{
198 return m_pitEntries;
199}
200
HYuana9b85752014-02-26 02:32:30 -0600201inline shared_ptr<measurements::Entry>
202Entry::getMeasurementsEntry() const
203{
204 return m_measurementsEntry;
205}
206
Junxiao Shibb5105f2014-03-03 12:06:45 -0700207inline shared_ptr<strategy_choice::Entry>
208Entry::getStrategyChoiceEntry() const
209{
210 return m_strategyChoiceEntry;
211}
212
HYuana9b85752014-02-26 02:32:30 -0600213} // namespace name_tree
214} // namespace nfd
215
216#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP