This PR enables users to easily define their own caching decision and cache replacement strategies.
A quick note on terminology:
The caching decision strategy defines how a router decides whether or not to store an incoming chunk in the CS. The default strategy in both the literature and in CCN-lite is to always cache everything. However, the caching decision strategy can be arbitrarily complex, ranging from simple probabilistic caching to advanced strategies involving properties of the device, content, network topology, etc. [1]
The cache replacement strategy is consulted after the caching decision strategy has decided in favour of caching the chunk and the CS is at capacity. It decides what old content chunk to evict. The default strategy in the literature and in CCN-lite is LRU, but it could be MRU, LFU, random, etc.
CCN-lite already provides an interface for user-defined cache replacement strategies using the ccnl_set_cache_strategy_remove() function in ccn-lite-riot.c. However, any user-defined strategies are not actually consulted in ccnl_content_add2cache(), which just applies LRU. This PR moves the relevant functions to ccnl-relay.c to make them accessible everywhere, not just in RIOT, and amends ccnl_content_add2cache() to consult the user-defined caching strategy. If there is no user-defined strategy, the default LRU is applied.
The caching decision strategy is implemented the same way. Use ccnl_set_cache_strategy_cache() to define a caching decision strategy that returns 1 if the content is to be cached and 0 otherwise. This caching decision strategy is consulted in ccnl_fwd_handleContent(). If no user-defined caching strategy exists, 1 is always returned, i.e. the content is always cached, just like before.
These changes do not modify the default behaviour if no user-defined strategies exist.
Contribution description
This PR enables users to easily define their own caching decision and cache replacement strategies.
A quick note on terminology:
CCN-lite already provides an interface for user-defined cache replacement strategies using the
ccnl_set_cache_strategy_remove()
function inccn-lite-riot.c
. However, any user-defined strategies are not actually consulted inccnl_content_add2cache()
, which just applies LRU. This PR moves the relevant functions toccnl-relay.c
to make them accessible everywhere, not just in RIOT, and amendsccnl_content_add2cache()
to consult the user-defined caching strategy. If there is no user-defined strategy, the default LRU is applied.The caching decision strategy is implemented the same way. Use
ccnl_set_cache_strategy_cache()
to define a caching decision strategy that returns1
if the content is to be cached and0
otherwise. This caching decision strategy is consulted inccnl_fwd_handleContent()
. If no user-defined caching strategy exists,1
is always returned, i.e. the content is always cached, just like before.These changes do not modify the default behaviour if no user-defined strategies exist.