[ndnSIM] Modify/Read payload content & Read the content in cache
Kanin Assantachai
kanin at inl.ics.keio.ac.jp
Sun May 24 22:23:03 PDT 2015
Dear everyone,
As I have figured out the solutions to my own questions already, I would
like to contribute some knowledge back to the community as well since I
have received a lot of suggestions here. Feel free to modify these to
suit your needs. :)
1. Modify packet payload (implemented in ndn-producer.cc)
std::string string = "payloadString"; // payload
content to be added
data = Create<Data> (Create<Packet> (reinterpret_cast<const
uint8_t*>(&string[0]), string.size())); // create data packet using
the value of "string" variable
2. Read payload content (implemented in ndn-consumer.cc)
int payloadSize = data->GetPayload ()->GetSize ();
std::string content = "";
for (int i=0; i<payloadSize; i++){ // allocate the same number of
characters as the number of characters in the payload
content = content + ".";
}
data->GetPayload
()->CopyData(reinterpret_cast<uint8_t*>(&content[0]), content.size());
std::cout << "Received payload content: " << content << std::endl;
3. Read name of content in cache (actually implemented in
ndn-producer.cc not lru-policy.h)
Ptr<ContentStore> cs = GetNode ()->GetObject<ContentStore> ();
Ptr<cs::Entry> current = cs->Begin (); // can iterate to another
content store entry before printing its name
std::string string;
string = string + current->GetName ().toUri ();
std::cout << "Content name: " << string << std::endl;
Hope this helps those who are looking to do something similar!
Kanin Assantachai
On 17-May-15 1:22 AM, Kanin Assantachai wrote:
> Dear Alex / Spyridon,
>
> Currently I am working with various parts of the simulator (version
> 1.1) related to its caching mechanism. I need your kind help for the
> following questions.
>
> 1. I would like to modify the payload of packets sent by the producer
> app. My current approach is to change this part of code in the
> OnInterest() function of ndn-producer.cc:
>
> Ptr<Data> data = Create<Data> (Create<Packet> (m_virtualPayloadSize));
>
> to
>
> std::string string = "Hello";
> Ptr<Data> data = Create<Data> (Create<Packet> (reinterpret_cast<const
> uint8_t*>(&string[0]), 5));
>
> I want to firstly check if this simple way works. Even though the code
> is compiled without an error, I have a difficulty checking whether the
> payload of the packet really carries this string "Hello". So far, I
> add this code to the OnData() function of ndn-consumer.cc to try to
> read the content of the payload:
>
> data->GetPayload ()->Print (std::cout);
>
> It only outputs the size of the payload in the terminal. I have tried
> reading this previous archive about reading the content of payload but
> still cannot solve this problem:
> http://www.lists.cs.ucla.edu/pipermail/ndnsim/2015-January/001501.html
> In summary, my questions are whether my simple method in adding a
> specific string to the payload works, and which function (or other
> approach) can I use to really see the real content (string) of the
> payload?
>
> 2. I would like to get the latest content which has just been added to
> the LRU cache. So in the file "lru-policy.h", after this line of code
> in the insert() function:
>
> policy_container::push_back (*item);
>
> I tried adding this line of code to read the newly added content:
>
> std::cout << "Item added: " << policy_container::end
> ()->payload()->GetName() << std::endl;
>
> When I compile the file, I get an error saying that the compiler
> cannot recognize the GetName() function. I wonder if I need to
> #include other files. My reference is this archive:
> http://www.lists.cs.ucla.edu/pipermail/ndnsim/2014-July/001329.html
>
> Thank you for your help in advance.
>
> Sincerely,
>
> Kanin Assantachai
>
More information about the ndnSIM
mailing list