From d4901ad3b0b2c7eace75559bd618c783dff10b2a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 10 Sep 2014 17:31:46 -0700 Subject: [PATCH] move unknown TCP option handling with the base class --- src/internet/model/tcp-header.cc | 1 - src/internet/model/tcp-option-rfc793.cc | 79 ------------------------ src/internet/model/tcp-option-rfc793.h | 33 ---------- src/internet/model/tcp-option.cc | 80 +++++++++++++++++++++++++ src/internet/model/tcp-option.h | 33 ++++++++++ 5 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/internet/model/tcp-header.cc b/src/internet/model/tcp-header.cc index 3ddaee5ea..c3dd30005 100644 --- a/src/internet/model/tcp-header.cc +++ b/src/internet/model/tcp-header.cc @@ -22,7 +22,6 @@ #include #include "tcp-header.h" #include "tcp-option.h" -#include "tcp-option-rfc793.h" #include "ns3/buffer.h" #include "ns3/address-utils.h" #include "ns3/log.h" diff --git a/src/internet/model/tcp-option-rfc793.cc b/src/internet/model/tcp-option-rfc793.cc index 60688a393..c7dba540d 100644 --- a/src/internet/model/tcp-option-rfc793.cc +++ b/src/internet/model/tcp-option-rfc793.cc @@ -254,83 +254,4 @@ TcpOptionMSS::SetMSS (uint16_t mss) m_mss = mss; } -// Tcp Option Unknown - -NS_OBJECT_ENSURE_REGISTERED (TcpOptionUnknown); - -TcpOptionUnknown::TcpOptionUnknown () - : TcpOption () -{ - m_kind = 0xFF; - m_size = 0; -} - -TcpOptionUnknown::~TcpOptionUnknown () -{ -} - -TypeId -TcpOptionUnknown::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::TcpOptionUnknown") - .SetParent () - .AddConstructor () - ; - return tid; -} - -TypeId -TcpOptionUnknown::GetInstanceTypeId (void) const -{ - return GetTypeId (); -} - -void -TcpOptionUnknown::Print (std::ostream &os) const -{ - os << "Unknown option"; -} - -uint32_t -TcpOptionUnknown::GetSerializedSize (void) const -{ - return m_size; -} - -void -TcpOptionUnknown::Serialize (Buffer::Iterator i) const -{ - if (m_size == 0) - { - NS_LOG_WARN ("Can't Serialize an Unknown Tcp Option"); - return; - } - - i.WriteU8 (GetKind ()); - i.WriteU8 (GetSerializedSize ()); - i.Write (m_content, m_size-2); -} - -uint32_t -TcpOptionUnknown::Deserialize (Buffer::Iterator start) -{ - Buffer::Iterator i = start; - - m_kind = i.ReadU8 (); - NS_LOG_WARN ("Trying to Deserialize an Unknown Option of Kind " << int (m_kind)); - - m_size = i.ReadU8 (); - NS_ASSERT_MSG ((m_size >= 2) && (m_size < 40), "Unable to parse an Unknown Option of Kind " << int (m_kind) << " with apparent size " << int (m_size)); - - i.Read (m_content, m_size-2); - - return m_size; -} - -uint8_t -TcpOptionUnknown::GetKind (void) const -{ - return m_kind; -} - } // namespace ns3 diff --git a/src/internet/model/tcp-option-rfc793.h b/src/internet/model/tcp-option-rfc793.h index e3e197a3d..2ebf945c2 100644 --- a/src/internet/model/tcp-option-rfc793.h +++ b/src/internet/model/tcp-option-rfc793.h @@ -111,39 +111,6 @@ protected: uint16_t m_mss; //!< maximum segment size }; -/** - * \brief An unknown TCP option. - * - * An unknown option can be deserialized and (only if deserialized previously) - * serialized again. - */ -class TcpOptionUnknown : public TcpOption -{ -public: - TcpOptionUnknown (); - virtual ~TcpOptionUnknown (); - - /** - * \brief Get the type ID. - * \return the object TypeId - */ - static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; - - virtual void Print (std::ostream &os) const; - virtual void Serialize (Buffer::Iterator start) const; - virtual uint32_t Deserialize (Buffer::Iterator start); - - virtual uint8_t GetKind (void) const; - virtual uint32_t GetSerializedSize (void) const; - -private: - uint8_t m_kind; //!< The unknown option kind - uint32_t m_size; //!< The unknown option size - uint8_t m_content[40]; //!< The option data - -}; - } // namespace ns3 #endif // TCPOPTIONRFC793_H diff --git a/src/internet/model/tcp-option.cc b/src/internet/model/tcp-option.cc index 01c8e51ae..673635e86 100644 --- a/src/internet/model/tcp-option.cc +++ b/src/internet/model/tcp-option.cc @@ -24,9 +24,12 @@ #include "tcp-option-ts.h" #include "ns3/type-id.h" +#include "ns3/log.h" #include +NS_LOG_COMPONENT_DEFINE ("TcpOption"); + namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (TcpOption); @@ -104,4 +107,81 @@ TcpOption::IsKindKnown (uint8_t kind) return false; } +NS_OBJECT_ENSURE_REGISTERED (TcpOptionUnknown); + +TcpOptionUnknown::TcpOptionUnknown () + : TcpOption () +{ + m_kind = 0xFF; + m_size = 0; +} + +TcpOptionUnknown::~TcpOptionUnknown () +{ +} + +TypeId +TcpOptionUnknown::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::TcpOptionUnknown") + .SetParent () + .AddConstructor () + ; + return tid; +} + +TypeId +TcpOptionUnknown::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + +void +TcpOptionUnknown::Print (std::ostream &os) const +{ + os << "Unknown option"; +} + +uint32_t +TcpOptionUnknown::GetSerializedSize (void) const +{ + return m_size; +} + +void +TcpOptionUnknown::Serialize (Buffer::Iterator i) const +{ + if (m_size == 0) + { + NS_LOG_WARN ("Can't Serialize an Unknown Tcp Option"); + return; + } + + i.WriteU8 (GetKind ()); + i.WriteU8 (GetSerializedSize ()); + i.Write (m_content, m_size-2); +} + +uint32_t +TcpOptionUnknown::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + + m_kind = i.ReadU8 (); + NS_LOG_WARN ("Trying to Deserialize an Unknown Option of Kind " << int (m_kind)); + + m_size = i.ReadU8 (); + NS_ASSERT_MSG ((m_size >= 2) && (m_size < 40), "Unable to parse an Unknown Option of Kind " << int (m_kind) << " with apparent size " << int (m_size)); + + i.Read (m_content, m_size-2); + + return m_size; +} + +uint8_t +TcpOptionUnknown::GetKind (void) const +{ + return m_kind; +} + } // namespace ns3 diff --git a/src/internet/model/tcp-option.h b/src/internet/model/tcp-option.h index 461e23d5f..9fed484b4 100644 --- a/src/internet/model/tcp-option.h +++ b/src/internet/model/tcp-option.h @@ -107,6 +107,39 @@ public: static bool IsKindKnown (uint8_t kind); }; +/** + * \brief An unknown TCP option. + * + * An unknown option can be deserialized and (only if deserialized previously) + * serialized again. + */ +class TcpOptionUnknown : public TcpOption +{ +public: + TcpOptionUnknown (); + virtual ~TcpOptionUnknown (); + + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + + virtual void Print (std::ostream &os) const; + virtual void Serialize (Buffer::Iterator start) const; + virtual uint32_t Deserialize (Buffer::Iterator start); + + virtual uint8_t GetKind (void) const; + virtual uint32_t GetSerializedSize (void) const; + +private: + uint8_t m_kind; //!< The unknown option kind + uint32_t m_size; //!< The unknown option size + uint8_t m_content[40]; //!< The option data + +}; + } // namespace ns3 #endif /* TCP_OPTION */