Hi Alex,<div><br></div><div>Thanks very much for the information you offered and it works :)</div><div><br></div><div>Sincerely,</div><div>Xiaoyan<br><br><div class="gmail_quote">On Tue, Dec 11, 2012 at 8:29 AM, Alex Afanasyev <span dir="ltr"><<a href="mailto:alexander.afanasyev@ucla.edu" target="_blank">alexander.afanasyev@ucla.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Xiaoyan,<br>
<br>
The "policy" that I was talking about is just a way to get access to the underlying data structure (insert/erase events).<br>
<br>
In any case, as it could be a generally useful metric, I decided to implement the necessary mechanics myself.   If you're curious, you can check commit 8566f458f2aacc25f06683ce00219f7168ee71f5, in particular utils/trie/lifetime-stats-policy.h policy file.<br>

<br>
As of right now (commit f4a0359ac1dc60390ea41d8347c73a8c24a6789e) you can use the following code in order to get samples for lifetime of cached entries (copy from <a href="http://ndnsim.net/helpers.html#content-store" target="_blank">http://ndnsim.net/helpers.html#content-store</a>):<br>

<br>
--------------------<br>
void<br>
CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)<br>
{<br>
    std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;<br>
}<br>
...<br>
ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", "MaxSize", "10000");<br>
...<br>
ndnHelper.Install (nodes);<br>
// connect to lifetime trace<br>
Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback (CacheEntryRemoved));<br>
--------------------<br>
<br>
I haven't had time, but you can write a tracer (similar to the one you already wrote for CacheHits/CacheMisses), which will make tracing totally trivial.<br>
<br>
Please note, that you *have to* use a specialized version of content store (ns3::ndn::cs::Stats::Lru, ns3::ndn::cs::Stats::Random, or ns3::ndn::cs::Stats::Fifo), and Config::Connect/Config::ConnectWithoutContext *have to* specify the correct content store implementation.<br>

<br>
Another note, for some replacement policies, entries may not be put in cache at all.  In the current implementation, such entries will be reported with lifetime 0.<br>
<br>
---<br>
Alex<br>
<br>
PS<br>
I have incorporated your implementation of the content store tracer (ndn::CsImpTracer). I also have added an example how to use the tracer (<a href="http://ndnsim.net/examples.html#level-binary-tree-with-content-store-trace-helper" target="_blank">http://ndnsim.net/examples.html#level-binary-tree-with-content-store-trace-helper</a>).   Thanks again.<br>

<div class="HOEnZb"><div class="h5"><br>
<br>
On Dec 10, 2012, at 1:34 AM, Xiao yan Hu <<a href="mailto:xhbreezehu@gmail.com">xhbreezehu@gmail.com</a>> wrote:<br>
<br>
> Hi Alex,<br>
><br>
> Thanks very much for your information.<br>
> Actually I do not want to create a new replacement policy, but that updating the average lifetime of content store entries whenever cache replacement happens.<br>
> I found, e.g., in lru-policy.h, how an new content store entry is inserted as follow, and " base_.erase (&(*policy_container::begin ()));" shuld be for the replacement (&(*policy_container::begin ()) is the entry to replace), right?<br>

> 74       inline bool<br>
>  75       insert (typename parent_trie::iterator item)<br>
>  76       {<br>
>  77         if (max_size_ != 0 && policy_container::size () >= max_size_)<br>
>  78           {<br>
>  79             base_.erase (&(*policy_container::begin ()));<br>
>  80           }<br>
>  81<br>
>  82         policy_container::push_back (*item);<br>
>  83         return true;<br>
>  84       }<br>
><br>
> I think I get stuck in that how to map &(*policy_container::begin ()) into content store entry. Please forgive me about that I don't understand c++ very well.<br>
> And then I do not know what are eventually instantiated separately as "class Base, class Container, class Hook" of "template<class Base, class Container, class Hook>" in in lru-policy.h.<br>

> Would you pls give me a hint?<br>
><br>
> Thanks,<br>
> Xiaoyan<br>
><br>
> On Mon, Dec 10, 2012 at 4:28 PM, Alex Afanasyev <<a href="mailto:alexander.afanasyev@ucla.edu">alexander.afanasyev@ucla.edu</a>> wrote:<br>
> Hi Xiaoyan,<br>
><br>
> Replacement and removal of content store entries in ndnSIM is controlled by so called policies. These policies are not really related specifically to the content store, but to the general data structure (trie-with-policy: utils/trie/trie-with-policy.h).  There are currently three policies that are used in content stores: lru-policy.h, random-policy.h, and fifo-policy.h (code in utils/trie/ folder).  If you create a new policy, a "new" content store can be created by adding a couple of lines (at least in the current code) into model/cs/content-store-impl.cc file:<br>

><br>
> ---<br>
><br>
> // (1) A little bit cheating to trick NS-3 object system<br>
><br>
> template<><br>
> TypeId<br>
> ContentStoreImpl< YOUR_POLICY >::GetTypeId ()<br>
> {<br>
>   static TypeId tid = TypeId ("CONTENT_STORE_NAME")  // e.g., to use in ndnStackHelper.SetContentStore ("CONTENT_STORE_NAME")<br>
>     .SetGroupName ("Ndn")<br>
>     .SetParent<ContentStore> ()<br>
>     .AddConstructor< ContentStoreImpl< YOUR_POLICY > > ()<br>
>     .AddAttribute ("MaxSize",<br>
>                    "Set maximum number of entries in ContentStore. If 0, limit is not enforced",<br>
>                    StringValue ("100"),<br>
>                    MakeUintegerAccessor (&ContentStoreImpl< YOUR_POLICY >::GetMaxSize,<br>
>                                          &ContentStoreImpl< YOUR_POLICY >::SetMaxSize),<br>
>                    MakeUintegerChecker<uint32_t> ())<br>
>     ;<br>
><br>
>   return tid;<br>
> }<br>
><br>
> // (2) specialize content store implementation:<br>
><br>
> template class ContentStoreImpl<lru_policy_traits>;<br>
><br>
> ---<br>
><br>
> Now regarding the policy itself.<br>
> For CS statistic generation I would recommend (at least for now) creating a custom "replacement" policy based on the existing one.  That is, if you want stats for LRU policy, just copy lru-policy.h to lru-policy-stat.h and do necessary modifications.  There is also multi-policy.h, which potentially could be a better fit (e.g., you would not need to "reimplement" stats for every replacement policy), but I haven't thoroughly tested this implementation.<br>

><br>
> The code should be semi-self explanatory, though may be a little bit obscured.  Looking forward to hear about your progress and/or problems :)<br>
><br>
> Sincerely,<br>
> Alex<br>
><br>
> On Dec 10, 2012, at 12:08 AM, Xiao yan Hu <<a href="mailto:xhbreezehu@gmail.com">xhbreezehu@gmail.com</a>> wrote:<br>
><br>
> > Hi all,<br>
> ><br>
> > Really happy to join the ndnSIM mailing list.<br>
> > Thank Alex very much for the development of ndnSIM which enables the simulation for NDN features.<br>
> > Hope everyone have fun with ndnSIM.<br>
> > I am doing some research on the NDN caching stuff and trying to simulate it with ndnSIM.<br>
> > I want to do statistics about the average time that an content object stays in the content store of a NDN node which is based on the lifetime of content store entries that have been replaced. Would you guys pls tell me where is the exact source code location of ndnSIM when an content store entry is replaced/erased?<br>

> > Look forward to hearing from your guys :) Thanks in advance!<br>
> ><br>
> > Best regards,<br>
> > Xiaoyan<br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>