[ndnSIM] regarding block.hpp

Alex Afanasyev aa at CS.UCLA.EDU
Mon Feb 8 17:34:24 PST 2016


> On Feb 8, 2016, at 3:10 PM, Carl Zu <carlzu8 at gmail.com> wrote:
> 
> I think lack of documentation is a problem...
> 
> I wanted to write some bytes in the interest message in ndnSIM. In ns3, thanks to their documentation, one can easily understand that in order to write some bytes, he should serialize a header.
> 
> For doing the same thing in ndnSIM, I have had the impression that I should use "block". Moreover, It looks as though an interest message is a set of TLVs (based on the explanation in the NDN project website). So probably if I like to write eight bytes as four pieces of two-byte data, I should write four TLVs. But indeed, there are many constructors in block.hpp, and it's just about looking at one code after another to understand each of them due to lack of documentation...

Hi Carl,

I think you're looking into a slightly wrong place.  If you want to extend Interest, you need first define your own TLV (which type to use and specific content).  For simple things you don't need to define your own class, you can simply store the actual value in some standard type, say char[8].  After doing so, the only part remain is to update serialization/deserialization methods of interest.cpp which are called  wireEncode and wireDecode.

I will agree that there is limited documentation, but there are many examples of this encoding.

add variable to keep your data (and getter/setter methods when needed):

    char m_myValue[8];

Add the following to the wireEncode (note that encoding is done in reverse order):

    totalLength += encoder.prependByteArrayBlock(<YOUR_TYPE>, m_myValue, 8);

And the following to the wireDecode:

      val = m_wire.find(<YOUR_TYPE>);
      if (val != m_wire.elements_end()) {
         memcpy(m_myValue, val->value(), val->value_size());
      else
         memset(m_myValue, 0, 8);

---
Alex

> 
> Can someone please give some guidance ???.
> 
> thanks and rgds.
> C
> _______________________________________________
> ndnSIM mailing list
> ndnSIM at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20160208/6196d88e/attachment.bin>


More information about the ndnSIM mailing list