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?