NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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-2017, 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 
86  private:
87  enum Status {
88  OK,
89  NOT_REGISTERED,
90  EXCEPTION,
91  DEPTH_EXCEEDED
92  };
93 
94  // implicitly constructible from Status
95  InsertResult(Status status, const std::string& exceptionMessage = "");
96 
97  private:
98  Status m_status;
99  std::string m_exceptionMessage;
100 
101  friend class StrategyChoice;
102  friend std::ostream& operator<<(std::ostream&, const InsertResult&);
103  };
104 
112  insert(const Name& prefix, const Name& strategyName);
113 
118  void
119  erase(const Name& prefix);
120 
124  std::pair<bool, Name>
125  get(const Name& prefix) const;
126 
127 public: // effective strategy
130  fw::Strategy&
131  findEffectiveStrategy(const Name& prefix) const;
132 
137  fw::Strategy&
138  findEffectiveStrategy(const pit::Entry& pitEntry) const;
139 
144  fw::Strategy&
145  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
146 
147 public: // enumeration
148  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
149  typedef boost::range_iterator<Range>::type const_iterator;
150 
156  const_iterator
157  begin() const
158  {
159  return this->getRange().begin();
160  }
161 
165  const_iterator
166  end() const
167  {
168  return this->getRange().end();
169  }
170 
171 private:
172  void
173  changeStrategy(Entry& entry,
174  fw::Strategy& oldStrategy,
175  fw::Strategy& newStrategy);
176 
179  template<typename K>
180  fw::Strategy&
181  findEffectiveStrategyImpl(const K& key) const;
182 
183  Range
184  getRange() const;
185 
186 private:
187  Forwarder& m_forwarder;
188  NameTree& m_nameTree;
189  size_t m_nItems;
190 };
191 
192 std::ostream&
193 operator<<(std::ostream& os, const StrategyChoice::InsertResult& res);
194 
195 } // namespace strategy_choice
196 
198 
199 } // namespace nfd
200 
201 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
boost::range_iterator< Range >::type const_iterator
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
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
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
Represents an absolute name.
Definition: name.hpp:42
void setDefaultStrategy(const Name &strategyName)
set the default strategy
Forwarder
Definition: forwarder.cpp:38
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
represents the Strategy Choice table
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries