[ndnSIM] how to trace the self-defined element in ndnsim?

Alex Afanasyev alexander.afanasyev at ucla.edu
Fri Apr 12 11:50:25 PDT 2013

Hi huyao,

Technically, you have many options how to trace self-defined variables.  If you really want to, you can just directly dump the values to std::cout or to some file.

If you want to go with NS-3-style tracing, you would need to use either TraceSource, with which you explicitly notifying (somebody, who is configured in the simulation scenario using Connect calls) before or after you change the value.

There is also a TraceValue, which can automate some notification tasks, if you're tracing just a value.  

Both methods require a couple of things.  For TraceSource, you need to define a local TracedCallback (like this https://github.com/NDN-Routing/ndnSIM/blob/master/model/fw/ndn-forwarding-strategy.h#L482) and then define a way to connect to this variable in GetTypeId method (like this https://github.com/NDN-Routing/ndnSIM/blob/master/model/fw/ndn-forwarding-strategy.cc#L71).  Afterwards, you just use the locally defined TracedCallback as if it is a function (like this https://github.com/NDN-Routing/ndnSIM/blob/master/model/fw/ndn-forwarding-strategy.cc#L586).

For TracedValue, you need to define the variable that you want to trace in a slightly different way (it is no longer a simple variable), like this https://github.com/NDN-Routing/ndnSIM/blob/master/apps/ndn-consumer-window.h#L98.  Then add a line into GetTypeId call, similar to this https://github.com/NDN-Routing/ndnSIM/blob/master/apps/ndn-consumer-window.cc#L65.

To connect to variables, you need to use either Config::Connect/Config::ConnectWithoutContext method, or Object's TraceConnect (http://www.nsnam.org/doxygen-release/classns3_1_1_object_base.html#ada3a45b34bc23114a25e0ab19188276e).

Let us know if you have more questions.  If you can give more specific description of what you want to trace, then we may give more concrete suggestion of what is the best way to do it.


On Apr 12, 2013, at 9:37 AM, yao hu <huyao0107 at gmail.com> wrote:

> Hi Alex,
> Maybe this is not related to ndnsim, just about ns3. Could you please give a hint about how to trace or record the value of some self-defined variable like each element in some array somewhere in ndnsim when simulation runs?
> Thanks a lot!!
> Regards,
> huyao
> _______________________________________________
> ndnSIM mailing list
> ndnSIM at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20130412/f4ffbe82/attachment.html>

More information about the ndnSIM mailing list