problem with adding a new field to the hello msg

42 views
Skip to first unread message

Doaa

unread,
Feb 14, 2016, 5:21:07 AM2/14/16
to ns-3-users
Hi all 
I am trying to add new field to the hello msg called "qos"
I made the following changes changes 
I added in hello struct in olsr-header.h 
struct Hello
  {
    struct LinkMessage {
      uint8_t linkCode;
      std::vector<Ipv4Address> neighborInterfaceAddresses;
    };
// add the qos variable 
uint8_t qos;


and in olsr-header.cc , I modified GetSerializedSize,Serialized and DeSerialize functions as follows


uint32_t 
MessageHeader::Hello::GetSerializedSize (void) const
{
  uint32_t size = 4;
  for (std::vector<LinkMessage>::const_iterator iter = this->linkMessages.begin ();
       iter != this->linkMessages.end (); iter++)
    {
      const LinkMessage &lm = *iter;
 size += 4;
      size += IPV4_ADDRESS_SIZE * lm.neighborInterfaceAddresses.size ();
    }
  return size+1;
}





void
MessageHeader::Hello::Serialize (Buffer::Iterator start) const
{
  Buffer::Iterator i = start;

  i.WriteU16 (0); // Reserved

  i.WriteU8 (this->hTime);
  i.WriteU8 (this->willingness);
  ///////////////////
  i.WriteU8 (this->qos);   //////// 
 for (std::vector<LinkMessage>::const_iterator iter = this->linkMessages.begin ();
       iter != this->linkMessages.end (); iter++)
    {
      const LinkMessage &lm = *iter;

      i.WriteU8 (lm.linkCode);
      i.WriteU8 (0); // Reserved

      // The size of the link message, counted in bytes and measured
      // from the beginning of the "Link Code" field and until the
      // next "Link Code" field (or - if there are no more link types
      // - the end of the message).
      i.WriteHtonU16 (4 + lm.neighborInterfaceAddresses.size () * IPV4_ADDRESS_SIZE);

      for (std::vector<Ipv4Address>::const_iterator neigh_iter = lm.neighborInterfaceAddresses.begin ();
           neigh_iter != lm.neighborInterfaceAddresses.end (); neigh_iter++)
        {
          i.WriteHtonU32 (neigh_iter->Get ());
        }
    }
}





uint32_t
MessageHeader::Hello::Deserialize (Buffer::Iterator start, uint32_t messageSize)
{
  Buffer::Iterator i = start;

  NS_ASSERT (messageSize >= 4);

  this->linkMessages.clear ();

  uint16_t helloSizeLeft = messageSize;

  i.ReadNtohU16 (); // Reserved
  this->hTime = i.ReadU8 ();
  this->willingness = i.ReadU8 ();

  /////////// added by me
  this->qos= i.ReadU8();

  //helloSizeLeft -= 4;
    helloSizeLeft -= 5; // 


  while (helloSizeLeft)
    {
      LinkMessage lm;
      NS_ASSERT (helloSizeLeft >= 4);
      lm.linkCode = i.ReadU8 ();
      i.ReadU8 (); // Reserved
      uint16_t lmSize = i.ReadNtohU16 ();
      NS_ASSERT ((lmSize - 4) % IPV4_ADDRESS_SIZE == 0);
      for (int n = (lmSize - 4) / IPV4_ADDRESS_SIZE; n; --n)
//for (int n = (lmSize - 5) / IPV4_ADDRESS_SIZE; n; --n)

        {
          lm.neighborInterfaceAddresses.push_back (Ipv4Address (i.ReadNtohU32 ()));
        }
      helloSizeLeft -= lmSize;
      this->linkMessages.push_back (lm);
    }

  return messageSize;
}


Then, I ran the code without errors. 
But when I used PCAP to check the packet, there was this  : Not enough bytes for last Hello entry

So what is missing in what I did ? 
can anyone help please?

Tommaso Pecorella

unread,
Feb 14, 2016, 5:42:05 AM2/14/16
to ns-3-users


On Sunday, February 14, 2016 at 11:21:07 AM UTC+1, Doaa wrote:
Hi all 
I am trying to add new field to the hello msg called "qos"
I made the following changes changes 
I added in hello struct in olsr-header.h 
....
Then, I ran the code without errors. 
But when I used PCAP to check the packet, there was this  : Not enough bytes for last Hello entry

So what is missing in what I did ? 
can anyone help please?

Hi,

let's see what Captain Picard have to say about this:

 
Thanks Captain for your insights.

Wireshark decodes packets by using a dissector. The dissector is built to decode packets that are following the standard, do you think that it could magically know that you added a byte in the middle of the header and do the right thing ?
According to your logic, the next thing you're assuming is that the computer will self-write all the code it's needed to handle your new byte, perhaps overnight and while you're sleeping, right ?

Now, there are only two alternatives for the question you made.
1) You're so tired that your brain is disconnected.
2) your brain is naturally disconnected.

I believe that it's case 1. The solution is to stop doing what you're doing and relax for some time (from a couple of hours to a couple of weeks, depending on you).
The brain is like every other part of your body. Would you keep cutting wood logs with your arms so tired to be hurting ? No.
Then why should you keep programming and debugging when you can't concentrate and you have this kind of doubts ?

T.

PS: to have your new packet being recognized by Wireshark you'd need to modify the Wireshark code and rebuild it. I would not suggest to even try, Wireshark is huge and it's not an easy code.

Doaa Terri

unread,
Feb 14, 2016, 6:01:54 AM2/14/16
to ns-3-users
Hi Tommaso 
Thank you for your reply. 
Regarding your comment, actually its case 1 but the problem is that I have "Deadlines" :P
I hope my supervisor asks me the same thing you asked me to do :P (about the relaxation thing)

Thanks again for the clarifications


--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/vf6QQVkL05U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages