NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::util::InMemoryStorage Class Referenceabstract

Represents in-memory storage. More...

#include <in-memory-storage.hpp>

Inheritance diagram for ndn::util::InMemoryStorage:
Collaboration diagram for ndn::util::InMemoryStorage:

Classes

class  const_iterator
 Represents a self-defined const_iterator for the in-memory storage. More...
 
class  Error
 Represents an error might be thrown during reduce the current capacity of the in-memory storage through function setCapacity(size_t nMaxPackets). More...
 

Public Types

typedef boost::multi_index_container< InMemoryStorageEntry *, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< byFullName >, boost::multi_index::const_mem_fun< InMemoryStorageEntry, const Name &, &InMemoryStorageEntry::getFullName >, std::less< Name > > > > Cache
 

Public Member Functions

 InMemoryStorage (size_t limit=std::numeric_limits< size_t >::max())
 Create a InMemoryStorage with up to limit entries The InMemoryStorage created through this method will ignore MustBeFresh in interest processing. More...
 
 InMemoryStorage (boost::asio::io_service &ioService, size_t limit=std::numeric_limits< size_t >::max())
 Create a InMemoryStorage with up to limit entries The InMemoryStorage created through this method will handle MustBeFresh in interest processing. More...
 
virtual ~InMemoryStorage ()
 
void insert (const Data &data, const time::milliseconds &mustBeFreshProcessingWindow=INFINITE_WINDOW)
 Inserts a Data packet. More...
 
shared_ptr< const Datafind (const Interest &interest)
 Finds the best match Data for an Interest. More...
 
shared_ptr< const Datafind (const Name &name)
 Finds the best match Data for a Name with or without the implicit digest. More...
 
void erase (const Name &prefix, const bool isPrefix=true)
 Deletes in-memory storage entry by prefix by default. More...
 
size_t getLimit () const
 
size_t size () const
 
InMemoryStorage::const_iterator begin () const
 Returns begin iterator of the in-memory storage ordering by name with digest. More...
 
InMemoryStorage::const_iterator end () const
 Returns end iterator of the in-memory storage ordering by name with digest. More...
 
virtual void afterInsert (InMemoryStorageEntry *entry)
 Update the entry or other data structures after a entry is successfully inserted according to derived class implemented replacement policy. More...
 
virtual void beforeErase (InMemoryStorageEntry *entry)
 Update the entry or other data structures before a entry is successfully erased according to derived class implemented replacement policy. More...
 
virtual bool evictItem ()=0
 Removes one Data packet from in-memory storage based on derived class implemented replacement policy. More...
 
size_t getCapacity () const
 returns current capacity of in-memory storage (in packets) More...
 
bool isFull () const
 returns true if the in-memory storage uses up the current capacity, false otherwise More...
 
void eraseImpl (const Name &name)
 deletes in-memory storage entries by the Name with implicit digest. More...
 
void printCache (std::ostream &os) const
 Prints contents of the in-memory storage. More...
 
InMemoryStorageEntryselectChild (const Interest &interest, Cache::index< byFullName >::type::iterator startingPoint) const
 Implements child selector (leftmost, rightmost, undeclared). More...
 
Cache::index< byFullName >::type::iterator findNextFresh (Cache::index< byFullName >::type::iterator startingPoint) const
 Get the next iterator (include startingPoint) that satisfies MustBeFresh requirement. More...
 

Public Attributes

NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED __pad0__: virtual void afterAccess(InMemoryStorageEntry* entry)
 
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED __pad1__: void setCapacity(size_t nMaxPackets)
 
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE __pad2__: Cache::iterator freeEntry(Cache::iterator it)
 

Static Public Attributes

static const time::milliseconds INFINITE_WINDOW
 

Detailed Description

Represents in-memory storage.

Definition at line 46 of file in-memory-storage.hpp.

Member Typedef Documentation

◆ Cache

typedef boost::multi_index_container< InMemoryStorageEntry*, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag<byFullName>, boost::multi_index::const_mem_fun<InMemoryStorageEntry, const Name&, &InMemoryStorageEntry::getFullName>, std::less<Name> > > > ndn::util::InMemoryStorage::Cache

Definition at line 50 of file in-memory-storage.hpp.

Constructor & Destructor Documentation

◆ InMemoryStorage() [1/2]

ndn::util::InMemoryStorage::InMemoryStorage ( size_t  limit = std::numeric_limits<size_t>::max())
explicit

Create a InMemoryStorage with up to limit entries The InMemoryStorage created through this method will ignore MustBeFresh in interest processing.

Definition at line 90 of file in-memory-storage.cpp.

Referenced by ndn::util::InMemoryStorage::Error::Error().

◆ InMemoryStorage() [2/2]

ndn::util::InMemoryStorage::InMemoryStorage ( boost::asio::io_service &  ioService,
size_t  limit = std::numeric_limits<size_t>::max() 
)
explicit

Create a InMemoryStorage with up to limit entries The InMemoryStorage created through this method will handle MustBeFresh in interest processing.

Definition at line 97 of file in-memory-storage.cpp.

◆ ~InMemoryStorage()

ndn::util::InMemoryStorage::~InMemoryStorage ( )
virtual
Note
Please make sure to implement it to free m_freeEntries and evict all items in the derived class for anybody who wishes to inherit this class

Definition at line 120 of file in-memory-storage.cpp.

References evictItem(), and size().

Referenced by ndn::util::InMemoryStorage::Error::Error().

Member Function Documentation

◆ insert()

void ndn::util::InMemoryStorage::insert ( const Data data,
const time::milliseconds &  mustBeFreshProcessingWindow = INFINITE_WINDOW 
)

Inserts a Data packet.

Parameters
datathe packet to insert
mustBeFreshProcessingWindowBeyond this time period after the data is inserted, the data can only be used to answer interest without MustBeFresh selector.
Note
Packets are considered duplicate if the name with implicit digest matches. The new Data packet with the identical name, but a different payload will be placed in the in-memory storage.
It will invoke afterInsert(shared_ptr<InMemoryStorageEntry>).

Definition at line 167 of file in-memory-storage.cpp.

References afterInsert(), evictItem(), find(), getCapacity(), ndn::Data::getFullName(), getLimit(), isFull(), and ndn::util::InMemoryStorageEntry::markStale().

Referenced by ndn::util::InMemoryStorage::Error::Error().

◆ find() [1/2]

shared_ptr< const Data > ndn::util::InMemoryStorage::find ( const Interest interest)

Finds the best match Data for an Interest.

Note
It will invoke afterAccess(shared_ptr<InMemoryStorageEntry>). As currently it is impossible to determine whether a Name contains implicit digest or not, therefore this find function is not able to locate a packet according to an interest( including implicit digest) whose name is not the full name of the data matching the implicit digest.
Returns
{ the best match, if any; otherwise a null shared_ptr }

Definition at line 226 of file in-memory-storage.cpp.

References ndn::util::InMemoryStorageEntry::getData(), ndn::Interest::getName(), and selectChild().

Referenced by ndn::util::InMemoryStorageLfu::afterAccess(), ndn::util::InMemoryStorageFifo::beforeErase(), ndn::util::InMemoryStorageLru::beforeErase(), ndn::util::InMemoryStorageLfu::beforeErase(), erase(), eraseImpl(), ndn::util::InMemoryStorage::Error::Error(), and insert().

◆ find() [2/2]

shared_ptr< const Data > ndn::util::InMemoryStorage::find ( const Name name)

Finds the best match Data for a Name with or without the implicit digest.

If packets with the same name but different digests exist and the Name supplied is the one without implicit digest, a packet will be arbitrarily chosen to return.

Note
It will invoke afterAccess(shared_ptr<InMemoryStorageEntry>).
Returns
{ the one matched the Name; otherwise a null shared_ptr }

Definition at line 207 of file in-memory-storage.cpp.

References ndn::Name::isPrefixOf().

◆ erase()

void ndn::util::InMemoryStorage::erase ( const Name prefix,
const bool  isPrefix = true 
)

Deletes in-memory storage entry by prefix by default.

Parameters
prefixExact name of a prefix of the data to remove
isPrefixIf false, the function will only delete the entry completely matched with the prefix according to canonical ordering. For this case, user should substitute the prefix with full name.
Note
Please do not use this function directly in any derived class to erase entry in the cache, use eraseHelper instead.
It will invoke beforeErase(shared_ptr<InMemoryStorageEntry>).

Definition at line 377 of file in-memory-storage.cpp.

References beforeErase(), find(), getCapacity(), ndn::Name::isPrefixOf(), and size().

Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and ndn::util::InMemoryStorage::Error::Error().

◆ getLimit()

size_t ndn::util::InMemoryStorage::getLimit ( ) const
inline
Returns
{ maximum number of packets that can be allowed to store in in-memory storage }

Definition at line 189 of file in-memory-storage.hpp.

Referenced by insert().

◆ size()

size_t ndn::util::InMemoryStorage::size ( ) const
inline

◆ begin()

InMemoryStorage::const_iterator ndn::util::InMemoryStorage::begin ( ) const

Returns begin iterator of the in-memory storage ordering by name with digest.

Returns
{ const_iterator pointing to the beginning of the m_cache }

Definition at line 415 of file in-memory-storage.cpp.

Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and size().

◆ end()

InMemoryStorage::const_iterator ndn::util::InMemoryStorage::end ( ) const

Returns end iterator of the in-memory storage ordering by name with digest.

Returns
{ const_iterator pointing to the end of the m_cache }

Definition at line 423 of file in-memory-storage.cpp.

Referenced by findNextFresh(), selectChild(), and size().

