|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
36 namespace strategy_choice {
51 : m_forwarder(forwarder)
52 , m_nameTree(m_forwarder.getNameTree())
59 auto entry = make_unique<Entry>(
Name());
61 NFD_LOG_INFO(
"setDefaultStrategy " << entry->getStrategyInstanceName());
74 return InsertResult::DEPTH_EXCEEDED;
77 unique_ptr<Strategy> strategy;
81 catch (
const std::invalid_argument& e) {
82 NFD_LOG_ERROR(
"insert(" << prefix <<
"," << strategyName <<
") cannot create strategy: " << e.what());
86 if (strategy ==
nullptr) {
87 NFD_LOG_ERROR(
"insert(" << prefix <<
"," << strategyName <<
") strategy not registered");
88 return InsertResult::NOT_REGISTERED;
94 if (entry !=
nullptr) {
96 NFD_LOG_TRACE(
"insert(" << prefix <<
") not changing " << strategy->getInstanceName());
97 return InsertResult::OK;
101 " to " << strategy->getInstanceName());
105 auto newEntry = make_unique<Entry>(prefix);
106 entry = newEntry.get();
109 NFD_LOG_TRACE(
"insert(" << prefix <<
") new entry " << strategy->getInstanceName());
112 this->changeStrategy(*entry, *oldStrategy, *strategy);
114 return InsertResult::OK;
117 StrategyChoice::InsertResult::InsertResult(Status status,
const std::string& exceptionMessage)
119 , m_exceptionMessage(exceptionMessage)
126 switch (res.m_status) {
127 case StrategyChoice::InsertResult::OK:
129 case StrategyChoice::InsertResult::NOT_REGISTERED:
130 return os <<
"Strategy not registered";
131 case StrategyChoice::InsertResult::EXCEPTION:
132 return os <<
"Error instantiating strategy: " << res.m_exceptionMessage;
133 case StrategyChoice::InsertResult::DEPTH_EXCEEDED:
134 return os <<
"Prefix has too many components (limit is "
143 BOOST_ASSERT(prefix.
size() > 0);
146 if (nte ==
nullptr) {
151 if (entry ==
nullptr) {
158 this->changeStrategy(*entry, oldStrategy, parentStrategy);
165 std::pair<bool, Name>
169 if (nte ==
nullptr) {
174 if (entry ==
nullptr) {
183 StrategyChoice::findEffectiveStrategyImpl(
const K& key)
const
186 BOOST_ASSERT(nte !=
nullptr);
193 return this->findEffectiveStrategyImpl(prefix);
199 return this->findEffectiveStrategyImpl(pitEntry);
205 return this->findEffectiveStrategyImpl(measurementsEntry);
214 pitEntry->clearStrategyInfo();
215 for (
const auto& inRecord : pitEntry->getInRecords()) {
218 for (
const auto& outRecord : pitEntry->getOutRecords()) {
228 StrategyChoice::changeStrategy(Entry& entry,
Strategy& oldStrategy,
Strategy& newStrategy)
230 const Name& oldInstanceName = oldStrategy.getInstanceName();
231 const Name& newInstanceName = newStrategy.getInstanceName();
234 NFD_LOG_INFO(
"changeStrategy(" << entry.getPrefix() <<
") "
235 << oldInstanceName <<
" -> " << newInstanceName <<
" same-type");
239 NFD_LOG_INFO(
"changeStrategy(" << entry.getPrefix() <<
") "
240 << oldInstanceName <<
" -> " << newInstanceName);
244 const name_tree::Entry* rootNte = m_nameTree.
getEntry(entry);
245 BOOST_ASSERT(rootNte !=
nullptr);
247 [&rootNte] (
const name_tree::Entry& nte) -> std::pair<bool, bool> {
248 if (&nte == rootNte) {
251 if (nte.getStrategyChoiceEntry() !=
nullptr) {
252 return {false, false};
256 for (
const auto& nte : ntChanged) {
262 StrategyChoice::getRange()
const
265 boost::adaptors::transformed(name_tree::GetTableEntry<Entry>(
266 &name_tree::Entry::getStrategyChoiceEntry));
An entry in the name tree.
Entry * getEntry(const EntryT &tableEntry) const
NDN_CXX_ASSERT_FORWARD_ITERATOR(StrategyChoice::const_iterator)
Contains information about an Interest toward an outgoing face.
size_t size() const
Returns the number of components.
const std::vector< shared_ptr< pit::Entry > > & getPitEntries() const
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
size_t eraseIfEmpty(Entry *entry, bool canEraseAncestors=true)
Delete the entry if it is empty.
Entry & lookup(const Name &name, size_t prefixLen)
Find or insert an entry by name.
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
Entry * findExactMatch(const Name &name, size_t prefixLen=std::numeric_limits< size_t >::max()) const
Exact match lookup.
const Name & getInstanceName() const
Represents an absolute name.
const Name & getName() const
void clearStrategyInfo()
Clear all StrategyInfo items.
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getStrategyInstanceName() const
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
Get effective strategy for prefix.
boost::range_iterator< Range >::type const_iterator
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
std::ostream & operator<<(std::ostream &os, const StrategyChoice::InsertResult &res)
strategy_choice::Entry * getStrategyChoiceEntry() const
Contains information about an Interest from an incoming face.
void setDefaultStrategy(const Name &strategyName)
Set the default strategy.
measurements::Entry * getMeasurementsEntry() const
void erase(const Name &prefix)
Make prefix to inherit strategy from its parent.
Represents a Strategy Choice entry.
represents a forwarding strategy
Main class of NFD's forwarding engine.
StrategyChoice(Forwarder &forwarder)
Range partialEnumerate(const Name &prefix, const EntrySubTreeSelector &entrySubTreeSelector=AnyEntrySubTree()) const
Enumerate all entries under a prefix.
static constexpr size_t getMaxDepth()
Maximum depth of the name tree.
std::string to_string(const T &val)
Represents a Measurements entry.
fw::Strategy & getStrategy() const
static bool nteHasStrategyChoiceEntry(const name_tree::Entry &nte)
Represents the Strategy Choice table.
void setStrategy(unique_ptr< fw::Strategy > strategy)
Entry * findLongestPrefixMatch(const Name &name, const EntrySelector &entrySelector=AnyEntry()) const
Longest prefix matching.
std::pair< bool, Name > get(const Name &prefix) const
Get strategy Name of prefix.
void setStrategyChoiceEntry(unique_ptr< strategy_choice::Entry > strategyChoiceEntry)
InsertResult insert(const Name &prefix, const Name &strategyName)
Set strategy of prefix to be strategyName.
static void clearStrategyInfo(const name_tree::Entry &nte)
#define NFD_LOG_INIT(name)