NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2019, 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 class StrategyChoice;
110  friend std::ostream& operator<<(std::ostream&, const InsertResult&);
111  };
112 
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  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
156  typedef boost::range_iterator<Range>::type const_iterator;
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 
205 
206 } // namespace nfd
207 
208 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
name-tree.hpp
nfd::strategy_choice::StrategyChoice::size
size_t size() const
Definition: strategy-choice.hpp:58
nfd::name_tree::NameTree
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:37
nfd::strategy_choice::StrategyChoice::InsertResult
Definition: strategy-choice.hpp:72
nfd::strategy_choice::StrategyChoice::Range
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
Definition: strategy-choice.hpp:155
nfd::name_tree::Range
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
Definition: name-tree-iterator.hpp:212
nfd::strategy_choice::StrategyChoice::end
const_iterator end() const
Definition: strategy-choice.hpp:173
nfd::strategy_choice::StrategyChoice::InsertResult::operator<<
friend std::ostream & operator<<(std::ostream &, const InsertResult &)
Definition: strategy-choice.cpp:124
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::strategy_choice::StrategyChoice::findEffectiveStrategy
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
Get effective strategy for prefix.
Definition: strategy-choice.cpp:191
nfd::strategy_choice::StrategyChoice::const_iterator
boost::range_iterator< Range >::type const_iterator
Definition: strategy-choice.hpp:156
nfd::strategy_choice::operator<<
std::ostream & operator<<(std::ostream &os, const StrategyChoice::InsertResult &res)
Definition: strategy-choice.cpp:124
nfd::strategy_choice::StrategyChoice::InsertResult::isRegistered
bool isRegistered() const
Definition: strategy-choice.hpp:81
nfd::pit::Entry
An Interest table entry.
Definition: pit-entry.hpp:59
nfd::strategy_choice::StrategyChoice::setDefaultStrategy
void setDefaultStrategy(const Name &strategyName)
Set the default strategy.
Definition: strategy-choice.cpp:57
nfd::strategy_choice::StrategyChoice::erase
void erase(const Name &prefix)
Make prefix to inherit strategy from its parent.
Definition: strategy-choice.cpp:141
nfd::strategy_choice::Entry
Represents a Strategy Choice entry.
Definition: strategy-choice-entry.hpp:46
nfd::fw::Strategy
represents a forwarding strategy
Definition: strategy.hpp:38
nfd::strategy_choice::StrategyChoice::begin
const_iterator begin() const
Definition: strategy-choice.hpp:164
nfd::Forwarder
Main class of NFD's forwarding engine.
Definition: forwarder.hpp:52
nfd::strategy_choice::StrategyChoice::InsertResult::getStatusCode
int getStatusCode() const
Get a status code for use in management command response.
Definition: strategy-choice.hpp:89
nfd::strategy_choice::StrategyChoice::StrategyChoice
StrategyChoice(Forwarder &forwarder)
Definition: strategy-choice.cpp:50
nfd::Forwarder
Forwarder
Definition: forwarder.cpp:41
nfd::measurements::Entry
Represents a Measurements entry.
Definition: measurements-entry.hpp:42
nfd::strategy_choice::StrategyChoice
Represents the Strategy Choice table.
Definition: strategy-choice.hpp:52
strategy-choice-entry.hpp
nfd::strategy_choice::StrategyChoice::get
std::pair< bool, Name > get(const Name &prefix) const
Get strategy Name of prefix.
Definition: strategy-choice.cpp:166
nfd::strategy_choice::StrategyChoice::insert
InsertResult insert(const Name &prefix, const Name &strategyName)
Set strategy of prefix to be strategyName.
Definition: strategy-choice.cpp:71
nfd::strategy_choice::StrategyChoice
StrategyChoice
Definition: strategy-choice.cpp:40