patched winscale option impl draft
authorAnh Nguyen <trucanh524@gmail.com>
Wed, 27 Aug 2014 14:39:08 -0500
changeset 10863 0b0cbb284706
parent 10862 968da64da5b4
child 10864 3cd16e3b0974
patched winscale option impl
src/internet/model/tcp-option-end.cc
src/internet/model/tcp-option-end.h
src/internet/model/tcp-option-mss.cc
src/internet/model/tcp-option-mss.h
src/internet/model/tcp-option-nop.cc
src/internet/model/tcp-option-nop.h
src/internet/model/tcp-option-winscale.cc
src/internet/model/tcp-option-winscale.h
src/internet/model/tcp-option.cc
src/internet/model/tcp-option.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-end.cc	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,82 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#include "tcp-option-end.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (TcpOptionEnd);
+
+TcpOptionEnd::TcpOptionEnd ()
+    : TcpOption ()
+{
+}
+
+TcpOptionEnd::~TcpOptionEnd ()
+{
+}
+
+TypeId
+TcpOptionEnd::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::TcpOptionEnd")
+    .SetParent<TcpOption> ()
+    .AddConstructor<TcpOptionEnd> ()
+  ;
+  return tid;
+}
+
+TypeId
+TcpOptionEnd::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void
+TcpOptionEnd::Print (std::ostream &os) const
+{
+}
+
+uint32_t
+TcpOptionEnd::GetSerializedSize (void) const
+{
+  return 1;
+}
+
+void
+TcpOptionEnd::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  i.WriteU8 (GetKind ());
+}
+
+uint32_t
+TcpOptionEnd::Deserialize (Buffer::Iterator start)
+{
+  return 1;
+}
+
+uint8_t
+TcpOptionEnd::GetKind (void) const
+{
+  return TcpOption::END;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-end.h	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,52 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#ifndef TCP_OPTION_END_H
+#define TCP_OPTION_END_H
+
+#include "tcp-option.h"
+
+namespace ns3 {
+
+/**
+ * Defines the TCP option of kind 0 (end of option list) as in RFC793
+ */
+
+class TcpOptionEnd : public TcpOption
+{
+public:
+  TcpOptionEnd ();
+  virtual ~TcpOptionEnd ();
+
+  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;
+protected:
+};
+
+} // namespace ns3
+
+#endif /* TCP_OPTION_END_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-mss.cc	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,102 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#include "tcp-option-mss.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (TcpOptionMSS);
+
+TcpOptionMSS::TcpOptionMSS ()
+  : TcpOption (),
+    m_mss (1460)
+{
+}
+
+TcpOptionMSS::~TcpOptionMSS ()
+{
+}
+
+TypeId
+TcpOptionMSS::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::TcpOptionMSS")
+    .SetParent<TcpOption> ()
+    .AddConstructor<TcpOptionMSS> ()
+  ;
+  return tid;
+}
+
+TypeId
+TcpOptionMSS::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void
+TcpOptionMSS::Print (std::ostream &os) const
+{
+  os << m_mss;
+}
+
+uint32_t
+TcpOptionMSS::GetSerializedSize (void) const
+{
+  return 4;
+}
+
+void
+TcpOptionMSS::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  i.WriteU8 (GetKind ()); // Kind
+  i.WriteU8 (4); // Length
+  i.WriteHtonU16 (m_mss); // Max segment size
+}
+
+uint32_t
+TcpOptionMSS::Deserialize (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  uint8_t size = i.ReadU8 ();
+  NS_ASSERT (size == 4);
+  m_mss = i.ReadNtohU16 ();
+  return 4;
+}
+
+uint8_t
+TcpOptionMSS::GetKind (void) const
+{
+  return TcpOption::MSS;
+}
+
+uint16_t
+TcpOptionMSS::GetMSS (void) const
+{
+  return m_mss;
+}
+
+void
+TcpOptionMSS::SetMSS (uint16_t mss)
+{
+  m_mss = mss;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-mss.h	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,56 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#ifndef TCP_OPTION_MSS_H
+#define TCP_OPTION_MSS_H
+
+#include "tcp-option.h"
+
+namespace ns3 {
+
+/**
+ * Defines the TCP option of kind 2 (maximum segment size) as in RFC793
+ */
+
+class TcpOptionMSS : public TcpOption
+{
+public:
+  TcpOptionMSS ();
+  virtual ~TcpOptionMSS ();
+
+  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;
+
+  uint16_t GetMSS (void) const;
+  void SetMSS (uint16_t mss);
+protected:
+  uint16_t m_mss; // maximum segment size
+};
+
+} // namespace ns3
+
+#endif /* TCP_OPTION_MSS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-nop.cc	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,82 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#include "tcp-option-nop.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (TcpOptionNOP);
+
+TcpOptionNOP::TcpOptionNOP ()
+    : TcpOption ()
+{
+}
+
+TcpOptionNOP::~TcpOptionNOP ()
+{
+}
+
+TypeId
+TcpOptionNOP::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::TcpOptionNOP")
+    .SetParent<TcpOption> ()
+    .AddConstructor<TcpOptionNOP> ()
+  ;
+  return tid;
+}
+
+TypeId
+TcpOptionNOP::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void
+TcpOptionNOP::Print (std::ostream &os) const
+{
+}
+
+uint32_t
+TcpOptionNOP::GetSerializedSize (void) const
+{
+  return 1;
+}
+
+void
+TcpOptionNOP::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  i.WriteU8 (GetKind ());
+}
+
+uint32_t
+TcpOptionNOP::Deserialize (Buffer::Iterator start)
+{
+  return 1;
+}
+
+uint8_t
+TcpOptionNOP::GetKind (void) const
+{
+  return TcpOption::NOP;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-nop.h	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,52 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#ifndef TCP_OPTION_NOP_H
+#define TCP_OPTION_NOP_H
+
+#include "tcp-option.h"
+
+namespace ns3 {
+
+/**
+ * Defines the TCP option of kind 1 (no operation) as in RFC793
+ */
+
+class TcpOptionNOP : public TcpOption
+{
+public:
+  TcpOptionNOP ();
+  virtual ~TcpOptionNOP ();
+
+  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;
+protected:
+};
+
+} // namespace ns3
+
+#endif /* TCP_OPTION_NOP_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-winscale.cc	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,107 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ * Documentation, test cases: Natale Patriciello <natale.patriciello@gmail.com>
+ */
+
+#include "tcp-option-winscale.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (TcpOptionWinScale);
+
+TcpOptionWinScale::TcpOptionWinScale ()
+  : TcpOption (),
+    m_scale (0)
+{
+}
+
+TcpOptionWinScale::~TcpOptionWinScale ()
+{
+}
+
+TypeId
+TcpOptionWinScale::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::TcpOptionWinScale")
+    .SetParent<TcpOption> ()
+    .AddConstructor<TcpOptionWinScale> ()
+  ;
+  return tid;
+}
+
+TypeId
+TcpOptionWinScale::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void
+TcpOptionWinScale::Print (std::ostream &os) const
+{
+  os << m_scale;
+}
+
+uint32_t
+TcpOptionWinScale::GetSerializedSize (void) const
+{
+  return 3;
+}
+
+void
+TcpOptionWinScale::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  i.WriteU8 (GetKind ()); // Kind
+  i.WriteU8 (3); // Length
+  i.WriteU8 (m_scale); // Max segment size
+}
+
+uint32_t
+TcpOptionWinScale::Deserialize (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  uint8_t size = i.ReadU8 ();
+  NS_ASSERT (size == 3);
+  m_scale = i.ReadU8 ();
+  return 3;
+}
+
+uint8_t
+TcpOptionWinScale::GetKind (void) const
+{
+  return TcpOption::WINSCALE;
+}
+
+uint8_t
+TcpOptionWinScale::GetScale (void) const
+{
+  NS_ASSERT (m_scale <= 14);
+
+  return m_scale;
+}
+
+void
+TcpOptionWinScale::SetScale (uint8_t scale)
+{
+  NS_ASSERT (scale <= 14);
+
+  m_scale = scale;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option-winscale.h	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,129 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ * Documentation, test cases: Natale Patriciello <natale.patriciello@gmail.com>
+ */
+
+#ifndef TCP_OPTION_WINSCALE_H
+#define TCP_OPTION_WINSCALE_H
+
+#include "tcp-option.h"
+
+namespace ns3 {
+
+/**
+ * \brief Defines the TCP option of kind 3 (window scale option) as in RFC1323
+ *
+ * For more efficient use of high bandwidth networks, a larger TCP window size
+ * may be used. The TCP window size field controls the flow of data and its
+ * value is limited to between 2 and 65,535 bytes.
+ *
+ * Since the size field cannot be expanded, a scaling factor is used.
+ * The TCP window scale option, as defined in RFC 1323, is an option used
+ * to increase the maximum window size from 65,535 bytes to 1 gigabyte.
+ * Scaling up to larger window sizes is a part of what is necessary for TCP Tuning.
+ *
+ * The window scale option is used only during the TCP 3-way handshake.
+ * The window scale value represents the number of bits to left-shift the
+ * 16-bit window size field. The window scale value can be set from 0
+ * (no shift) to 14 for each direction independently. Both sides must
+ * send the option in their SYN segments to enable window scaling in
+ * either direction.
+ */
+class TcpOptionWinScale : public TcpOption
+{
+public:
+  static TypeId GetTypeId (void);
+  virtual TypeId GetInstanceTypeId (void) const;
+
+  /**
+   * \brief Create the option
+   *
+   * The scale is initialized with a 0U value.
+   */
+  TcpOptionWinScale ();
+
+  /**
+   * \brief Deconstructor
+   */
+  virtual ~TcpOptionWinScale ();
+
+  /**
+   * \brief Print the option to a ostream
+   *
+   * Only the window scale (uint8_t) is printed out.
+   *
+   * \param os Stream to which print the option to
+   */
+  virtual void Print (std::ostream &os) const;
+
+  /**
+   * \brief Serialize the option to a Buffer
+   *
+   * The option writes three U8: kind, length, and the scale.
+   *
+   * \param start Buffer::Iterator to which write to
+   */
+  virtual void Serialize (Buffer::Iterator start) const;
+
+  /**
+   * \brief Deserialize the option from a Buffer
+   *
+   * The option read two U8: length, and the scale. Kind SHOULD be read
+   * before call this method.
+   *
+   * \param start Buffer::Iterator to which read from
+   */
+  virtual uint32_t Deserialize (Buffer::Iterator start);
+
+  /**
+   * \brief Get the kind value for this option
+   *
+   * \return Fixed value, TcpOption::WINSCALE
+   */
+  virtual uint8_t GetKind (void) const;
+
+  /**
+   * \brief Get the serialized size of the option
+   *
+   * \return Fixed value, 3
+   */
+  virtual uint32_t GetSerializedSize (void) const;
+
+  /**
+   * \brief Get the scale value (uint8_t)
+   * \return The scale value
+   */
+  uint8_t GetScale (void) const;
+
+  /**
+   * \brief Set the scale option
+   *
+   * The scale option SHOULD be <= 14 (as RFC).
+   *
+   * \param scale Scale factor
+   */
+  void SetScale (uint8_t scale);
+
+protected:
+  uint8_t m_scale; //!< Window scaling in number of bit shift
+};
+
+} // namespace ns3
+
+#endif /* TCP_OPTION_WINSCALE */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option.cc	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,97 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#include "tcp-option.h"
+#include "tcp-option-end.h"
+#include "tcp-option-nop.h"
+#include "tcp-option-mss.h"
+#include "tcp-option-winscale.h"
+//#include "tcp-option-sack-permitted.h"
+//#include "tcp-option-sack.h"
+//#include "tcp-option-ts.h"
+//#include "tcp-option-snack.h"
+
+#include "ns3/type-id.h"
+
+#include <vector>
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (TcpOption);
+
+
+TcpOption::TcpOption ()
+{
+}
+
+TcpOption::~TcpOption ()
+{
+}
+
+TypeId
+TcpOption::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::TcpOption")
+    .SetParent<Object> ()
+  ;
+  return tid;
+}
+
+TypeId
+TcpOption::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+Ptr<TcpOption>
+TcpOption::CreateOption (uint8_t kind)
+{
+  struct kindToTid
+    {
+      TcpOption::Kind kind;
+      TypeId tid;
+    };
+
+  static ObjectFactory objectFactory;
+  static kindToTid toTid[] =
+    {
+      { TcpOption::END,       TcpOptionEnd::GetTypeId () },
+      { TcpOption::MSS,       TcpOptionMSS::GetTypeId () },
+      { TcpOption::NOP,       TcpOptionNOP::GetTypeId () },
+ //     { TcpOption::SACK,      TcpOptionSack::GetTypeId () },
+ //     { TcpOption::SACK_PERM, TcpOptionSackPermitted::GetTypeId () },
+ //     { TcpOption::SNACK,     TcpOptionSnack::GetTypeId () },
+ //     { TcpOption::TS,        TcpOptionTS::GetTypeId () },
+      { TcpOption::WINSCALE,  TcpOptionWinScale::GetTypeId () }
+    };
+
+  for (unsigned int i=0; i < sizeof(toTid)/sizeof(kindToTid); ++i)
+    {
+      if (toTid[i].kind == kind)
+        {
+          objectFactory.SetTypeId(toTid[i].tid);
+          return objectFactory.Create<TcpOption> ();
+        }
+    }
+
+  return 0;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet/model/tcp-option.h	Wed Aug 27 14:39:08 2014 -0500
@@ -0,0 +1,67 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Adrian Sai-wah Tam
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
+ */
+
+#ifndef TCP_OPTION_H
+#define TCP_OPTION_H
+
+#include <stdint.h>
+#include "ns3/object.h"
+#include "ns3/buffer.h"
+#include "ns3/object-factory.h"
+
+namespace ns3 {
+
+/**
+ * Base class for all kinds of TCP options
+ */
+class TcpOption : public Object
+{
+public:
+  TcpOption ();
+  virtual ~TcpOption ();
+
+  static TypeId GetTypeId (void);
+  virtual TypeId GetInstanceTypeId (void) const;
+
+  enum Kind
+  {
+      END = 0,
+      NOP = 1,
+      MSS = 2,
+      WINSCALE = 3,
+//      SACK_PERM = 4,
+//      SACK = 5,
+//      TS = 8,
+//      SNACK = 21
+  };
+
+  virtual void Print (std::ostream &os) const = 0;
+  virtual void Serialize (Buffer::Iterator start) const = 0;
+  virtual uint32_t Deserialize (Buffer::Iterator start) = 0;
+
+  virtual uint8_t GetKind (void) const = 0; // Get the `kind' (as in RFC793) of this option
+  virtual uint32_t GetSerializedSize (void) const = 0; // Get the total length of this option, >= 1
+
+  static Ptr<TcpOption> CreateOption (uint8_t kind); // Factory method for all options
+};
+
+} // namespace ns3
+
+#endif /* TCP_OPTION */