strategy-choice.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, 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.
10  *
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/>.
24  */
25 
26 #ifndef NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
27 #define NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
28 
30 #include "name-tree.hpp"
31 
32 #include <boost/range/adaptor/transformed.hpp>
33 
34 namespace nfd {
35 
36 class Forwarder;
37 
38 namespace strategy_choice {
39 
51 class StrategyChoice : noncopyable
52 {
53 public:
54  explicit
55  StrategyChoice(Forwarder& forwarder);
56 
57  size_t
58  size() const
59  {
60  return m_nItems;
61  }
62 
67  void
68  setDefaultStrategy(const Name& strategyName);
69 
70 public: // Strategy Choice table
72  {
73  public:
74  explicit
75  operator bool() const
76  {
77  return m_status == OK;
78  }
79 
80  bool
81  isRegistered() const
82  {
83  return m_status == OK || m_status == EXCEPTION;
84  }
85 
88  int
89  getStatusCode() const
90  {
91  return static_cast<int>(m_status);
92  }
93 
94  private:
95  enum Status {
96  OK = 200,
97  NOT_REGISTERED = 404,
98  EXCEPTION = 409,
99  DEPTH_EXCEEDED = 414,
100  };
101 
102  // implicitly constructible from Status
103  InsertResult(Status status, const std::string& exceptionMessage = "");
104 
105  private:
106  Status m_status;
107  std::string m_exceptionMessage;
108 
109  friend StrategyChoice;
110  friend std::ostream& operator<<(std::ostream&, const InsertResult&);
111  };
112 
119  InsertResult
120  insert(const Name& prefix, const Name& strategyName);
121 
125  void
126  erase(const Name& prefix);
127 
131  std::pair<bool, Name>
132  get(const Name& prefix) const;
133 
134 public: // effective strategy
137  fw::Strategy&
138  findEffectiveStrategy(const Name& prefix) const;
139 
144  fw::Strategy&
145  findEffectiveStrategy(const pit::Entry& pitEntry) const;
146 
151  fw::Strategy&
152  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
153 
154 public: // enumeration
155  using Range = boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range>;
156  using const_iterator = boost::range_iterator<Range>::type;
157 
164  begin() const
165  {
166  return this->getRange().begin();
167  }
168 
173  end() const
174  {
175  return this->getRange().end();
176  }
177 
178 private:
179  void
180  changeStrategy(Entry& entry,
181  fw::Strategy& oldStrategy,
182  fw::Strategy& newStrategy);
183 
186  template<typename K>
187  fw::Strategy&
188  findEffectiveStrategyImpl(const K& key) const;
189 
190  Range
191  getRange() const;
192 
193 private:
194  Forwarder& m_forwarder;
195  NameTree& m_nameTree;
196  size_t m_nItems = 0;
197 };
198 
199 std::ostream&
200 operator<<(std::ostream& os, const StrategyChoice::InsertResult& res);
201 
202 } // namespace strategy_choice
203 
204 using strategy_choice::StrategyChoice;
205 
206 } // namespace nfd
207 
208 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
Main class of NFD's forwarding engine.
Definition: forwarder.hpp:54
Base class of all forwarding strategies.
Definition: strategy.hpp:46
Represents an entry in the Measurements table.
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:37
Represents an entry in the Interest table (PIT).
Definition: pit-entry.hpp:197
Represents an entry in the Strategy Choice table.
int getStatusCode() const
Get a status code for use in management command response.
friend std::ostream & operator<<(std::ostream &, const InsertResult &)
Represents the Strategy Choice table.
void erase(const Name &prefix)
Make prefix to inherit strategy from its parent.
boost::range_iterator< Range >::type const_iterator
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
InsertResult insert(const Name &prefix, const Name &strategyName)
Set strategy of prefix to be strategyName.
void setDefaultStrategy(const Name &strategyName)
Set the default strategy.
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
Get effective strategy for prefix.
std::pair< bool, Name > get(const Name &prefix) const
Get strategy Name of prefix.
boost::iterator_range< Iterator > Range
A forward range of name tree entries.
std::ostream & operator<<(std::ostream &os, const StrategyChoice::InsertResult &res)
-status-http-server
Definition: common.hpp:71