33 namespace strategy_choice {
46 : m_nameTree(nameTree)
49 this->setDefaultStrategy(std::move(defaultStrategy));
56 return m_strategyInstances.count(strategyName) > 0;
59 return this->getStrategy(strategyName) !=
nullptr;
63 std::pair<bool, Strategy*>
66 BOOST_ASSERT(strategy !=
nullptr);
67 Name strategyName = strategy->getName();
70 bool isInserted =
false;
72 std::tie(it, isInserted) = m_strategyInstances.emplace(strategyName, std::move(strategy));
75 NFD_LOG_ERROR(
"install(" << strategyName <<
") duplicate strategyName");
77 return std::make_pair(isInserted, it->second.get());
81 StrategyChoice::getStrategy(
const Name& strategyName)
const 84 for (
auto it = m_strategyInstances.lower_bound(strategyName);
85 it != m_strategyInstances.end() && strategyName.
isPrefixOf(it->first); ++it) {
86 switch (it->first.size() - strategyName.
size()) {
88 return it->second.get();
90 candidate = it->second.get();
100 Strategy* strategy = this->getStrategy(strategyName);
101 if (strategy ==
nullptr) {
102 NFD_LOG_ERROR(
"insert(" << prefix <<
"," << strategyName <<
") strategy not installed");
109 if (entry !=
nullptr) {
116 " to " << strategy->
getName());
119 if (entry ==
nullptr) {
121 auto newEntry = make_unique<Entry>(prefix);
122 entry = newEntry.get();
128 this->changeStrategy(*entry, *oldStrategy, *strategy);
136 BOOST_ASSERT(prefix.
size() > 0);
139 if (nte ==
nullptr) {
143 Entry* entry = nte->getStrategyChoiceEntry();
144 if (entry ==
nullptr) {
151 this->changeStrategy(*entry, oldStrategy, parentStrategy);
153 nte->setStrategyChoiceEntry(
nullptr);
158 std::pair<bool, Name>
162 if (nte ==
nullptr) {
163 return {
false,
Name()};
167 if (entry ==
nullptr) {
168 return {
false,
Name()};
176 StrategyChoice::findEffectiveStrategyImpl(
const K& key)
const 179 BOOST_ASSERT(nte !=
nullptr);
186 return this->findEffectiveStrategyImpl(prefix);
192 return this->findEffectiveStrategyImpl(pitEntry);
198 return this->findEffectiveStrategyImpl(measurementsEntry);
202 StrategyChoice::setDefaultStrategy(unique_ptr<Strategy> strategy)
204 bool isInstalled =
false;
206 std::tie(isInstalled, instance) = this->
install(std::move(strategy));
207 BOOST_ASSERT(isInstalled);
209 auto entry = make_unique<Entry>(
Name());
210 entry->setStrategy(*instance);
225 for (
const shared_ptr<pit::Entry>& pitEntry : nte.
getPitEntries()) {
226 pitEntry->clearStrategyInfo();
227 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
230 for (
const pit::OutRecord& outRecord : pitEntry->getOutRecords()) {
242 if (&oldStrategy == &newStrategy) {
247 <<
" from " << oldStrategy.
getName()
248 <<
" to " << newStrategy.
getName());
253 BOOST_ASSERT(rootNte !=
nullptr);
256 if (&nte == rootNte) {
259 if (nte.getStrategyChoiceEntry() !=
nullptr) {
260 return {
false,
false};
270 StrategyChoice::getRange()
const void setStrategy(fw::Strategy &strategy)
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
static void clearStrategyInfo(const name_tree::Entry &nte)
const std::vector< shared_ptr< pit::Entry > > & getPitEntries() const
Entry * findExactMatch(const Name &name) const
exact match lookup
contains information about an Interest from an incoming face
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
const Name & getPrefix() const
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
const Name & getName() const
#define NFD_LOG_INFO(expression)
std::pair< bool, fw::Strategy * > install(unique_ptr< fw::Strategy > strategy)
install a strategy
Entry * findLongestPrefixMatch(const Name &name, const EntrySelector &entrySelector=AnyEntry()) const
longest prefix matching
represents a Measurements entry
Range partialEnumerate(const Name &prefix, const EntrySubTreeSelector &entrySubTreeSelector=AnyEntrySubTree()) const
enumerate all entries under a prefix
Table::const_iterator iterator
measurements::Entry * getMeasurementsEntry() const
#define NFD_LOG_TRACE(expression)
#define NFD_LOG_ERROR(expression)
Copyright (c) 2011-2015 Regents of the University of California.
Entry & lookup(const Name &name)
find or insert an entry with specified name
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
void clearStrategyInfo()
clear all StrategyInfo items
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
Range fullEnumerate(const EntrySelector &entrySelector=AnyEntry()) const
enumerate all entries
size_t size() const
Get the number of components.
represents a forwarding strategy
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
size_t eraseIfEmpty(Entry *entry, bool canEraseAncestors=true)
delete the entry if it is empty
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
a common index structure for FIB, PIT, StrategyChoice, and Measurements
fw::Strategy & getStrategy() const
contains information about an Interest toward an outgoing face
Entry * getEntry(const ENTRY &tableEntry) const
strategy_choice::Entry * getStrategyChoiceEntry() const
#define NFD_LOG_INIT(name)
a functor to get a table entry from a name tree entry
static bool nteHasStrategyChoiceEntry(const name_tree::Entry &nte)
const Name & getName() const
void setStrategyChoiceEntry(unique_ptr< strategy_choice::Entry > strategyChoiceEntry)
StrategyChoice(NameTree &nameTree, unique_ptr< fw::Strategy > defaultStrategy)
an entry in the name tree