From 9d2770100d9aa4cdd0195b374f313d9e4807dcf3 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 6 Sep 2014 09:40:18 -0700 Subject: [PATCH] last TCP option should be END, not NOP --- src/internet/model/tcp-header.cc | 18 +++++++++++++----- src/internet/test/tcp-header-test.cc | 19 ++++++++----------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/internet/model/tcp-header.cc b/src/internet/model/tcp-header.cc index 096ad5fdf..eb73b5099 100644 --- a/src/internet/model/tcp-header.cc +++ b/src/internet/model/tcp-header.cc @@ -21,6 +21,7 @@ #include #include #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) diff --git a/src/internet/test/tcp-header-test.cc b/src/internet/test/tcp-header-test.cc index 263446f26..d87216f5b 100644 --- a/src/internet/test/tcp-header-test.cc +++ b/src/internet/test/tcp-header-test.cc @@ -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"); } {