[ndnSIM] calling dynamic variable from content-store-impl.hpp in another function

Zeinab zeinab.rezaiefar at gmail.com
Sun Jul 10 17:11:55 PDT 2016



> 
> Dear Alex,
> as you helped me, I have added variable ( double fake_content) to lifetime-stats-policy.hpp and increase and decrease it when fake content evicted. then I try to add read only attribute for this variable  as below
> template<class Policy>
> TypeId
> ContentStoreWithStats< Policy >::GetTypeId ()
> {
>   static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ())
>     .SetGroupName ("Ndn")
>     .SetParent<super> ()
>     .template AddConstructor< ContentStoreWithStats< Policy > > ()
>     .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed",
>                      MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry))
> .AddAttribute ("FakeContent", "number of fake content in the router",
>                    TypeId::ATTR_GET, // allow only getting it.
>                    UintegerValue (0), // unused (attribute is read-only
>                    MakeUintegerAccessor (?????),
>                    MakeUintegerChecker<double> ())
>     // trace stuff here
>     ;
>   return tid;
> }
> 
> however, I do not know what should I write in "MakeUintegerAccessor " to access fake_content varaiable which I defined in lifetime-stats-policy.hpp. should I define tracedcall ?
> I am looking forward to hearing you
> thank you so much
> regards
> 
>> On Fri, Jul 8, 2016 at 10:37 AM, Alex Afanasyev <aa at cs.ucla.edu> wrote:
>> 
>>> On Jul 7, 2016, at 6:26 PM, Zeinab Rezaiefar <zeinab.rezaiefar at gmail.com> wrote:
>>> 
>>> Hello Alex,
>>> Thank you so much for replying. First I would like to explain what I want to do with using invalid_content . I would like to define how many fake contents( the content with specific signature) are ine each node. therefore I defined this variable in  content-store-impl.h and call it in ContentStoreImpl<Policy>::Add (Ptr<const Data> data) function to add this value when the router receive fake contents. however , I would like to decrease this value when the router removes fake content from their cache. therefore I would like to call invalid_content in the main function (for example ndn-simple.cc in scratch folder) where I defined " Config::Connect("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback(CacheEntryRemoved)); " to call CacheEntryRemoved . inside this function I try to decrease the value of the invalid_content when the fake contents will be removed.
>>> I defined as below:
>>> void
>>> CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
>>> {
>>> 
>>> if (entry->GetData()->GetSignature()!=0){
>>> Ptr<ndn::cs::ContentStoreImpl<ns3::ndn::ndnSIM::lru_policy_traits > > content;
>>> 
>>> content->invalid_content;
>>> }
>>> }
>>>  with  defining,the program will be run but I received SIGSEGV for (content->invalid_content;) which is I think because of content pointer is null. moreover , since I have used "cnxHelper.SetContentStore("ns3::ndn::cs::Stats::Lru", "MaxSize", "1000");" , I am worry that policy is not lru_policy_traits but it can be lifetime_stats_policy_traits . however, I do not know how to use it.
>>> finally I want to call invalid_content in trace file and show the output in output text file. I will become happy and thankful , if I hear your opinion .
>>> thanks
>>> regards
>> 
>> Of course this segfaults, as content points to nothing.
>> 
>> What you want to achieve is much easier to accomplish by just writing a new specialized policy, just for that part.  There is a little bit of a hassle to instantiate it, but it would be the most straightforward way.  Though agree that it can be convoluted with c++ templates.
>> 
>> The easiest way would be to update content-store-with-stats.hpp and lifetime-stats-policy.hpp.  
>> 
>> - In the policy, you add your variable and simply increase it by one whenever things are added and remove by one when bad packet evicted (this should be easy).
>> 
>> - in the content-store-with-stats.hpp  you would want to add a read-only attribute in GetTypeId method to expose the variable in the policy.  You would need check NS-3 docs what is the proper syntax for the read-only attribute.  After that you should be able to access the value in main.cpp by
>> 
>> node->GetObject<ndn::ContentStore>()->GetAttribute("name-you-defined")...
>> 
>> --
>> Alex
>> 
>> 
>> 
>>> 
>>>> On Fri, Jul 8, 2016 at 12:36 AM, Alex Afanasyev <aa at cs.ucla.edu> wrote:
>>>> 
>>>> > On Jul 7, 2016, at 6:26 AM, Zeinab Rezaiefar <zeinab.rezaiefar at gmail.com> wrote:
>>>> >
>>>> > hello everyone,
>>>> > I have defined public variable in class ContentStoreImpl (double invalid_content)  in content-store-impl.hpp. furthermore I have change these value in ContentStoreImpl<Policy>::Add (invalid_content++;) I want to access this value through files in scratch folder .
>>>> > therefore I include this path (#include "ns3/ndnSIM/model/cs/content-store-impl.h").  I want to access it before main function as below:
>>>> >
>>>> > using namespace ns3;
>>>> > void
>>>> > CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
>>>> > {
>>>> >
>>>> > if (entry->GetData()->GetSignature()!=0){
>>>> > //ContentStoreImpl a;
>>>> > Ptr<ndn::cs::ContentStoreImpl> content;
>>>> > content.invalid_content--;
>>>> >
>>>> > }
>>>> > }
>>>> >
>>>> > however, I have received error  (mismatch at argument 1 in template parameter list for ‘template<class T> class ns3::Ptr’)
>>>> > is there anybody knows how I can access this value through this function.
>>>> > I will become thankful, if I know your opinion
>>>> > thanks in advance
>>>> > best regards
>>>> 
>>>> I'm not exactly sure what you're trying to do in the main function...  Even if you going to make it compile, "Ptr<ndn::cs::ContentStoreImpl> content;" be a null pointer.
>>>> 
>>>> What is the exact error you're having?
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20160711/1dabaa95/attachment.html>


More information about the ndnSIM mailing list