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 struct KindToTid
48 {
49 TcpOption::Kind kind;
50 TypeId tid;
51 };
52
53 static ObjectFactory objectFactory;
54 static KindToTid toTid[] = {
63 };
64
65 for (unsigned int i = 0; i < sizeof(toTid) / sizeof(KindToTid); ++i)
66 {
67 if (toTid[i].kind == kind)
68 {
69 objectFactory.SetTypeId(toTid[i].tid);
70 return objectFactory.Create<TcpOption>();
71 }
72 }
73
75}
76
77bool
79{
80 switch (kind)
81 {
82 case END:
83 case NOP:
84 case MSS:
85 case WINSCALE:
86 case SACKPERMITTED:
87 case SACK:
88 case TS:
89 // Do not add UNKNOWN here
90 return true;
91 }
92
93 return false;
94}
95
97
99 : TcpOption()
100{
101 m_kind = 0xFF;
102 m_size = 0;
103}
104
108
109TypeId
111{
112 static TypeId tid = TypeId("ns3::TcpOptionUnknown")
114 .SetGroupName("Internet")
115 .AddConstructor<TcpOptionUnknown>();
116 return tid;
117}
118
119void
120TcpOptionUnknown::Print(std::ostream& os) const
121{
122 os << "Unknown option";
123}
124
127{
128 return m_size;
129}
130
131void
133{
134 if (m_size == 0)
135 {
136 NS_LOG_WARN("Can't Serialize an Unknown Tcp Option");
137 return;
138 }
139
140 i.WriteU8(GetKind());
141 i.WriteU8(static_cast<uint8_t>(GetSerializedSize()));
142 i.Write(m_content, m_size - 2);
143}
144
147{
148 Buffer::Iterator i = start;
149
150 m_kind = i.ReadU8();
151 NS_LOG_WARN("Trying to Deserialize an Unknown Option of Kind " << int(m_kind));
152
153 m_size = i.ReadU8();
155 {
156 NS_LOG_WARN("Unable to parse an unknown option of kind "
157 << int(m_kind) << " with apparent size " << int(m_size));
158 return 0;
159 }
160
161 i.Read(m_content, m_size - 2);
162
163 return m_size;
164}
165
166uint8_t
168{
169 return m_kind;
170}
171
172} // 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:45
~TcpOption() override
Definition tcp-option.cc:33
static bool IsKindKnown(uint8_t kind)
Check if the option is implemented.
Definition tcp-option.cc:78
Kind
The option Kind, as defined in the respective RFCs.
Definition tcp-option.h:42
@ UNKNOWN
not a standardized value; for unknown recv'd options
Definition tcp-option.h:52
@ SACKPERMITTED
SACKPERMITTED.
Definition tcp-option.h:49
@ WINSCALE
WINSCALE.
Definition tcp-option.h:48
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:111
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:132
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:131
~TcpOptionUnknown() override
uint8_t m_kind
The unknown option kind.
Definition tcp-option.h:130
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition type-id.h:49
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.