Classes | Public Member Functions | List of all members
ndn::MemoryContentCache Class Reference

A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data packet. More...

#include <memory-content-cache.hpp>

Classes

class  PendingInterest
 A PendingInterest holds an interest which onInterest received but could not satisfy. More...
 

Public Member Functions

 MemoryContentCache (Face *face, Milliseconds cleanupIntervalMilliseconds=1000.0)
 Create a new MemoryContentCache to use the given Face. More...
 
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 interests whose name has the prefix. More...
 
void registerPrefix (const Name &prefix, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, 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 interests whose name has the prefix. More...
 
void setInterestFilter (const InterestFilter &filter, const OnInterestCallback &onDataNotFound=OnInterestCallback())
 Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name matches the filter. More...
 
void setInterestFilter (const Name &prefix, const OnInterestCallback &onDataNotFound=OnInterestCallback())
 Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix. More...
 
void unregisterAll ()
 Call Face.unsetInterestFilter and Face.removeRegisteredPrefix for all the prefixes given to the setInterestFilter and registerPrefix method on this MemoryContentCache object so that it will not receive interests any more. More...
 
void add (const Data &data)
 Add the Data packet to the cache so that it is available to use to answer interests. More...
 
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 because there is no Data packet available yet to satisfy the interest). More...
 
const OnInterestCallbackgetStorePendingInterest ()
 Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest() to store the interest that doesn't match a Data packet. More...
 
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 Interest.matchesName(name), append the PendingInterest entry to the given pendingInterests list. More...
 
void operator() (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)
 This is the OnInterest callback which is called when the library receives an interest whose name has the prefix given to registerPrefix. More...
 

Detailed Description

A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data packet.

The cache is periodically cleaned up to remove each stale Data packet based on its FreshnessPeriod (if it has one).

Note
This class is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/memory-content-cache.html .

Constructor & Destructor Documentation

ndn::MemoryContentCache::MemoryContentCache ( Face face,
Milliseconds  cleanupIntervalMilliseconds = 1000.0 
)

Create a new MemoryContentCache to use the given Face.

Parameters
faceThe Face to use to call registerPrefix and setInterestFilter, and which will call this object's OnInterest callback.
cleanupIntervalMilliseconds(optional) The interval in milliseconds between each check to clean up stale content in the cache. If omitted, use a default of 1000 milliseconds. If this is a large number, then effectively the stale content will not be removed from the cache.

Member Function Documentation

void ndn::MemoryContentCache::add ( const Data data)

Add the Data packet to the cache so that it is available to use to answer interests.

If data.getMetaInfo().getFreshnessPeriod() is not negative, set the staleness time to now plus data.getMetaInfo().getFreshnessPeriod(), which is checked during cleanup to remove stale content. This also checks if cleanupIntervalMilliseconds milliseconds have passed and removes stale content from the cache. After removing stale content, remove timed-out pending interests from storePendingInterest(), then if the added Data packet satisfies any interest, send it through the transport and remove the interest from the pending interest table. Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
dataThe Data packet object to put in the cache. This copies the fields from the object.
void ndn::MemoryContentCache::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 Interest.matchesName(name), append the PendingInterest entry to the given pendingInterests list.

Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
nameThe name to check.
pendingInterestsThe vector to receive the matching PendingInterest objects. This first clears the list before adding objects. You should not modify the PendingInterest objects.
const OnInterestCallback& ndn::MemoryContentCache::getStorePendingInterest ( )
inline

Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest() to store the interest that doesn't match a Data packet.

add(data) will check if the added Data packet satisfies any pending interest and send it.

Returns
A callback to use for onDataNotFound in registerPrefix().
void ndn::MemoryContentCache::operator() ( 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 
)

This is the OnInterest callback which is called when the library receives an interest whose name has the prefix given to registerPrefix.

First check if cleanupIntervalMilliseconds milliseconds have passed and remove stale content from the cache. Then search the cache for the Data packet, matching any interest selectors including ChildSelector, and send the Data packet to the transport. If no matching Data packet is in the cache, call the callback in onDataNotFoundForPrefix_ (if defined).

void ndn::MemoryContentCache::registerPrefix ( const Name prefix,
const OnRegisterFailed onRegisterFailed,
const OnInterestCallback onDataNotFound = OnInterestCallback(),
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
inline

Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Alternatively, if the Face's registerPrefix has already been called, then you can call this object's setInterestFilter.

Parameters
prefixThe Name for the prefix to register. This copies the Name.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterest(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
flags(optional) See Face::registerPrefix.
wireFormat(optional) See Face::registerPrefix.
void ndn::MemoryContentCache::registerPrefix ( const Name prefix,
const OnRegisterFailed onRegisterFailed,
const OnRegisterSuccess onRegisterSuccess,
const OnInterestCallback onDataNotFound = OnInterestCallback(),
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
inline

Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Alternatively, if the Face's registerPrefix has already been called, then you can call this object's setInterestFilter.

Parameters
prefixThe Name for the prefix to register. This copies the Name.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
onRegisterSuccess(optional) A function object to call registerPrefix receives a success message from the forwarder. This calls onRegisterSuccess(prefix, registeredPrefixId) where prefix and registeredPrefixId are the values given to registerPrefix. If onRegisterSuccess is an empty OnRegisterSuccess(), this does not use it.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterest(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
flags(optional) See Face::registerPrefix.
wireFormat(optional) See Face::registerPrefix.
void ndn::MemoryContentCache::setInterestFilter ( const InterestFilter filter,
const OnInterestCallback onDataNotFound = OnInterestCallback() 
)
inline

Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name matches the filter.

Parameters
filterThe InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). Note: If you call setInterestFilter multiple times where filter.getPrefix() is the same, it is undetermined which onDataNotFound will be called. If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterest(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
void ndn::MemoryContentCache::setInterestFilter ( const Name prefix,
const OnInterestCallback onDataNotFound = OnInterestCallback() 
)
inline

Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Parameters
prefixThe Name prefix used to match the name of an incoming Interest. This copies the Name.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterest(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
void ndn::MemoryContentCache::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 because there is no Data packet available yet to satisfy the interest).

add(data) will check if the added Data packet satisfies any pending interest and send it through the face. Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
interestThe Interest for which we don't have a Data packet yet. You should not modify the interest after calling this.
faceThe Face with the connection which received the interest. This comes from the onInterest callback.
void ndn::MemoryContentCache::unregisterAll ( )

Call Face.unsetInterestFilter and Face.removeRegisteredPrefix for all the prefixes given to the setInterestFilter and registerPrefix method on this MemoryContentCache object so that it will not receive interests any more.

You can call this if you want to "shut down" this MemoryContentCache while your application is still running.


The documentation for this class was generated from the following files: