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) {
85 shared_ptr<lp::CachePolicyTag> tag = data.getTag<lp::CachePolicyTag>();
87 lp::CachePolicyType policy = tag->get().getPolicy();
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));
122 const Name& prefix = interest.getName();
123 bool isRightmost = interest.getChildSelector() == 1;
124 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
126 iterator first = m_table.lower_bound(prefix);
128 if (prefix.size() > 0) {
129 last = m_table.lower_bound(prefix.getSuccessor());
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());
151 Cs::findLeftmost(
const Interest& interest,
iterator first,
iterator last)
const 157 Cs::findRightmost(
const Interest& interest,
iterator first,
iterator last)
const 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) {
189 Cs::findRightmostAmongExact(
const Interest& interest,
iterator first,
iterator last)
const 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);
void updateStaleTime()
refreshes stale time relative to current time
#define NFD_LOG_DEBUG(expression)
std::function< void(const Interest &, const Data &data)> HitCallback
It find_last_if(It first, It last, Pred p)
finds the last element satisfying a predicate
implements the ContentStore
static unique_ptr< Policy > create(const std::string &policyName)
Table::const_iterator iterator
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
unique_ptr< Policy > makeDefaultPolicy()
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
std::function< void(const Interest &)> MissCallback
NFD_ASSERT_FORWARD_ITERATOR(Cs::const_iterator)
an Entry in ContentStore implementation
#define NFD_LOG_INIT(name)
bool isUnsolicited() const
#define NFD_LOG_TRACE(expression)
bool canSatisfy(const Interest &interest) const
determines whether Interest can be satisified by the stored Data
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Cs(size_t nMaxPackets=10)