34 using strategy_choice::Entry;
40 : m_nameTree(nameTree)
43 this->setDefaultStrategy(defaultStrategy);
50 return m_strategyInstances.count(strategyName) > 0;
53 return static_cast<bool>(this->getStrategy(strategyName));
60 BOOST_ASSERT(static_cast<bool>(strategy));
61 const Name& strategyName = strategy->getName();
64 NFD_LOG_ERROR(
"install(" << strategyName <<
") duplicate strategyName");
68 m_strategyInstances[strategyName] = strategy;
73 StrategyChoice::getStrategy(
const Name& strategyName)
const 76 for (
auto it = m_strategyInstances.lower_bound(strategyName);
77 it != m_strategyInstances.end() && strategyName.
isPrefixOf(it->first); ++it) {
78 switch (it->first.size() - strategyName.
size()) {
80 return it->second.get();
82 candidate = it->second.get();
92 Strategy* strategy = this->getStrategy(strategyName);
93 if (strategy ==
nullptr) {
94 NFD_LOG_ERROR(
"insert(" << prefix <<
"," << strategyName <<
") strategy not installed");
98 shared_ptr<name_tree::Entry> nte = m_nameTree.
lookup(prefix);
99 shared_ptr<Entry> entry = nte->getStrategyChoiceEntry();
101 if (static_cast<bool>(entry)) {
102 if (entry->getStrategy().getName() == strategy->
getName()) {
106 oldStrategy = &entry->getStrategy();
108 " to " << strategy->
getName());
111 if (!static_cast<bool>(entry)) {
113 entry = make_shared<Entry>(prefix);
114 nte->setStrategyChoiceEntry(entry);
119 this->changeStrategy(*entry, *oldStrategy, *strategy);
120 entry->setStrategy(*strategy);
127 BOOST_ASSERT(prefix.
size() > 0);
129 shared_ptr<name_tree::Entry> nte = m_nameTree.
findExactMatch(prefix);
130 if (!static_cast<bool>(nte)) {
134 shared_ptr<Entry> entry = nte->getStrategyChoiceEntry();
135 if (!static_cast<bool>(entry)) {
139 Strategy& oldStrategy = entry->getStrategy();
142 this->changeStrategy(*entry, oldStrategy, parentStrategy);
144 nte->setStrategyChoiceEntry(shared_ptr<Entry>());
149 std::pair<bool, Name>
152 shared_ptr<name_tree::Entry> nte = m_nameTree.
findExactMatch(prefix);
153 if (!static_cast<bool>(nte)) {
154 return {
false,
Name() };
157 shared_ptr<Entry> entry = nte->getStrategyChoiceEntry();
158 if (!static_cast<bool>(entry)) {
159 return {
false,
Name() };
162 return {
true, entry->getStrategy().getName() };
173 BOOST_ASSERT(static_cast<bool>(nte));
174 return nte->getStrategyChoiceEntry()->getStrategy();
180 shared_ptr<strategy_choice::Entry> entry = nte->getStrategyChoiceEntry();
181 if (static_cast<bool>(entry))
182 return entry->getStrategy();
189 BOOST_ASSERT(static_cast<bool>(nte));
190 return nte->getStrategyChoiceEntry()->getStrategy();
196 shared_ptr<name_tree::Entry> nte = m_nameTree.
get(pitEntry);
198 BOOST_ASSERT(static_cast<bool>(nte));
205 shared_ptr<name_tree::Entry> nte = m_nameTree.
get(measurementsEntry);
207 BOOST_ASSERT(static_cast<bool>(nte));
212 StrategyChoice::setDefaultStrategy(shared_ptr<Strategy> strategy)
218 shared_ptr<name_tree::Entry> nte = m_nameTree.
lookup(
Name());
219 shared_ptr<Entry> entry = make_shared<Entry>(
Name());
220 nte->setStrategyChoiceEntry(entry);
222 NFD_LOG_INFO(
"setDefaultStrategy " << strategy->getName());
224 entry->setStrategy(*strategy);
232 for (
const shared_ptr<pit::Entry>& pitEntry : nte.
getPitEntries()) {
233 pitEntry->clearStrategyInfo();
234 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
237 for (
const pit::OutRecord& outRecord : pitEntry->getOutRecords()) {
251 if (&oldStrategy == &newStrategy) {
256 <<
" from " << oldStrategy.
getName()
257 <<
" to " << newStrategy.
getName());
264 if (&nte == rootNte) {
267 if (static_cast<bool>(nte.getStrategyChoiceEntry())) {
268 return {
false,
false};
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
const Name & getName() const
a Name that represent the Strategy program
bool eraseEntryIfEmpty(shared_ptr< name_tree::Entry > entry)
Delete a Name Tree Entry if this entry is empty.
StrategyChoice(NameTree &nameTree, shared_ptr< fw::Strategy > defaultStrategy)
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
contains information about an Interest from an incoming face
const Name & getPrefix() const
shared_ptr< name_tree::Entry > get(const fib::Entry &fibEntry) const
get NameTree entry from FIB entry
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
#define NFD_LOG_ERROR(expression)
const Name & getPrefix() const
shared_ptr< measurements::Entry > getMeasurementsEntry() const
const std::vector< shared_ptr< pit::Entry > > & getPitEntries() const
represents a Measurements entry
shared_ptr< name_tree::Entry > findLongestPrefixMatch(const Name &prefix, const name_tree::EntrySelector &entrySelector=name_tree::AnyEntry()) const
Longest prefix matching for the given name.
#define NFD_LOG_INFO(expression)
Copyright (c) 2011-2015 Regents of the University of California.
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
shared_ptr< name_tree::Entry > findExactMatch(const Name &prefix) const
Exact match lookup for the given name prefix.
Name abstraction to represent an absolute name.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
represents a Strategy Choice entry
bool install(shared_ptr< fw::Strategy > strategy)
install a strategy
const_iterator begin() const
shared_ptr< name_tree::Entry > lookup(const Name &prefix)
Look for the Name Tree Entry that contains this name prefix.
size_t size() const
Get the number of components.
represents a forwarding strategy
#define NFD_LOG_INIT(name)
#define NFD_LOG_TRACE(expression)
contains information about an Interest toward an outgoing face
boost::iterator_range< const_iterator > partialEnumerate(const Name &prefix, const name_tree::EntrySubTreeSelector &entrySubTreeSelector=name_tree::AnyEntrySubTree()) const
Enumerate all entries under a prefix, optionally filtered by an EntrySubTreeSelector.
boost::iterator_range< const_iterator > fullEnumerate(const name_tree::EntrySelector &entrySelector=name_tree::AnyEntry()) const
Enumerate all entries, optionally filtered by an EntrySelector.
static void clearStrategyInfo(const name_tree::Entry &nte)
shared_ptr< strategy_choice::Entry > getStrategyChoiceEntry() const