blob: 3df32aac45cfa12399525c3166b8ad400a54bab6 [file] [log] [blame]
Junxiao Shibb5105f2014-03-03 12:06:45 -07001/* -*- 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 **/
Junxiao Shibb5105f2014-03-03 12:06:45 -070024
25#ifndef NFD_TABLE_STRATEGY_CHOICE_HPP
26#define NFD_TABLE_STRATEGY_CHOICE_HPP
27
28#include "strategy-choice-entry.hpp"
29#include "name-tree.hpp"
30
31namespace nfd {
32
33class StrategyChoice : noncopyable
34{
35public:
36 StrategyChoice(NameTree& nameTree, shared_ptr<fw::Strategy> defaultStrategy);
37
38public: // available Strategy types
39 /** \return true if strategy is installed
40 */
41 bool
42 hasStrategy(const Name& strategyName) const;
43
44 /** \brief install a strategy
45 * \return true if installed; false if not installed due to duplicate strategyName
46 */
47 bool
48 install(shared_ptr<fw::Strategy> strategy);
49
50public: // Strategy Choice table
51 /** \brief set strategy of prefix to be strategyName
52 * \param strategyName the strategy to be used, must be installed
53 * \return true on success
54 */
55 bool
56 insert(const Name& prefix, const Name& strategyName);
57
58 /** \brief make prefix to inherit strategy from its parent
59 *
60 * not allowed for root prefix (ndn:/)
61 */
62 void
63 erase(const Name& prefix);
64
65 /** \brief get strategy Name of prefix
66 * \return strategyName at exact match, or nullptr
67 */
68 shared_ptr<const Name>
69 get(const Name& prefix) const;
70
71public: // effect strategy
72 /// get effective strategy for prefix
73 fw::Strategy&
74 findEffectiveStrategy(const Name& prefix) const;
75
76 /// get effective strategy for pitEntry
77 fw::Strategy&
78 findEffectiveStrategy(const pit::Entry& pitEntry) const;
79
Junxiao Shi7bb01512014-03-05 21:34:09 -070080 /// get effective strategy for measurementsEntry
81 fw::Strategy&
82 findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
83
Junxiao Shibb5105f2014-03-03 12:06:45 -070084 /// number of entries stored
85 size_t
86 size() const;
87
88private:
89 shared_ptr<fw::Strategy>
90 getStrategy(const Name& strategyName);
91
92 void
93 setDefaultStrategy(shared_ptr<fw::Strategy> strategy);
94
95 void
96 changeStrategy(shared_ptr<strategy_choice::Entry> entry,
97 shared_ptr<fw::Strategy> oldStrategy,
98 shared_ptr<fw::Strategy> newStrategy);
99
HangZhangcb4fc832014-03-11 16:57:11 +0800100 fw::Strategy&
101 findEffectiveStrategy(shared_ptr<name_tree::Entry> nameTreeEntry) const;
102
Junxiao Shibb5105f2014-03-03 12:06:45 -0700103private:
104 NameTree& m_nameTree;
105 size_t m_nItems;
106
107 typedef std::map<Name, shared_ptr<fw::Strategy> > StrategyInstanceTable;
108 StrategyInstanceTable m_strategyInstances;
109};
110
111inline size_t
112StrategyChoice::size() const
113{
114 return m_nItems;
115}
116
117} // namespace nfd
118
119#endif // NFD_TABLE_STRATEGY_CHOICE_HPP