A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-option.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Adrian Sai-wah Tam
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
7 */
8
9#include "tcp-option.h"
10
11#include "tcp-option-rfc793.h"
13#include "tcp-option-sack.h"
14#include "tcp-option-ts.h"
15#include "tcp-option-winscale.h"
16
17#include "ns3/log.h"
18#include "ns3/type-id.h"
19
20#include <vector>
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("TcpOption");
26
28
32
36
39{
40 static TypeId tid = TypeId("ns3::TcpOption").SetParent<Object>().SetGroupName("Internet");
41 return tid;
42}
43
46{
47 return GetTypeId();
48}
49
52{
53 struct KindToTid
54 {
55 TcpOption::Kind kind;
56 TypeId tid;
57 };
58
59 static ObjectFactory objectFactory;
60 static KindToTid toTid[] = {
69 };
70
71 for (unsigned int i = 0; i < sizeof(toTid) / sizeof(KindToTid); ++i)
72 {
73 if (toTid[i].kind == kind)
74 {
75 objectFactory.SetTypeId(toTid[i].tid);
76 return objectFactory.Create<TcpOption>();
77 }
78 }
79
81}
82
83bool
85{
86 switch (kind)
87 {
88 case END:
89 case NOP:
90 case MSS:
91 case WINSCALE:
92 case SACKPERMITTED:
93 case SACK:
94 case TS:
95 // Do not add UNKNOWN here
96 return true;
97 }
98
99 return false;
100}
101
103
105 : TcpOption()
106{
107 m_kind = 0xFF;
108 m_size = 0;
109}
110
114
115TypeId
117{
118 static TypeId tid = TypeId("ns3::TcpOptionUnknown")
120 .SetGroupName("Internet")
121 .AddConstructor<TcpOptionUnknown>();
122 return tid;
123}
124
125TypeId
127{
128 return GetTypeId();
129}
130
131void
132TcpOptionUnknown::Print(std::ostream& os) const
133{
134 os << "Unknown option";
135}
136
139{
140 return m_size;
141}
142
143void
145{
146 if (m_size == 0)
147 {
148 NS_LOG_WARN("Can't Serialize an Unknown Tcp Option");
149 return;
150 }
151
152 i.WriteU8(GetKind());
153 i.WriteU8(static_cast<uint8_t>(GetSerializedSize()));
154 i.Write(m_content, m_size - 2);
155}
156
159{
160 Buffer::Iterator i = start;
161
162 m_kind = i.ReadU8();
163 NS_LOG_WARN("Trying to Deserialize an Unknown Option of Kind " << int(m_kind));
164
165 m_size = i.ReadU8();
167 {
168 NS_LOG_WARN("Unable to parse an unknown option of kind "
169 << int(m_kind) << " with apparent size " << int(m_size));
170 return 0;
171 }
172
173 i.Read(m_content, m_size - 2);
174
175 return m_size;
176}
177
178uint8_t
180{
181 return m_kind;
182}
183
184} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:937
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1114
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:78
Smart pointer class similar to boost::intrusive_ptr.
static TypeId GetTypeId()
Get the type ID.
Base class for all kinds of TCP options.
Definition tcp-option.h:27
static Ptr< TcpOption > CreateOption(uint8_t kind)
Creates an option.
Definition tcp-option.cc:51
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition tcp-option.cc:45
~TcpOption() override
Definition tcp-option.cc:33
static bool IsKindKnown(uint8_t kind)
Check if the option is implemented.
Definition tcp-option.cc:84
Kind
The option Kind, as defined in the respective RFCs.
Definition tcp-option.h:44
@ UNKNOWN
not a standardized value; for unknown recv'd options
Definition tcp-option.h:54
@ SACKPERMITTED
SACKPERMITTED.
Definition tcp-option.h:51
@ WINSCALE
WINSCALE.
Definition tcp-option.h:50
static TypeId GetTypeId()
Get the type ID.
Definition tcp-option.cc:38
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:113
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
uint8_t m_content[40]
The option data.
Definition tcp-option.h:135
void Print(std::ostream &os) const override
Print the Option contents.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
uint32_t m_size
The unknown option size.
Definition tcp-option.h:134
~TcpOptionUnknown() override
uint8_t m_kind
The unknown option kind.
Definition tcp-option.h:133
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.