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; -*- */
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 namespace strategy_choice {
36 
48 class StrategyChoice : noncopyable
49 {
50 public:
51  StrategyChoice(NameTree& nameTree, unique_ptr<fw::Strategy> defaultStrategy);
52 
53  size_t
54  size() const
55  {
56  return m_nItems;
57  }
58 
59 public: // available Strategy types
65  bool
66  hasStrategy(const Name& strategyName, bool isExact = false) const;
67 
73  std::pair<bool, fw::Strategy*>
74  install(unique_ptr<fw::Strategy> strategy);
75 
76 public: // Strategy Choice table
87  bool
88  insert(const Name& prefix, const Name& strategyName);
89 
94  void
95  erase(const Name& prefix);
96 
100  std::pair<bool, Name>
101  get(const Name& prefix) const;
102 
103 public: // effective strategy
106  fw::Strategy&
107  findEffectiveStrategy(const Name& prefix) const;
108 
113  fw::Strategy&
114  findEffectiveStrategy(const pit::Entry& pitEntry) const;
115 
120  fw::Strategy&
121  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
122 
123 public: // enumeration
124  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
125  typedef boost::range_iterator<Range>::type const_iterator;
126 
132  const_iterator
133  begin() const
134  {
135  return this->getRange().begin();
136  }
137 
141  const_iterator
142  end() const
143  {
144  return this->getRange().end();
145  }
146 
147 private:
151  fw::Strategy*
152  getStrategy(const Name& strategyName) const;
153 
154  void
155  setDefaultStrategy(unique_ptr<fw::Strategy> strategy);
156 
157  void
158  changeStrategy(Entry& entry,
159  fw::Strategy& oldStrategy,
160  fw::Strategy& newStrategy);
161 
164  template<typename K>
165  fw::Strategy&
166  findEffectiveStrategyImpl(const K& key) const;
167 
168  Range
169  getRange() const;
170 
171 private:
172  NameTree& m_nameTree;
173  size_t m_nItems;
174 
175  typedef std::map<Name, unique_ptr<fw::Strategy>> StrategyInstanceTable;
176  StrategyInstanceTable m_strategyInstances;
177 };
178 
179 } // namespace strategy_choice
180 
182 
183 } // namespace nfd
184 
185 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
boost::range_iterator< Range >::type const_iterator
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
std::pair< bool, fw::Strategy * > install(unique_ptr< fw::Strategy > strategy)
install a strategy
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
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
Name abstraction to represent an absolute name.
Definition: name.hpp:46
represents a Strategy Choice entry
represents a forwarding strategy
Definition: strategy.hpp:38
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
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:36
represents the Strategy Choice table
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
StrategyChoice(NameTree &nameTree, unique_ptr< fw::Strategy > defaultStrategy)