Is there a error in Ipv4Header?

20 views
Skip to first unread message

NanerLee

unread,
Nov 28, 2016, 10:24:27 PM11/28/16
to ns-3-users
Hello everyone !

In the ipv4-header.h:241, there are some codes about flags related to IP fragmentation

  enum FlagsE {
    DONT_FRAGMENT = (1<<0),
    MORE_FRAGMENTS = (1<<1)
  };

But I think their positions are wrong, I think it should be:

  enum FlagsE {
    DONT_FRAGMENT = (1<<1),
    MORE_FRAGMENTS = (1<<0)
  };

is is right about my understanding ? If I am wrong, please tell me. Thanks!

Natale Patriciello

unread,
Nov 29, 2016, 10:50:13 AM11/29/16
to ns-3-...@googlegroups.com
Hi!

Please remember that the order in which they are declared is not the
order in which they are then serialized. If you want to look to that
order, please take a look in the Serialize () method.

Nat

NanerLee

unread,
Nov 29, 2016, 9:05:35 PM11/29/16
to ns-3-users
Thanks for your reply, But the order I said is not the order  in which they are declared. I means the positions left-shifted.

In the source code, DONT_FRAGMENT left-shifted by 0 = 001; MORE_FRAGMENTS left-shifted by 1 = 010.

As we know, DONT_FRAGMENT should set 1 at the second position(010), and MORE_FRAGMENTS should set 1 at the third position(001). So I think the positions is wrong.

在 2016年11月29日星期二 UTC+8下午11:50:13,Nat P写道:

Natale Patriciello

unread,
Nov 30, 2016, 4:32:59 AM11/30/16
to ns-3-...@googlegroups.com
On 29/11/16 at 06:05pm, NanerLee wrote:
> Thanks for your reply, But the order I said is not the order in which they
> are declared. I means the positions *left-shifted*.
>
> In the source code, DONT_FRAGMENT left-shifted by 0 = 001; MORE_FRAGMENTS
> left-shifted by 1 = 010.
>
> As we know, DONT_FRAGMENT should set 1 at the second position(010), and
> MORE_FRAGMENTS should set 1 at the third position(001). So I think the
> positions is wrong.


Hi,

I'm absolutely not an expert of the Ipv4 code, but I suggest you to not
focus on the declaration only, take also a look on the Serialize ()
method and the various Set*Fragments () methods.

Print the values, and then look what is written in the Serialize ()
and various Set*Fragments() methods. Just for reference, this is what goes on
the network:

uint32_t fragmentOffset = m_fragmentOffset / 8;
uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
if (m_flags & DONT_FRAGMENT)
{
flagsFrag |= (1<<6);
}
if (m_flags & MORE_FRAGMENTS)
{
flagsFrag |= (1<<5);
}
i.WriteU8 (flagsFrag);

In which the values DONT_FRAGMENT and MORE_FRAGMENTS are not written directly
into the buffer.


Nat

NanerLee

unread,
Nov 30, 2016, 5:42:25 AM11/30/16
to ns-3-users
Thanks for your detailed explanation,and I apologize for my lazy that I don't see the Serialize ()

And, now I understand the problem. Thank you again !
 

Reply all
Reply to author
Forward
0 new messages