move unknown TCP option handling with the base class
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
#include <iostream>
|
||||
#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"
|
||||
|
||||
@@ -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<TcpOption> ()
|
||||
.AddConstructor<TcpOptionUnknown> ()
|
||||
;
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,9 +24,12 @@
|
||||
#include "tcp-option-ts.h"
|
||||
|
||||
#include "ns3/type-id.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
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<TcpOption> ()
|
||||
.AddConstructor<TcpOptionUnknown> ()
|
||||
;
|
||||
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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user