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 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("TcpOptionRfc793");
30 
31 NS_OBJECT_ENSURE_REGISTERED (TcpOptionEnd);
32 
34 {
35 }
36 
38 {
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::TcpOptionEnd")
45  .SetParent<TcpOption> ()
46  .SetGroupName ("Internet")
47  .AddConstructor<TcpOptionEnd> ()
48  ;
49  return tid;
50 }
51 
52 TypeId
54 {
55  return GetTypeId ();
56 }
57 
58 void
59 TcpOptionEnd::Print (std::ostream &os) const
60 {
61  os << "EOL";
62 }
63 
64 uint32_t
66 {
67  return 1;
68 }
69 
70 void
72 {
74  i.WriteU8 (GetKind ());
75 }
76 
77 uint32_t
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 
93 uint8_t
95 {
96  return TcpOption::END;
97 }
98 
99 
100 // Tcp Option NOP
101 
103 
105  : TcpOption ()
106 {
107 }
108 
110 {
111 }
112 
113 TypeId
115 {
116  static TypeId tid = TypeId ("ns3::TcpOptionNOP")
117  .SetParent<TcpOption> ()
118  .SetGroupName ("Internet")
119  .AddConstructor<TcpOptionNOP> ()
120  ;
121  return tid;
122 }
123 
124 TypeId
126 {
127  return GetTypeId ();
128 }
129 
130 void
131 TcpOptionNOP::Print (std::ostream &os) const
132 {
133  os << "NOP";
134 }
135 
136 uint32_t
138 {
139  return 1;
140 }
141 
142 void
144 {
146  i.WriteU8 (GetKind ());
147 }
148 
149 uint32_t
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 
164 uint8_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 
184 TypeId
186 {
187  static TypeId tid = TypeId ("ns3::TcpOptionMSS")
188  .SetParent<TcpOption> ()
189  .SetGroupName ("Internet")
190  .AddConstructor<TcpOptionMSS> ()
191  ;
192  return tid;
193 }
194 
195 TypeId
197 {
198  return GetTypeId ();
199 }
200 
201 void
202 TcpOptionMSS::Print (std::ostream &os) const
203 {
204  os << "MSS:" << m_mss;
205 }
206 
207 uint32_t
209 {
210  return 4;
211 }
212 
213 void
215 {
217  i.WriteU8 (GetKind ()); // Kind
218  i.WriteU8 (4); // Length
219  i.WriteHtonU16 (m_mss); // Max segment size
220 }
221 
222 uint32_t
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_ASSERT (size == 4);
237  m_mss = i.ReadNtohU16 ();
238 
239  return GetSerializedSize ();
240 }
241 
242 uint8_t
244 {
245  return TcpOption::MSS;
246 }
247 
248 uint16_t
250 {
251  return m_mss;
252 }
253 
254 void
255 TcpOptionMSS::SetMSS (uint16_t mss)
256 {
257  m_mss = mss;
258 }
259 
260 } // namespace ns3
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
void SetMSS(uint16_t mss)
Set the Maximum Segment Size stored in the Option.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
Defines the TCP option of kind 1 (no operation) as in RFC 793
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
def start()
Definition: core.py:1482
virtual uint8_t GetKind(void) const
Get the `kind' (as in RFC 793) of this option.
virtual void Print(std::ostream &os) const
Print the Option contents.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
virtual uint8_t GetKind(void) const
Get the `kind' (as in RFC 793) of this option.
iterator in a Buffer instance
Definition: buffer.h:98
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 TypeId GetInstanceTypeId(void) const
Implement the GetInstanceTypeId method defined in ObjectBase.
void WriteHtonU16(uint16_t data)
Definition: buffer.h:904
Defines the TCP option of kind 0 (end of option list) as in RFC 793
uint16_t m_mss
maximum segment size
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
virtual TypeId GetInstanceTypeId(void) const
Implement the GetInstanceTypeId method defined in ObjectBase.
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.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
static TypeId GetTypeId(void)
Get the type ID.
void WriteU8(uint8_t data)
Definition: buffer.h:868
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
static TypeId GetTypeId(void)
Get the type ID.
Defines the TCP option of kind 2 (maximum segment size) as in RFC 793
uint8_t ReadU8(void)
Definition: buffer.h:1020
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
Base class for all kinds of TCP options.
Definition: tcp-option.h:36
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
virtual TypeId GetInstanceTypeId(void) const
Implement the GetInstanceTypeId method defined in ObjectBase.
uint16_t ReadNtohU16(void)
Definition: buffer.h:945
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
virtual void Print(std::ostream &os) const
Print the Option contents.