30 #include <ndn-cxx/lp/tags.hpp> 42 const std::string DEFAULT_POLICY =
"priority_fifo";
49 m_policy->setLimit(nMaxPackets);
55 m_policy->setLimit(nMaxPackets);
61 return m_policy->getLimit();
67 BOOST_ASSERT(policy !=
nullptr);
68 BOOST_ASSERT(m_policy !=
nullptr);
69 size_t limit = m_policy->getLimit();
70 this->setPolicyImpl(std::move(policy));
71 m_policy->setLimit(limit);
79 if (m_policy->getLimit() == 0) {
88 if (policy == lp::CachePolicyType::NO_CACHE) {
93 bool isNewEntry =
false;
96 std::tie(it, isNewEntry) = m_table.insert(
EntryImpl(data.shared_from_this(), isUnsolicited));
107 m_policy->afterRefresh(it);
110 m_policy->afterInsert(it);
119 BOOST_ASSERT(static_cast<bool>(hitCallback));
120 BOOST_ASSERT(static_cast<bool>(missCallback));
124 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
126 iterator first = m_table.lower_bound(prefix);
128 if (prefix.
size() > 0) {
134 match = this->findRightmost(interest, first, last);
137 match = this->findLeftmost(interest, first, last);
142 missCallback(interest);
146 m_policy->beforeUse(match);
147 hitCallback(interest, match->getData());
163 size_t interestNameLength = interest.
getName().
size();
164 for (
iterator right = last; right != first;) {
168 if (prev->getName().size() == interestNameLength) {
170 iterator matchExact = this->findRightmostAmongExact(interest, first, right);
171 return matchExact == right ? last : matchExact;
174 Name prefix = prev->getName().
getPrefix(interestNameLength + 1);
175 iterator left = m_table.lower_bound(prefix);
179 iterator match = this->findLeftmost(interest, left, right);
180 if (match != right) {
195 Cs::setPolicyImpl(unique_ptr<Policy> policy)
198 m_policy = std::move(policy);
199 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
iterator it) {
203 m_policy->setCs(
this);
204 BOOST_ASSERT(m_policy->getCs() ==
this);
const Name & getName() const
bool canSatisfy(const Interest &interest) const
determines whether Interest can be satisified by the stored Data
Name getSuccessor() const
Get the successor of a name.
implements the ContentStore
static unique_ptr< Policy > create(const std::string &policyName)
It find_last_if(It first, It last, Pred p)
represents an Interest packet
#define NFD_LOG_DEBUG(expression)
int getChildSelector() const
an Entry in ContentStore implementation
provides a tag type for simple types
Table::const_iterator iterator
#define NFD_LOG_TRACE(expression)
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Copyright (c) 2011-2015 Regents of the University of California.
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
Cs(size_t nMaxPackets=10)
bool isUnsolicited() const
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
unique_ptr< Policy > makeDefaultPolicy()
size_t size() const
Get number of components.
CachePolicyType
indicates the cache policy applied to a Data packet
Represents an absolute name.
std::function< void(const Interest &, const Data &data)> HitCallback
std::function< void(const Interest &)> MissCallback
NFD_ASSERT_FORWARD_ITERATOR(Cs::const_iterator)
const Name & getName() const
Get name.
void updateStaleTime()
refreshes stale time relative to current time
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
shared_ptr< T > getTag() const
get a tag item
#define NFD_LOG_INIT(name)
Represents a Data packet.