A Discrete-Event Network Simulator
API
tcp-option-winscale.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  * Documentation, test cases: Natale Patriciello <natale.patriciello@gmail.com>
20  */
21 
22 #include "tcp-option-winscale.h"
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpOptionWinScale");
28 
29 NS_OBJECT_ENSURE_REGISTERED (TcpOptionWinScale);
30 
32  : TcpOption (),
33  m_scale (0)
34 {
35 }
36 
38 {
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::TcpOptionWinScale")
45  .SetParent<TcpOption> ()
46  .SetGroupName ("Internet")
47  .AddConstructor<TcpOptionWinScale> ()
48  ;
49  return tid;
50 }
51 
52 TypeId
54 {
55  return GetTypeId ();
56 }
57 
58 void
59 TcpOptionWinScale::Print (std::ostream &os) const
60 {
61  os << static_cast<int> (m_scale);
62 }
63 
64 uint32_t
66 {
67  return 3;
68 }
69 
70 void
72 {
74  i.WriteU8 (GetKind ()); // Kind
75  i.WriteU8 (3); // Length
76  i.WriteU8 (m_scale); // Max segment size
77 }
78 
79 uint32_t
81 {
83 
84  uint8_t readKind = i.ReadU8 ();
85  if (readKind != GetKind ())
86  {
87  NS_LOG_WARN ("Malformed Window Scale option");
88  return 0;
89  }
90  uint8_t size = i.ReadU8 ();
91  if (size != 3)
92  {
93  NS_LOG_WARN ("Malformed Window Scale option");
94  return 0;
95  }
96  m_scale = i.ReadU8 ();
97  return GetSerializedSize ();
98 }
99 
100 uint8_t
102 {
103  return TcpOption::WINSCALE;
104 }
105 
106 uint8_t
108 {
109  NS_ASSERT (m_scale <= 14);
110 
111  return m_scale;
112 }
113 
114 void
116 {
117  NS_ASSERT (scale <= 14);
118 
119  m_scale = scale;
120 }
121 
122 } // namespace ns3
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
def start()
Definition: core.py:1855
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
#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:205
Defines the TCP option of kind 3 (window scale option) as in RFC 1323
virtual void Print(std::ostream &os) const
Print the Option contents.
iterator in a Buffer instance
Definition: buffer.h:98
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetScale(uint8_t scale)
Set the scale option.
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
void WriteU8(uint8_t data)
Definition: buffer.h:869
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
uint8_t ReadU8(void)
Definition: buffer.h:1021
Base class for all kinds of TCP options.
Definition: tcp-option.h:36
uint8_t m_scale
Window scaling in number of bit shift.
uint8_t GetScale(void) const
Get the scale value (uint8_t)
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923