[ndnSIM] How to add additional std::vector<std::string> type field in Interest packet

Mudasir Qazi mudasirqazi00 at gmail.com
Tue May 22 05:57:20 PDT 2018


Hi, can anyone answer to this question please? I'm still unable to solve it.

On Sat, 19 May 2018 at 12:54, Mudasir Qazi <mudasirqazi00 at gmail.com> wrote:

> Hi,
> I need to add and an Integer and std::vector<std::string> type additional
> fields in the Interest packet. I have done following steps to do so:
> 1. Added private fields (say: m_MyInteger and m_MyVector) in
> *interest.hpp* file and write necessary getters, setters and helper
> functions to manipulate these private members
> 2. Added MyVector = 40002 and MyInteger = 40003 in the enum in* tlv.hpp*
> file
> 3. Added following code blocks in wireEncode method in *interest.cpp*
> //for MyVector
> std::vector<std::string> myTempVector = this->getMyVector();
>     totalLength += encoder.prependByteArray(
>             reinterpret_cast<uint8_t*>(&myTempVector),
> sizeof(myTempVector));
>     totalLength += encoder.prependVarNumber(sizeof(myTempVector));
>     totalLength += encoder.prependVarNumber(tlv::MyVector);
>
> //for MyInteger
> int myTempInt = this->getMyInteger();
>     totalLength += encoder.prependByteArray(
>             reinterpret_cast<uint8_t*>(&myTempInt), sizeof(myTempInt));
>     totalLength += encoder.prependVarNumber(sizeof(myTempInt));
>     totalLength += encoder.prependVarNumber(tlv::MyInteger);
>
> 4. Added following code blocks in wireDecode method in *interest.cpp*
> //for MyVector
> val = m_wire.find(tlv::MyVector);
> if (val == m_wire.elements_end()) {
>     BOOST_THROW_EXCEPTION(Error("MyVector element is missing"));
> }
> std::vector<std::string> myTemVector;
> if (val->value_size() != sizeof(myTemVector)) {
>     BOOST_THROW_EXCEPTION(Error("myTemVector element is malformed"));
> }
> std::memcpy(&myTemVector, val->value(), sizeof(myTemVector));
> m_MyVector = myTemVector;
>
> //for MyInteger
> val = m_wire.find(tlv::MyInteger);
> if (val == m_wire.elements_end()) {
>     BOOST_THROW_EXCEPTION(Error("MyInteger element is missing"));
> }
> uint32_t myTmpInteger = 0;
> if (val->value_size() != sizeof(myTmpInteger)) {
>     BOOST_THROW_EXCEPTION(Error("myTmpInteger element is malformed"));
> }
> std::memcpy(&myTmpInteger, val->value(), sizeof(myTmpInteger));
> m_MyInteger = myTmpInteger;
>
> 5. I need to create a copy of Interest from an existing Interest (say:
> existingInterest), so I'm using this way to create an Interest:
> auto myInterest =
> std::make_shared<Interest>(existingInterest.wireEncode());
>
> *Problem:* I'm following these 1-to-5 steps in order to add an Integer
> and a std::vector<std::string> fields in Interest packet but it gives an
> error on *wireDecode* while decoding MyVector field and simulation stops
> and terminates. But it does not give error on MyInteger field. Am I doing
> it right? Am I missing something? Please help me solving this I'm stuck on
> this point from many days.
>
> --
> Regards,
> Mudasir Qazi
>


-- 
Regards,
Mudasir Qazi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20180522/f89bf02a/attachment-0001.html>


More information about the ndnSIM mailing list