[ndnSIM] do statistics about the lifetime of a content store entry in ndnSIM

Xiao yan Hu xhbreezehu at gmail.com
Tue Dec 11 18:27:54 PST 2012


Hi Alex,

Thanks very much for the information you offered and it works :)

Sincerely,
Xiaoyan

On Tue, Dec 11, 2012 at 8:29 AM, Alex Afanasyev <
alexander.afanasyev at ucla.edu> wrote:

> Hi Xiaoyan,
>
> The "policy" that I was talking about is just a way to get access to the
> underlying data structure (insert/erase events).
>
> 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.
>
> As of right now (commit f4a0359ac1dc60390ea41d8347c73a8c24a6789e) you can
> use the following code in order to get samples for lifetime of cached
> entries (copy from http://ndnsim.net/helpers.html#content-store):
>
> --------------------
> void
> CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry,
> Time lifetime)
> {
>     std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S)
> << "s" << std::endl;
> }
> ...
> ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", "MaxSize", "10000");
> ...
> ndnHelper.Install (nodes);
> // connect to lifetime trace
> Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry",
> MakeCallback (CacheEntryRemoved));
> --------------------
>
> 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.
>
> 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.
>
> 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.
>
> ---
> Alex
>
> PS
> I have incorporated your implementation of the content store tracer
> (ndn::CsImpTracer). I also have added an example how to use the tracer (
> http://ndnsim.net/examples.html#level-binary-tree-with-content-store-trace-helper).
>   Thanks again.
>
>
> On Dec 10, 2012, at 1:34 AM, Xiao yan Hu <xhbreezehu at gmail.com> wrote:
>
> > Hi Alex,
> >
> > Thanks very much for your information.
> > 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.
> > 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?
> > 74       inline bool
> >  75       insert (typename parent_trie::iterator item)
> >  76       {
> >  77         if (max_size_ != 0 && policy_container::size () >= max_size_)
> >  78           {
> >  79             base_.erase (&(*policy_container::begin ()));
> >  80           }
> >  81
> >  82         policy_container::push_back (*item);
> >  83         return true;
> >  84       }
> >
> > 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.
> > 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.
> > Would you pls give me a hint?
> >
> > Thanks,
> > Xiaoyan
> >
> > On Mon, Dec 10, 2012 at 4:28 PM, Alex Afanasyev <
> alexander.afanasyev at ucla.edu> wrote:
> > Hi Xiaoyan,
> >
> > 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:
> >
> > ---
> >
> > // (1) A little bit cheating to trick NS-3 object system
> >
> > template<>
> > TypeId
> > ContentStoreImpl< YOUR_POLICY >::GetTypeId ()
> > {
> >   static TypeId tid = TypeId ("CONTENT_STORE_NAME")  // e.g., to use in
> ndnStackHelper.SetContentStore ("CONTENT_STORE_NAME")
> >     .SetGroupName ("Ndn")
> >     .SetParent<ContentStore> ()
> >     .AddConstructor< ContentStoreImpl< YOUR_POLICY > > ()
> >     .AddAttribute ("MaxSize",
> >                    "Set maximum number of entries in ContentStore. If 0,
> limit is not enforced",
> >                    StringValue ("100"),
> >                    MakeUintegerAccessor (&ContentStoreImpl< YOUR_POLICY
> >::GetMaxSize,
> >                                          &ContentStoreImpl< YOUR_POLICY
> >::SetMaxSize),
> >                    MakeUintegerChecker<uint32_t> ())
> >     ;
> >
> >   return tid;
> > }
> >
> > // (2) specialize content store implementation:
> >
> > template class ContentStoreImpl<lru_policy_traits>;
> >
> > ---
> >
> > Now regarding the policy itself.
> > 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.
> >
> > The code should be semi-self explanatory, though may be a little bit
> obscured.  Looking forward to hear about your progress and/or problems :)
> >
> > Sincerely,
> > Alex
> >
> > On Dec 10, 2012, at 12:08 AM, Xiao yan Hu <xhbreezehu at gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > Really happy to join the ndnSIM mailing list.
> > > Thank Alex very much for the development of ndnSIM which enables the
> simulation for NDN features.
> > > Hope everyone have fun with ndnSIM.
> > > I am doing some research on the NDN caching stuff and trying to
> simulate it with ndnSIM.
> > > 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?
> > > Look forward to hearing from your guys :) Thanks in advance!
> > >
> > > Best regards,
> > > Xiaoyan
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20121212/7b3b4003/attachment.html>


More information about the ndnSIM mailing list