blob: 4d7ad0c5232215cae218c409d5c663a2f163e116 [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 {
36
HYuana9b85752014-02-26 02:32:30 -060037namespace name_tree {
38
HYuana9b85752014-02-26 02:32:30 -060039class Node;
40class Entry;
Junxiao Shi2570f3e2016-07-27 02:48:29 +000041class NameTree;
HYuana9b85752014-02-26 02:32:30 -060042
43/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060044 * \brief Name Tree Node Class
HYuana9b85752014-02-26 02:32:30 -060045 */
46class Node
47{
48public:
49 Node();
50
51 ~Node();
52
53public:
54 // variables are in public as this is just a data structure
55 shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry)
56 Node* m_prev; // Previous Name Tree Node (to resolve hash collision)
57 Node* m_next; // Next Name Tree Node (to resolve hash collision)
58};
59
60/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060061 * \brief Name Tree Entry Class
HYuana9b85752014-02-26 02:32:30 -060062 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070063class Entry : public enable_shared_from_this<Entry>, noncopyable
HYuana9b85752014-02-26 02:32:30 -060064{
HYuana9b85752014-02-26 02:32:30 -060065public:
66 explicit
67 Entry(const Name& prefix);
68
HYuana9b85752014-02-26 02:32:30 -060069 const Name&
70 getPrefix() const;
71
72 void
Haowei Yuanf52dac72014-03-24 23:35:03 -050073 setHash(size_t hash);
HYuana9b85752014-02-26 02:32:30 -060074
Haowei Yuanf52dac72014-03-24 23:35:03 -050075 size_t
HYuana9b85752014-02-26 02:32:30 -060076 getHash() const;
77
78 void
79 setParent(shared_ptr<Entry> parent);
80
81 shared_ptr<Entry>
82 getParent() const;
83
Junxiao Shi2570f3e2016-07-27 02:48:29 +000084 std::vector<shared_ptr<Entry>>&
HYuana9b85752014-02-26 02:32:30 -060085 getChildren();
Haowei Yuane1079fc2014-03-08 14:41:25 -060086
87 bool
88 hasChildren() const;
89
Junxiao Shi40631842014-03-01 13:52:37 -070090 bool
91 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060092
Junxiao Shiee5a4442014-07-27 17:13:43 -070093public: // attached table entries
HYuana9b85752014-02-26 02:32:30 -060094 void
Junxiao Shia6de4292016-07-12 02:08:10 +000095 setFibEntry(unique_ptr<fib::Entry> fibEntry);
HYuana9b85752014-02-26 02:32:30 -060096
Junxiao Shia6de4292016-07-12 02:08:10 +000097 fib::Entry*
HYuana9b85752014-02-26 02:32:30 -060098 getFibEntry() const;
99
HYuana9b85752014-02-26 02:32:30 -0600100 void
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700101 insertPitEntry(shared_ptr<pit::Entry> pitEntry);
102
103 void
104 erasePitEntry(shared_ptr<pit::Entry> pitEntry);
HYuana9b85752014-02-26 02:32:30 -0600105
Haowei Yuane1079fc2014-03-08 14:41:25 -0600106 bool
107 hasPitEntries() const;
108
Junxiao Shib184e532016-05-26 18:09:57 +0000109 const std::vector<shared_ptr<pit::Entry>>&
Junxiao Shie349ea12014-03-12 01:32:42 -0700110 getPitEntries() const;
111
HYuana9b85752014-02-26 02:32:30 -0600112 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000113 setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry);
HYuana9b85752014-02-26 02:32:30 -0600114
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000115 measurements::Entry*
HYuana9b85752014-02-26 02:32:30 -0600116 getMeasurementsEntry() const;
117
Junxiao Shibb5105f2014-03-03 12:06:45 -0700118 void
Junxiao Shiff10da62016-07-13 17:57:43 +0000119 setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700120
Junxiao Shiff10da62016-07-13 17:57:43 +0000121 strategy_choice::Entry*
Junxiao Shibb5105f2014-03-03 12:06:45 -0700122 getStrategyChoiceEntry() const;
123
HYuana9b85752014-02-26 02:32:30 -0600124private:
Haowei Yuanf52dac72014-03-24 23:35:03 -0500125 // Benefits of storing m_hash
126 // 1. m_hash is compared before m_prefix is compared
127 // 2. fast hash table resize support
128 size_t m_hash;
HYuana9b85752014-02-26 02:32:30 -0600129 Name m_prefix;
130 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
131 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
Junxiao Shia6de4292016-07-12 02:08:10 +0000132 unique_ptr<fib::Entry> m_fibEntry;
HYuana9b85752014-02-26 02:32:30 -0600133 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000134 unique_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shiff10da62016-07-13 17:57:43 +0000135 unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600136
137 // get the Name Tree Node that is associated with this Name Tree Entry
138 Node* m_node;
Haowei Yuanf52dac72014-03-24 23:35:03 -0500139
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
Haowei Yuanf52dac72014-03-24 23:35:03 -0500150inline size_t
HYuana9b85752014-02-26 02:32:30 -0600151Entry::getHash() const
152{
153 return m_hash;
154}
155
Haowei Yuanf52dac72014-03-24 23:35:03 -0500156inline void
157Entry::setHash(size_t hash)
158{
159 m_hash = hash;
160}
161
HYuana9b85752014-02-26 02:32:30 -0600162inline shared_ptr<Entry>
163Entry::getParent() const
164{
165 return m_parent;
166}
167
Haowei Yuanf52dac72014-03-24 23:35:03 -0500168inline void
169Entry::setParent(shared_ptr<Entry> parent)
170{
171 m_parent = parent;
172}
173
HYuana9b85752014-02-26 02:32:30 -0600174inline std::vector<shared_ptr<name_tree::Entry> >&
175Entry::getChildren()
176{
177 return m_children;
178}
179
Junxiao Shi40631842014-03-01 13:52:37 -0700180inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600181Entry::hasChildren() const
182{
183 return !m_children.empty();
184}
185
Junxiao Shia6de4292016-07-12 02:08:10 +0000186inline fib::Entry*
HYuana9b85752014-02-26 02:32:30 -0600187Entry::getFibEntry() const
188{
Junxiao Shia6de4292016-07-12 02:08:10 +0000189 return m_fibEntry.get();
HYuana9b85752014-02-26 02:32:30 -0600190}
191
Haowei Yuane1079fc2014-03-08 14:41:25 -0600192inline bool
193Entry::hasPitEntries() const
194{
195 return !m_pitEntries.empty();
196}
197
Junxiao Shib184e532016-05-26 18:09:57 +0000198inline const std::vector<shared_ptr<pit::Entry>>&
Junxiao Shie349ea12014-03-12 01:32:42 -0700199Entry::getPitEntries() const
200{
201 return m_pitEntries;
202}
203
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000204inline measurements::Entry*
HYuana9b85752014-02-26 02:32:30 -0600205Entry::getMeasurementsEntry() const
206{
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000207 return m_measurementsEntry.get();
HYuana9b85752014-02-26 02:32:30 -0600208}
209
Junxiao Shiff10da62016-07-13 17:57:43 +0000210inline strategy_choice::Entry*
Junxiao Shibb5105f2014-03-03 12:06:45 -0700211Entry::getStrategyChoiceEntry() const
212{
Junxiao Shiff10da62016-07-13 17:57:43 +0000213 return m_strategyChoiceEntry.get();
Junxiao Shibb5105f2014-03-03 12:06:45 -0700214}
215
HYuana9b85752014-02-26 02:32:30 -0600216} // namespace name_tree
217} // namespace nfd
218
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700219#endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP