last TCP option should be END, not NOP

This commit is contained in:
Tom Henderson
2014-09-06 09:40:18 -07:00
parent 287bda5b7e
commit 9d2770100d
2 changed files with 21 additions and 16 deletions

View File

@@ -21,6 +21,7 @@
#include <stdint.h>
#include <iostream>
#include "tcp-header.h"
#include "tcp-option.h"
#include "ns3/buffer.h"
#include "ns3/address-utils.h"
#include "ns3/log.h"
@@ -326,12 +327,19 @@ TcpHeader::Serialize (Buffer::Iterator start) const
i.Next ((*op)->GetSerializedSize ());
}
// padding
// padding to word alignment; add NOPs as needed until last byte which is END
while (optionLen % 4)
{
++optionLen;
i.WriteU8 (0);
}
{
if ((optionLen % 4) == 3)
{
i.WriteU8 (TcpOption::END);
}
else
{
i.WriteU8 (TcpOption::NOP);
}
++optionLen;
}
// Make checksum
if(m_calcChecksum)

View File

@@ -265,21 +265,18 @@ TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime ()
buffer.GetSize (), "Header not correctly serialized");
// Inserted only 1 byte NOP, and so implementation should pad; so
// the other 3 bytes should be NOP (so 4 byte NOP)
// the other 3 bytes should be NOP, NOP, END
Buffer::Iterator i = buffer.Begin ();
i.Next (20);
uint8_t value = i.ReadU8 ();
NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present");
for (uint32_t j = 1; j < 4; ++j)
{
std::stringstream ss;
ss << j;
value = i.ReadU8 ();
NS_TEST_ASSERT_MSG_EQ (value, 0,
"Header not padded with 0 at position " + ss.str ());
}
NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 1");
value = i.ReadU8 ();
NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 2");
value = i.ReadU8 ();
NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 3");
value = i.ReadU8 ();
NS_TEST_ASSERT_MSG_EQ (value, TcpOption::END, "END not present at byte 4");
}
{