22 #ifndef NDN_MEMORY_CONTENT_CACHE_HPP
23 #define NDN_MEMORY_CONTENT_CACHE_HPP
27 #include "../face.hpp"
68 (
const ptr_lib::shared_ptr<const Interest>& interest,
Face& face);
74 const ptr_lib::shared_ptr<const Interest>&
102 return timeoutTimeMilliseconds_ >= 0.0 &&
103 nowMilliseconds >= timeoutTimeMilliseconds_;
107 ptr_lib::shared_ptr<const Interest> interest_;
192 onDataNotFoundForPrefix_[prefix.
toUri()] = onDataNotFound;
197 onRegisterSuccess, flags, wireFormat);
199 registeredPrefixIdList_.push_back(registeredPrefixId);
229 onDataNotFoundForPrefix_[filter.
getPrefix().
toUri()] = onDataNotFound;
231 (filter, func_lib::ref(*
this));
233 interestFilterIdList_.push_back(interestFilterId);
261 onDataNotFoundForPrefix_[prefix.
toUri()] = onDataNotFound;
263 (prefix, func_lib::ref(*
this));
265 interestFilterIdList_.push_back(interestFilterId);
311 (
const ptr_lib::shared_ptr<const Interest>& interest,
Face& face);
323 return storePendingInterestCallback_;
340 std::vector<ptr_lib::shared_ptr<const PendingInterest> >& pendingInterests);
353 (
const ptr_lib::shared_ptr<const Name>& prefix,
354 const ptr_lib::shared_ptr<const Interest>& interest,
Face& face,
355 uint64_t interestFilterId,
356 const ptr_lib::shared_ptr<const InterestFilter>& filter);
370 Content(
const Data& data)
372 : name_(data.getName()), dataEncoding_(data.wireEncode())
376 getName()
const {
return name_; }
379 getDataEncoding()
const {
return dataEncoding_; }
390 class StaleTimeContent :
public Content {
398 StaleTimeContent(
const Data& data);
409 return staleTimeMilliseconds_ <= nowMilliseconds;
419 (
const ptr_lib::shared_ptr<const StaleTimeContent>& x,
420 const ptr_lib::shared_ptr<const StaleTimeContent>& y)
const
422 return x->staleTimeMilliseconds_ < y->staleTimeMilliseconds_;
447 storePendingInterestCallback
448 (
const ptr_lib::shared_ptr<const Name>& prefix,
449 const ptr_lib::shared_ptr<const Interest>& interest,
Face& face,
450 uint64_t interestFilterId,
451 const ptr_lib::shared_ptr<const InterestFilter>& filter)
459 std::map<std::string, OnInterestCallback> onDataNotFoundForPrefix_;
460 std::vector<uint64_t> interestFilterIdList_;
461 std::vector<uint64_t> registeredPrefixIdList_;
462 std::vector<ptr_lib::shared_ptr<const Content> > noStaleTimeCache_;
464 std::deque<ptr_lib::shared_ptr<const StaleTimeContent> > staleTimeCache_;
465 StaleTimeContent::Compare contentCompare_;
467 std::vector<ptr_lib::shared_ptr<const PendingInterest> > pendingInterestTable_;
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
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:237
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
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:226
std::string toUri(bool includeScheme=false) const
Encode this name as a URI.
Definition: name.cpp:305
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.cpp:114
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.cpp:106
Face & getFace() const
Return the face given to the constructor.
Definition: memory-content-cache.hpp:91
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:100
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, uint64_t)> OnRegisterSuccess
An OnRegisterSuccess function object is used to report when registerPrefix succeeds.
Definition: face.hpp:78
const Name & getPrefix() const
Get the prefix given to the constructor.
Definition: interest-filter.hpp:154
const ptr_lib::shared_ptr< const Interest > & getInterest() const
Return the interest given to the constructor.
Definition: memory-content-cache.hpp:75
A PendingInterest holds an interest which onInterest received but could not satisfy.
Definition: memory-content-cache.hpp:57
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.cpp:46
MemoryContentCache(Face *face, Milliseconds cleanupIntervalMilliseconds=1000.0)
Create a new MemoryContentCache to use the given Face.
Definition: memory-content-cache.cpp:35
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
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:146
const OnInterestCallback & getStorePendingInterest()
Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest...
Definition: memory-content-cache.hpp:321
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
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.cpp:61
virtual uint64_t setInterestFilter(const InterestFilter &filter, const OnInterestCallback &onInterest)
Add an entry to the local interest filter table to call the onInterest callback for a matching incomi...
Definition: face.cpp:196
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Face &, uint64_t, const ptr_lib::shared_ptr< const InterestFilter > &)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:67
Compare shared_ptrs to Content based only on staleTimeMilliseconds_.
Definition: memory-content-cache.hpp:415
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:72
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:85
virtual uint64_t registerPrefix(const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Register prefix with the connected NDN hub and call onInterest when a matching interest is received...
Definition: face.cpp:145