◆ afterInsert()

void ndn::util::InMemoryStorage::afterInsert ( InMemoryStorageEntry entry)
virtual

Update the entry or other data structures after a entry is successfully inserted according to derived class implemented replacement policy.

Reimplemented in ndn::util::InMemoryStorageLfu, ndn::util::InMemoryStorageLru, and ndn::util::InMemoryStorageFifo.

Definition at line 433 of file in-memory-storage.cpp.

Referenced by insert().

◆ beforeErase()

void ndn::util::InMemoryStorage::beforeErase ( InMemoryStorageEntry entry)
virtual

Update the entry or other data structures before a entry is successfully erased according to derived class implemented replacement policy.

Reimplemented in ndn::util::InMemoryStorageLfu, ndn::util::InMemoryStorageLru, and ndn::util::InMemoryStorageFifo.

Definition at line 438 of file in-memory-storage.cpp.

Referenced by erase().

◆ evictItem()

virtual bool ndn::util::InMemoryStorage::evictItem ( )
pure virtual

Removes one Data packet from in-memory storage based on derived class implemented replacement policy.

Please do not use this function directly in any derived class to erase entry in the cache, use eraseHelper instead.

Returns
{ whether the Data was removed }

Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), ndn::util::InMemoryStoragePersistent::InMemoryStoragePersistent(), insert(), and ~InMemoryStorage().

◆ getCapacity()

size_t ndn::util::InMemoryStorage::getCapacity ( ) const
inline

returns current capacity of in-memory storage (in packets)

Returns
{ number of packets that can be stored in application cache }

Definition at line 259 of file in-memory-storage.hpp.

Referenced by erase(), and insert().

◆ isFull()

bool ndn::util::InMemoryStorage::isFull ( ) const
inline

returns true if the in-memory storage uses up the current capacity, false otherwise

Definition at line 267 of file in-memory-storage.hpp.

References eraseImpl(), NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE, printCache(), and size().

Referenced by insert().

◆ eraseImpl()

void ndn::util::InMemoryStorage::eraseImpl ( const Name name)

deletes in-memory storage entries by the Name with implicit digest.

This is the function one should use to erase entry in the cache in derived class. It won't invoke beforeErase(shared_ptr<Entry>).

Definition at line 404 of file in-memory-storage.cpp.

References find().

Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and isFull().

◆ printCache()

void ndn::util::InMemoryStorage::printCache ( std::ostream &  os) const

Prints contents of the in-memory storage.

Definition at line 448 of file in-memory-storage.cpp.

Referenced by isFull().

◆ selectChild()

InMemoryStorageEntry * ndn::util::InMemoryStorage::selectChild ( const Interest interest,
Cache::index< byFullName >::type::iterator  startingPoint 
) const

Implements child selector (leftmost, rightmost, undeclared).

Operates on the first layer of a skip list.

startingPoint must be less than Interest Name. startingPoint can be equal to Interest Name only when the item is in the begin() position.

Iterates toward greater Names, terminates when application cache entry falls out of Interest prefix. When childSelector = leftmost, returns first application cache entry that satisfies other selectors. When childSelector = rightmost, it goes till the end, and returns application cache entry that satisfies other selectors. Returned application cache entry is the leftmost child of the rightmost child.

Returns
{ the best match, if any; otherwise 0 }

Definition at line 272 of file in-memory-storage.cpp.

References ndn::Name::empty(), end(), findNextFresh(), ndn::Interest::getChildSelector(), ndn::Interest::getMustBeFresh(), ndn::Interest::getName(), ndn::Name::getPrefix(), ndn::Name::isPrefixOf(), ndn::Interest::matchesData(), and ndn::Name::size().

Referenced by find().

◆ findNextFresh()

InMemoryStorage::Cache::index< InMemoryStorage::byFullName >::type::iterator ndn::util::InMemoryStorage::findNextFresh ( Cache::index< byFullName >::type::iterator  startingPoint) const

Get the next iterator (include startingPoint) that satisfies MustBeFresh requirement.

Parameters
startingPointThe iterator to start with.
Returns
The next qualified iterator

Definition at line 261 of file in-memory-storage.cpp.

References end().

Referenced by selectChild().

Member Data Documentation

◆ __pad0__

NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED ndn::util::InMemoryStorage::__pad0__

Definition at line 223 of file in-memory-storage.hpp.

◆ __pad1__

NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED ndn::util::InMemoryStorage::__pad1__

Definition at line 253 of file in-memory-storage.hpp.

◆ __pad2__

NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE ndn::util::InMemoryStorage::__pad2__

Definition at line 291 of file in-memory-storage.hpp.

◆ INFINITE_WINDOW

const time::milliseconds ndn::util::InMemoryStorage::INFINITE_WINDOW
static

Definition at line 324 of file in-memory-storage.hpp.

Referenced by ndn::util::InMemoryStorage::Error::Error().


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