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 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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.
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;
}