22 #ifndef NDN_MEMORY_CONTENT_CACHE_HPP
23 #define NDN_MEMORY_CONTENT_CACHE_HPP
27 #include "../face.hpp"
51 : impl_(
new Impl(face, cleanupIntervalMilliseconds))
72 (
const ptr_lib::shared_ptr<const Interest>& interest,
Face& face);
78 const ptr_lib::shared_ptr<const Interest>&
106 return nowMilliseconds >= timeoutTimeMilliseconds_;
110 ptr_lib::shared_ptr<const Interest> interest_;
130 : name_(data.
getName()), dataEncoding_(data.wireEncode())
152 typedef std::vector<ptr_lib::shared_ptr<const Content> > ContentList;
158 typedef func_lib::function<void
238 impl_->registerPrefix
239 (prefix, onRegisterFailed, onRegisterSuccess, onDataNotFound, flags,
270 impl_->setInterestFilter(filter, onDataNotFound);
298 impl_->setInterestFilter(prefix, onDataNotFound);
345 (
const ptr_lib::shared_ptr<const Interest>& interest,
Face& face)
347 impl_->storePendingInterest(interest, face);
375 std::vector<ptr_lib::shared_ptr<const PendingInterest> >& pendingInterests)
377 impl_->getPendingInterestsForName(name, pendingInterests);
396 std::vector<ptr_lib::shared_ptr<const PendingInterest> >& pendingInterests)
398 impl_->getPendingInterestsWithPrefix(prefix, pendingInterests);
414 impl_->setOnContentRemoved(onContentRemoved);
435 impl_->setMinimumCacheLifetime(minimumCacheLifetime);
444 class Impl :
public ptr_lib::enable_shared_from_this<Impl> {
483 (
const ptr_lib::shared_ptr<const Interest>& interest,
Face& face);
491 std::vector<ptr_lib::shared_ptr<const PendingInterest> >& pendingInterests);
496 std::vector<ptr_lib::shared_ptr<const PendingInterest> >& pendingInterests);
501 onContentRemoved_ = onContentRemoved;
510 minimumCacheLifetime_ = minimumCacheLifetime;
524 (
const ptr_lib::shared_ptr<const Name>& prefix,
525 const ptr_lib::shared_ptr<const Interest>& interest, Face& face,
526 uint64_t interestFilterId,
527 const ptr_lib::shared_ptr<const InterestFilter>& filter);
534 class StaleTimeContent :
public Content {
560 return cacheRemovalTimeMilliseconds_ <= nowMilliseconds;
573 return freshnessExpiryTimeMilliseconds_ > nowMilliseconds;
583 (
const ptr_lib::shared_ptr<const StaleTimeContent>& x,
584 const ptr_lib::shared_ptr<const StaleTimeContent>& y)
const
586 return x->cacheRemovalTimeMilliseconds_ < y->cacheRemovalTimeMilliseconds_;
618 storePendingInterestCallback
619 (
const ptr_lib::shared_ptr<const Name>& prefix,
620 const ptr_lib::shared_ptr<const Interest>& interest,
Face& face,
621 uint64_t interestFilterId,
622 const ptr_lib::shared_ptr<const InterestFilter>& filter)
630 std::map<std::string, OnInterestCallback> onDataNotFoundForPrefix_;
631 std::vector<uint64_t> interestFilterIdList_;
632 std::vector<uint64_t> registeredPrefixIdList_;
633 std::vector<ptr_lib::shared_ptr<const Content> > noStaleTimeCache_;
635 std::deque<ptr_lib::shared_ptr<const StaleTimeContent> > staleTimeCache_;
636 StaleTimeContent::Compare contentCompare_;
638 std::vector<ptr_lib::shared_ptr<const PendingInterest> > pendingInterestTable_;
641 bool isDoingCleanup_;
645 ndn::ptr_lib::shared_ptr<Impl> impl_;
void getPendingInterestsWithPrefix(const Name &prefix, std::vector< ptr_lib::shared_ptr< const PendingInterest > > &pendingInterests)
Remove timed-out pending interests, then for each pending interest which matches according to prefix...
Definition: memory-content-cache.hpp:395
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
PendingInterest(const ptr_lib::shared_ptr< const Interest > &interest, Face &face)
Create a new PendingInterest and set the timeoutTime_ based on the current time and the interest life...
Definition: memory-content-cache.cpp:344
A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data p...
Definition: memory-content-cache.hpp:38
void setInterestFilter(const InterestFilter &filter, const OnInterestCallback &onDataNotFound=OnInterestCallback())
Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answ...
Definition: memory-content-cache.hpp:267
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix, const ptr_lib::shared_ptr< const Interest > &interest, Face &face, uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filter)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:65
void setOnContentRemoved(const OnContentRemoved &onContentRemoved)
Set the OnContentRemoved callback to call when stale content is removed from the cache during cleanup...
Definition: memory-content-cache.hpp:412
void getPendingInterestsForName(const Name &name, std::vector< ptr_lib::shared_ptr< const PendingInterest > > &pendingInterests)
Remove timed-out pending interests, then for each pending interest which matches according to Interes...
Definition: memory-content-cache.hpp:374
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
void storePendingInterest(const ptr_lib::shared_ptr< const Interest > &interest, Face &face)
Store an interest from an OnInterest callback in the internal pending interest table (normally becaus...
Definition: memory-content-cache.hpp:345
Face & getFace() const
Return the face given to the constructor.
Definition: memory-content-cache.hpp:95
Compare shared_ptrs to Content based only on cacheRemovalTimeMilliseconds_.
Definition: memory-content-cache.hpp:579
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
Definition: forwarding-flags.hpp:35
bool isTimedOut(MillisecondsSince1970 nowMilliseconds) const
Check if this interest is timed out.
Definition: memory-content-cache.hpp:104
const ptr_lib::shared_ptr< const Interest > & getInterest() const
Return the interest given to the constructor.
Definition: memory-content-cache.hpp:79
const Name & getName() const
Get the content Name.
Definition: memory-content-cache.hpp:138
A PendingInterest holds an interest which onInterest received but could not satisfy.
Definition: memory-content-cache.hpp:61
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix, uint64_t registeredPrefixId)> OnRegisterSuccess
An OnRegisterSuccess function object is used to report when registerPrefix succeeds.
Definition: face.hpp:78
const Blob & getDataEncoding() const
Get the encoded content Data packet.
Definition: memory-content-cache.hpp:145
A Name::Component holds a read-only name component value.
Definition: name.hpp:45
void unregisterAll()
Call Face.unsetInterestFilter and Face.removeRegisteredPrefix for all the prefixes given to the setIn...
Definition: memory-content-cache.hpp:309
MemoryContentCache(Face *face, Milliseconds cleanupIntervalMilliseconds=1000.0)
Create a new MemoryContentCache to use the given Face.
Definition: memory-content-cache.hpp:50
Milliseconds getMinimumCacheLifetime()
Get the minimum lifetime before removing stale content from the cache.
Definition: memory-content-cache.hpp:422
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
void registerPrefix(const Name &prefix, const OnRegisterFailed &onRegisterFailed, const OnInterestCallback &onDataNotFound=OnInterestCallback(), const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer ...
Definition: memory-content-cache.hpp:192
const OnInterestCallback & getStorePendingInterest()
Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest...
Definition: memory-content-cache.hpp:358
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:119
void add(const Data &data)
Add the Data packet to the cache so that it is available to use to answer interests.
Definition: memory-content-cache.hpp:329
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:71
Content(const Data &data)
Create a new Content entry to hold data's name and wire encoding.
Definition: memory-content-cache.hpp:128
An InterestFilter holds a Name prefix and optional regex match expression for use in Face::setInteres...
Definition: interest-filter.hpp:33
MillisecondsSince1970 getTimeoutPeriodStart() const
Return the time when this pending interest entry was created (the time when the unsatisfied interest ...
Definition: memory-content-cache.hpp:89
Content is a private class to hold the name and encoding for each entry in the cache.
Definition: memory-content-cache.hpp:122
func_lib::function< void(const ptr_lib::shared_ptr< ContentList > &contentList)> OnContentRemoved
An OnContentRemoved function object is called when content is removed from the cache.
Definition: memory-content-cache.hpp:159
void setMinimumCacheLifetime(Milliseconds minimumCacheLifetime)
Set the minimum lifetime before removing stale content from the cache which can keep content in the c...
Definition: memory-content-cache.hpp:433