A Discrete-Event Network Simulator
API
tcp-option.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Adrian Sai-wah Tam
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
18 */
19
20#include "tcp-option.h"
21
22#include "tcp-option-rfc793.h"
24#include "tcp-option-sack.h"
25#include "tcp-option-ts.h"
26#include "tcp-option-winscale.h"
27
28#include "ns3/log.h"
29#include "ns3/type-id.h"
30
31#include <vector>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("TcpOption");
37
39
41{
42}
43
45{
46}
47
50{
51 static TypeId tid = TypeId("ns3::TcpOption").SetParent<Object>().SetGroupName("Internet");
52 return tid;
53}
54
57{
58 return GetTypeId();
59}
60
63{
64 struct kindToTid
65 {
66 TcpOption::Kind kind;
67 TypeId tid;
68 };
69
70 static ObjectFactory objectFactory;
71 static kindToTid toTid[] = {{TcpOption::END, TcpOptionEnd::GetTypeId()},
79
80 for (unsigned int i = 0; i < sizeof(toTid) / sizeof(kindToTid); ++i)
81 {
82 if (toTid[i].kind == kind)
83 {
84 objectFactory.SetTypeId(toTid[i].tid);
85 return objectFactory.Create<TcpOption>();
86 }
87 }
88
89 return CreateObject<TcpOptionUnknown>();
90}
91
92bool
94{
95 switch (kind)
96 {
97 case END:
98 case NOP:
99 case MSS:
100 case WINSCALE:
101 case SACKPERMITTED:
102 case SACK:
103 case TS:
104 // Do not add UNKNOWN here
105 return true;
106 }
107
108 return false;
109}
110
112
114 : TcpOption()
115{
116 m_kind = 0xFF;
117 m_size = 0;
118}
119
121{
122}
123
124TypeId
126{
127 static TypeId tid = TypeId("ns3::TcpOptionUnknown")
129 .SetGroupName("Internet")
130 .AddConstructor<TcpOptionUnknown>();
131 return tid;
132}
133
134TypeId
136{
137 return GetTypeId();
138}
139
140void
141TcpOptionUnknown::Print(std::ostream& os) const
142{
143 os << "Unknown option";
144}
145
148{
149 return m_size;
150}
151
152void
154{
155 if (m_size == 0)
156 {
157 NS_LOG_WARN("Can't Serialize an Unknown Tcp Option");
158 return;
159 }
160
161 i.WriteU8(GetKind());
162 i.WriteU8(static_cast<uint8_t>(GetSerializedSize()));
163 i.Write(m_content, m_size - 2);
164}
165
168{
170
171 m_kind = i.ReadU8();
172 NS_LOG_WARN("Trying to Deserialize an Unknown Option of Kind " << int(m_kind));
173
174 m_size = i.ReadU8();
175 if (m_size < 2 || m_size > 40)
176 {
177 NS_LOG_WARN("Unable to parse an unknown option of kind "
178 << int(m_kind) << " with apparent size " << int(m_size));
179 return 0;
180 }
181
182 i.Read(m_content, m_size - 2);
183
184 return m_size;
185}
186
187uint8_t
189{
190 return m_kind;
191}
192
193} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void Write(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:951
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1128
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static TypeId GetTypeId()
Get the type ID.
Base class for all kinds of TCP options.
Definition: tcp-option.h:38
static Ptr< TcpOption > CreateOption(uint8_t kind)
Creates an option.
Definition: tcp-option.cc:62
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: tcp-option.cc:56
~TcpOption() override
Definition: tcp-option.cc:44
static bool IsKindKnown(uint8_t kind)
Check if the option is implemented.
Definition: tcp-option.cc:93
Kind
The option Kind, as defined in the respective RFCs.
Definition: tcp-option.h:55
@ UNKNOWN
not a standardized value; for unknown recv'd options
Definition: tcp-option.h:65
@ SACKPERMITTED
SACKPERMITTED.
Definition: tcp-option.h:62
@ WINSCALE
WINSCALE.
Definition: tcp-option.h:61
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-option.cc:49
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
An unknown TCP option.
Definition: tcp-option.h:124
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
Definition: tcp-option.cc:167
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
Definition: tcp-option.cc:153
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793) of this option.
Definition: tcp-option.cc:188
uint8_t m_content[40]
The option data.
Definition: tcp-option.h:146
void Print(std::ostream &os) const override
Print the Option contents.
Definition: tcp-option.cc:141
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-option.cc:125
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
Definition: tcp-option.cc:147
uint32_t m_size
The unknown option size.
Definition: tcp-option.h:145
~TcpOptionUnknown() override
Definition: tcp-option.cc:120
uint8_t m_kind
The unknown option kind.
Definition: tcp-option.h:144
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: tcp-option.cc:135
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1861