A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-option-rfc793.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// TCP options that are specified in RFC 793 (kinds 0, 1, and 2)
10
11#include "tcp-option-rfc793.h"
12
13#include "ns3/log.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("TcpOptionRfc793");
19
20NS_OBJECT_ENSURE_REGISTERED(TcpOptionEnd);
21
26
30
33{
34 static TypeId tid = TypeId("ns3::TcpOptionEnd")
36 .SetGroupName("Internet")
37 .AddConstructor<TcpOptionEnd>();
38 return tid;
39}
40
43{
44 return GetTypeId();
45}
46
47void
48TcpOptionEnd::Print(std::ostream& os) const
49{
50 os << "EOL";
51}
52
55{
56 return 1;
57}
58
59void
61{
62 Buffer::Iterator i = start;
63 i.WriteU8(GetKind());
64}
65
68{
69 Buffer::Iterator i = start;
70
71 uint8_t readKind = i.ReadU8();
72
73 if (readKind != GetKind())
74 {
75 NS_LOG_WARN("Malformed END option");
76 return 0;
77 }
78
79 return GetSerializedSize();
80}
81
82uint8_t
84{
85 return TcpOption::END;
86}
87
88// Tcp Option NOP
89
91
96
100
101TypeId
103{
104 static TypeId tid = TypeId("ns3::TcpOptionNOP")
106 .SetGroupName("Internet")
107 .AddConstructor<TcpOptionNOP>();
108 return tid;
109}
110
111TypeId
113{
114 return GetTypeId();
115}
116
117void
118TcpOptionNOP::Print(std::ostream& os) const
119{
120 os << "NOP";
121}
122
125{
126 return 1;
127}
128
129void
131{
132 Buffer::Iterator i = start;
133 i.WriteU8(GetKind());
134}
135
138{
139 Buffer::Iterator i = start;
140
141 uint8_t readKind = i.ReadU8();
142 if (readKind != GetKind())
143 {
144 NS_LOG_WARN("Malformed NOP option");
145 return 0;
146 }
147
148 return GetSerializedSize();
149}
150
151uint8_t
153{
154 return TcpOption::NOP;
155}
156
157// Tcp Option MSS
158
160
162 : TcpOption(),
163 m_mss(1460)
164{
165}
166
170
171TypeId
173{
174 static TypeId tid = TypeId("ns3::TcpOptionMSS")
176 .SetGroupName("Internet")
177 .AddConstructor<TcpOptionMSS>();
178 return tid;
179}
180
181TypeId
183{
184 return GetTypeId();
185}
186
187void
188TcpOptionMSS::Print(std::ostream& os) const
189{
190 os << "MSS:" << m_mss;
191}
192
195{
196 return 4;
197}
198
199void
201{
202 Buffer::Iterator i = start;
203 i.WriteU8(GetKind()); // Kind
204 i.WriteU8(4); // Length
205 i.WriteHtonU16(m_mss); // Max segment size
206}
207
210{
211 Buffer::Iterator i = start;
212
213 uint8_t readKind = i.ReadU8();
214 if (readKind != GetKind())
215 {
216 NS_LOG_WARN("Malformed MSS option");
217 return 0;
218 }
219
220 uint8_t size = i.ReadU8();
221
222 NS_ABORT_IF(size != 4);
223 m_mss = i.ReadNtohU16();
224
225 return GetSerializedSize();
226}
227
228uint8_t
230{
231 return TcpOption::MSS;
232}
233
234uint16_t
236{
237 return m_mss;
238}
239
240void
242{
243 m_mss = mss;
244}
245
246} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtonU16(uint16_t data)
Definition buffer.h:904
uint16_t ReadNtohU16()
Definition buffer.h:943
Defines the TCP option of kind 0 (end of option list) as in RFC 793
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
static TypeId GetTypeId()
Get the type ID.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
void Print(std::ostream &os) const override
Print the Option contents.
Base class for all kinds of TCP options.
Definition tcp-option.h:27
Defines the TCP option of kind 2 (maximum segment size) as in RFC 793
uint16_t GetMSS() const
Get the Maximum Segment Size stored in the Option.
uint16_t m_mss
maximum segment size
void SetMSS(uint16_t mss)
Set the Maximum Segment Size stored in the Option.
static TypeId GetTypeId()
Get the type ID.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
void Print(std::ostream &os) const override
Print the Option contents.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
Defines the TCP option of kind 1 (no operation) as in RFC 793
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.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
void Print(std::ostream &os) const override
Print the Option contents.
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_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
#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
#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.