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
41void
42TcpOptionEnd::Print(std::ostream& os) const
43{
44 os << "EOL";
45}
46
49{
50 return 1;
51}
52
53void
55{
56 Buffer::Iterator i = start;
57 i.WriteU8(GetKind());
58}
59
62{
63 Buffer::Iterator i = start;
64
65 uint8_t readKind = i.ReadU8();
66
67 if (readKind != GetKind())
68 {
69 NS_LOG_WARN("Malformed END option");
70 return 0;
71 }
72
73 return GetSerializedSize();
74}
75
76uint8_t
78{
79 return TcpOption::END;
80}
81
82// Tcp Option NOP
83
85
90
94
97{
98 static TypeId tid = TypeId("ns3::TcpOptionNOP")
100 .SetGroupName("Internet")
101 .AddConstructor<TcpOptionNOP>();
102 return tid;
103}
104
105void
106TcpOptionNOP::Print(std::ostream& os) const
107{
108 os << "NOP";
109}
110
113{
114 return 1;
115}
116
117void
119{
120 Buffer::Iterator i = start;
121 i.WriteU8(GetKind());
122}
123
126{
127 Buffer::Iterator i = start;
128
129 uint8_t readKind = i.ReadU8();
130 if (readKind != GetKind())
131 {
132 NS_LOG_WARN("Malformed NOP option");
133 return 0;
134 }
135
136 return GetSerializedSize();
137}
138
139uint8_t
141{
142 return TcpOption::NOP;
143}
144
145// Tcp Option MSS
146
148
150 : TcpOption(),
151 m_mss(1460)
152{
153}
154
158
159TypeId
161{
162 static TypeId tid = TypeId("ns3::TcpOptionMSS")
164 .SetGroupName("Internet")
165 .AddConstructor<TcpOptionMSS>();
166 return tid;
167}
168
169void
170TcpOptionMSS::Print(std::ostream& os) const
171{
172 os << "MSS:" << m_mss;
173}
174
177{
178 return 4;
179}
180
181void
183{
184 Buffer::Iterator i = start;
185 i.WriteU8(GetKind()); // Kind
186 i.WriteU8(4); // Length
187 i.WriteHtonU16(m_mss); // Max segment size
188}
189
192{
193 Buffer::Iterator i = start;
194
195 uint8_t readKind = i.ReadU8();
196 if (readKind != GetKind())
197 {
198 NS_LOG_WARN("Malformed MSS option");
199 return 0;
200 }
201
202 uint8_t size = i.ReadU8();
203
204 NS_ABORT_IF(size != 4);
205 m_mss = i.ReadNtohU16();
206
207 return GetSerializedSize();
208}
209
210uint8_t
212{
213 return TcpOption::MSS;
214}
215
216uint16_t
218{
219 return m_mss;
220}
221
222void
224{
225 m_mss = mss;
226}
227
228} // 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.
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.
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.
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_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.