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

Zeinab Rezaiefar zeinab.rezaiefar at gmail.com
Thu Jul 7 22:58:43 PDT 2016


Dear Alex,
Thank you so much for nice points and your great helps. However, may I know
how I can access data signature in lifetime-stats-policy.hpp. I mean
for increasing defined variable with adding fake packet I need to access
signature in insert function which is defined as below:
inline bool
      insert (typename parent_trie::iterator item)
      {
        get_time (item) = Simulator::Now ();
        policy_container::push_back (*item);

        return true;
      }

how i can extract signature from item in the above function. i am looking
forward to hearing you
thanks
best 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/20160708/d6b30366/attachment.html>


More information about the ndnSIM mailing list