hello message modifications

75 views
Skip to first unread message

D_SMT

unread,
Apr 13, 2016, 4:56:40 AM4/13/16
to ns-3-users
Hi all,

I want to add a new field to the hello message. This field specifies the cluster head address for each neighbor so the Hello message would look like this:
 //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |          Reserved             |     Htime     |  Willingness  | Qos 
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |   Link Code   |   Reserved    |       Link Message Size       |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                  Neighbor Interface Address                   |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                     CH   Address                                                    |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                  Neighbor Interface Address                   |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                     CH   Address                                                    |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |   Link Code   |   Reserved    |       Link Message Size       |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
I added the following modification on the existing hello message: 
   struct LinkMessage {
        uint8_t linkCode;
        std::vector<Ipv4Address> neighborInterfaceAddresses;
 std::vector<Ipv4Address> ClusterheadAddresses;
    }; 

Then I modified the GetSerializedSize, Serialize and Deserialize as below. But I got n error while trying to compile the code. I believe that the error resulted from an incorrect deserialization but I was not able to spot the error. Can someone advise me on this matter.
Thanks in advance.


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 ()) + (IPV4_ADDRESS_SIZE * lm.ClusterheadAddresses.size ()) ; // this line is added in order to add on more ip address (address for the CH)

    }
  return size+1;
}

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


  i.WriteU8 (0); // Reserved
  i.WriteU8 (this->H); 
  ///////////////////////////
  i.WriteU8 (this->hTime);
  i.WriteU8 (this->willingness);

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

  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)+ (lm.ClusterheadAddresses.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 ());


        }
 
 
  for (std::vector<Ipv4Address>::const_iterator neigh_ite = lm.ClusterheadAddresses.begin ();
           neigh_ite != lm.ClusterheadAddresses.end (); neigh_ite++)
        {
          i.WriteHtonU32 (neigh_ite->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.ReadU8(); // Reserved 
  this->H= i.ReadU8();
  /////////////////

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

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

  //helloSizeLeft -= 4;
    helloSizeLeft -= 5; // added by me


  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 = (2*(lmSize - 4) )/( IPV4_ADDRESS_SIZE); n; --n)
        {
           lm.neighborInterfaceAddresses.push_back (Ipv4Address (i.ReadNtohU32 ()));
   lm.ClusterheadAddresses.push_back (Ipv4Address (i.ReadNtohU32 ()));

        }

      helloSizeLeft -= lmSize;
      this->linkMessages.push_back (lm);
    }

  return messageSize;
}



Konstantinos

unread,
Apr 13, 2016, 5:13:25 AM4/13/16
to ns-3-users
Hi,

If the error is generated from the compiler then it should fairly easy to identify it as the compiler usually says which like has the error.
Without the error message it will be quite difficult it identify it ourselves. 

K.

Doaa Terri

unread,
Apr 13, 2016, 5:17:01 AM4/13/16
to ns-3-users
Actually when I tried to compile, I got a break in the buffer.h file , specifically in the below line 
      uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];


--
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/JYQXOqiGoIU/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.

D_SMT

unread,
Apr 13, 2016, 5:18:00 AM4/13/16
to ns-3-users
Actually when I tried to compile, I got a break in the buffer.h file , specifically in the below line 
      uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];




Konstantinos

unread,
Apr 13, 2016, 5:37:56 AM4/13/16
to ns-3-users
Is it a compiler or runtime error? I would not expect it to be a compiler error.
Check more carefully what you write/read from the buffer (number of bytes, order etc).

For example I spotted a possible error. While you read and write 5 static bytes at the beginning (Reserved, H, hTime, willingness, QoS), in the SerializedSize you start from 4 not five 
uint32_t size = 4;
 
Further, I would make sure that the size of the packet is aligned (https://www.kernel.org/doc/htmldocs/80211/bk02pt01ch04s03.html)

K.

D_SMT

unread,
Apr 13, 2016, 6:40:47 AM4/13/16
to ns-3-users
Bu at the end of the Getserialization I wrote 
return size +1; 

D_SMT

unread,
Apr 13, 2016, 8:07:50 AM4/13/16
to ns-3-users
Actually everything was working fine untill I added the last field (cluster head address) and this is how i write/read it 
writing: 
   for (std::vector<Ipv4Address>::const_iterator neigh_ite = lm.ClusterheadAddresses.begin ();
           neigh_ite != lm.ClusterheadAddresses.end (); neigh_ite++)
        {
          i.WriteHtonU32 (neigh_ite->Get ());

        }

Reading: 

      for (int n = (2*(lmSize - 4) )/( IPV4_ADDRESS_SIZE); n; --n)
        {
           lm.neighborInterfaceAddresses.push_back (Ipv4Address (i.ReadNtohU32 ()));
   lm.ClusterheadAddresses.push_back (Ipv4Address (i.ReadNtohU32 ()));

        }

so what would be possible to be wrong? 

Konstantinos

unread,
Apr 13, 2016, 9:02:51 AM4/13/16
to ns-3-users
Hi,

when I said in my previous email to check how you write/read, I meant it.
Particularly you write all the Neighbour addresses and then you write the CH.
However, when you read, you read them together. So, check the loops.

Regards,
K.

D_SMT

unread,
Apr 13, 2016, 12:39:56 PM4/13/16
to ns-3-users
Thanks for the reply
How can I read the two vectors together in one loop since they are two different vectors?
any hint please? 

Konstantinos

unread,
Apr 13, 2016, 4:22:47 PM4/13/16
to ns-3-users
Hi,

You have to make clear what you want to have, based on your design

  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                  Neighbor Interface Address                   |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                     CH   Address                                                    |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                  Neighbor Interface Address                   |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  //       |                     CH   Address                                                    |
  //       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

This shows that you write one neighbor and then one CH, then the second neighbor and the second CH.
This is implemented correct in the reading part of your code but not in the writing.
Is in principle ClusterheadAddresses.size() == neighborInterfaceAddresses.size()?

Then you can have a single loop.

Regards,
K

Doaa Terri

unread,
Apr 15, 2016, 3:50:56 AM4/15/16
to ns-3-users
Yes ClusterheadAddresses.size() == neighborInterfaceAddresses.size(), I tried to have one loop but this did not work. I got the same problem

   std::vector<Ipv4Address>::const_iterator itn=lm.neighborInterfaceAddresses.begin ();
  std::vector<Ipv4Address>::const_iterator it=lm.ClusterheadAddresses.begin ();
  int dz= lm.ClusterheadAddresses.size();
 for (int dii= 0; dii<dz;dii++)

  {

  i.WriteHtonU32(itn->Get());
  i.WriteHtonU32(it->Get());
  itn++;
  it++;
  }

Reply all
Reply to author
Forward
0 new messages