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-2018, 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 
126  void
127  erase(const Name& prefix);
128 
132  std::pair<bool, Name>
133  get(const Name& prefix) const;
134 
135 public: // effective strategy
138  fw::Strategy&
139  findEffectiveStrategy(const Name& prefix) const;
140 
145  fw::Strategy&
146  findEffectiveStrategy(const pit::Entry& pitEntry) const;
147 
152  fw::Strategy&
153  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
154 
155 public: // enumeration
156  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
157  typedef boost::range_iterator<Range>::type const_iterator;
158 
165  begin() const
166  {
167  return this->getRange().begin();
168  }
169 
174  end() const
175  {
176  return this->getRange().end();
177  }
178 
179 private:
180  void
181  changeStrategy(Entry& entry,
182  fw::Strategy& oldStrategy,
183  fw::Strategy& newStrategy);
184 
187  template<typename K>
188  fw::Strategy&
189  findEffectiveStrategyImpl(const K& key) const;
190 
191  Range
192  getRange() const;
193 
194 private:
195  Forwarder& m_forwarder;
196  NameTree& m_nameTree;
197  size_t m_nItems;
198 };
199 
200 std::ostream&
201 operator<<(std::ostream& os, const StrategyChoice::InsertResult& res);
202 
203 } // namespace strategy_choice
204 
206 
207 } // namespace nfd
208 
209 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
int getStatusCode() const
get a status code for use in management command response
boost::range_iterator< Range >::type const_iterator
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
main class of NFD
Definition: forwarder.hpp:54
InsertResult insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
represents a Measurements entry
std::ostream & operator<<(std::ostream &os, const StrategyChoice::InsertResult &res)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:59
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
Represents an absolute name.
Definition: name.hpp:43
void setDefaultStrategy(const Name &strategyName)
set the default strategy
Forwarder
Definition: forwarder.cpp:40
friend std::ostream & operator<<(std::ostream &, const InsertResult &)
represents a Strategy Choice entry
represents a forwarding strategy
Definition: strategy.hpp:37
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:38
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
represents the Strategy Choice table