A Discrete-Event Network Simulator
API
tcp-option-rfc793.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Adrian Sai-wah Tam
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19 */
20
21// TCP options that are specified in RFC 793 (kinds 0, 1, and 2)
22
23#include "tcp-option-rfc793.h"
24
25#include "ns3/log.h"
26
27namespace ns3 {
28
29NS_LOG_COMPONENT_DEFINE ("TcpOptionRfc793");
30
31NS_OBJECT_ENSURE_REGISTERED (TcpOptionEnd);
32
34{
35}
36
38{
39}
40
43{
44 static TypeId tid = TypeId ("ns3::TcpOptionEnd")
46 .SetGroupName ("Internet")
47 .AddConstructor<TcpOptionEnd> ()
48 ;
49 return tid;
50}
51
54{
55 return GetTypeId ();
56}
57
58void
59TcpOptionEnd::Print (std::ostream &os) const
60{
61 os << "EOL";
62}
63
66{
67 return 1;
68}
69
70void
72{
74 i.WriteU8 (GetKind ());
75}
76
79{
81
82 uint8_t readKind = i.ReadU8 ();
83
84 if (readKind != GetKind ())
85 {
86 NS_LOG_WARN ("Malformed END option");
87 return 0;
88 }
89
90 return GetSerializedSize ();
91}
92
93uint8_t
95{
96 return TcpOption::END;
97}
98
99
100// Tcp Option NOP
101
103
105 : TcpOption ()
106{
107}
108
110{
111}
112
113TypeId
115{
116 static TypeId tid = TypeId ("ns3::TcpOptionNOP")
118 .SetGroupName ("Internet")
119 .AddConstructor<TcpOptionNOP> ()
120 ;
121 return tid;
122}
123
124TypeId
126{
127 return GetTypeId ();
128}
129
130void
131TcpOptionNOP::Print (std::ostream &os) const
132{
133 os << "NOP";
134}
135
138{
139 return 1;
140}
141
142void
144{
146 i.WriteU8 (GetKind ());
147}
148
151{
153
154 uint8_t readKind = i.ReadU8 ();
155 if (readKind != GetKind ())
156 {
157 NS_LOG_WARN ("Malformed NOP option");
158 return 0;
159 }
160
161 return GetSerializedSize ();
162}
163
164uint8_t
166{
167 return TcpOption::NOP;
168}
169
170// Tcp Option MSS
171
173
175 : TcpOption (),
176 m_mss (1460)
177{
178}
179
181{
182}
183
184TypeId
186{
187 static TypeId tid = TypeId ("ns3::TcpOptionMSS")
189 .SetGroupName ("Internet")
190 .AddConstructor<TcpOptionMSS> ()
191 ;
192 return tid;
193}
194
195TypeId
197{
198 return GetTypeId ();
199}
200
201void
202TcpOptionMSS::Print (std::ostream &os) const
203{
204 os << "MSS:" << m_mss;
205}
206
209{
210 return 4;
211}
212
213void
215{
217 i.WriteU8 (GetKind ()); // Kind
218 i.WriteU8 (4); // Length
219 i.WriteHtonU16 (m_mss); // Max segment size
220}
221
224{
226
227 uint8_t readKind = i.ReadU8 ();
228 if (readKind != GetKind ())
229 {
230 NS_LOG_WARN ("Malformed MSS option");
231 return 0;
232 }
233
234 uint8_t size = i.ReadU8 ();
235
236 NS_ABORT_IF (size != 4);
237 m_mss = i.ReadNtohU16 ();
238
239 return GetSerializedSize ();
240}
241
242uint8_t
244{
245 return TcpOption::MSS;
246}
247
248uint16_t
250{
251 return m_mss;
252}
253
254void
256{
257 m_mss = mss;
258}
259
260} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
Defines the TCP option of kind 0 (end of option list) as in RFC 793
virtual void Print(std::ostream &os) const
Print the Option contents.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Base class for all kinds of TCP options.
Definition: tcp-option.h:37
Defines the TCP option of kind 2 (maximum segment size) as in RFC 793
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint16_t m_mss
maximum segment size
void SetMSS(uint16_t mss)
Set the Maximum Segment Size stored in the Option.
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
uint16_t GetMSS(void) const
Get the Maximum Segment Size stored in the Option.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
virtual void Print(std::ostream &os) const
Print the Option contents.
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
Defines the TCP option of kind 1 (no operation) as in RFC 793
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
static TypeId GetTypeId(void)
Get the type ID.
virtual void Print(std::ostream &os) const
Print the Option contents.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:266
#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:1852