A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-option-winscale.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 * Documentation, test cases: Natale Patriciello <natale.patriciello@gmail.com>
8 */
9
10#include "tcp-option-winscale.h"
11
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("TcpOptionWinScale");
18
19NS_OBJECT_ENSURE_REGISTERED(TcpOptionWinScale);
20
22 : TcpOption(),
23 m_scale(0)
24{
25}
26
30
33{
34 static TypeId tid = TypeId("ns3::TcpOptionWinScale")
36 .SetGroupName("Internet")
37 .AddConstructor<TcpOptionWinScale>();
38 return tid;
39}
40
46
47void
48TcpOptionWinScale::Print(std::ostream& os) const
49{
50 os << static_cast<int>(m_scale);
51}
52
55{
56 return 3;
57}
58
59void
61{
62 Buffer::Iterator i = start;
63 i.WriteU8(GetKind()); // Kind
64 i.WriteU8(3); // Length
65 i.WriteU8(m_scale); // Max segment size
66}
67
70{
71 Buffer::Iterator i = start;
72
73 uint8_t readKind = i.ReadU8();
74 if (readKind != GetKind())
75 {
76 NS_LOG_WARN("Malformed Window Scale option");
77 return 0;
78 }
79 uint8_t size = i.ReadU8();
80 if (size != 3)
81 {
82 NS_LOG_WARN("Malformed Window Scale option");
83 return 0;
84 }
85 m_scale = i.ReadU8();
86 return GetSerializedSize();
87}
88
89uint8_t
94
95uint8_t
97{
98 NS_ASSERT(m_scale <= 14);
99
100 return m_scale;
101}
102
103void
105{
106 NS_ASSERT(scale <= 14);
107
108 m_scale = scale;
109}
110
111} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
Base class for all kinds of TCP options.
Definition tcp-option.h:27
@ WINSCALE
WINSCALE.
Definition tcp-option.h:50
Defines the TCP option of kind 3 (window scale option) as in RFC 1323
uint8_t GetScale() const
Get the scale value (uint8_t)
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.
void Print(std::ostream &os) const override
Print the Option contents.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
void SetScale(uint8_t scale)
Set the scale option.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t m_scale
Window scaling in number of bit shift.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
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_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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.