A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
tcp-option-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com>
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
*/
7
8
#include "ns3/core-module.h"
9
#include "ns3/tcp-option-ts.h"
10
#include "ns3/tcp-option-winscale.h"
11
#include "ns3/tcp-option.h"
12
#include "ns3/test.h"
13
14
#include <
string.h
>
15
16
using namespace
ns3
;
17
18
/**
19
* @ingroup internet-test
20
*
21
* @brief TCP Window Scaling option Test
22
*/
23
class
TcpOptionWSTestCase
:
public
TestCase
24
{
25
public
:
26
/**
27
* @brief Constructor.
28
* @param name Test description.
29
* @param scale Window scaling.
30
*/
31
TcpOptionWSTestCase
(std::string name, uint8_t
scale
);
32
33
/**
34
* @brief Serialization test.
35
*/
36
void
TestSerialize
();
37
/**
38
* @brief Deserialization test.
39
*/
40
void
TestDeserialize
();
41
42
private
:
43
void
DoRun
()
override
;
44
void
DoTeardown
()
override
;
45
46
uint8_t
m_scale
;
//!< Window scaling.
47
Buffer
m_buffer
;
//!< Buffer.
48
};
49
50
TcpOptionWSTestCase::TcpOptionWSTestCase
(std::string name, uint8_t
scale
)
51
:
TestCase
(name)
52
{
53
m_scale
=
scale
;
54
}
55
56
void
57
TcpOptionWSTestCase::DoRun
()
58
{
59
TestSerialize
();
60
TestDeserialize
();
61
}
62
63
void
64
TcpOptionWSTestCase::TestSerialize
()
65
{
66
TcpOptionWinScale
opt
;
67
68
opt
.
SetScale
(
m_scale
);
69
NS_TEST_EXPECT_MSG_EQ
(
m_scale
,
opt
.GetScale(),
"Scale isn't saved correctly"
);
70
71
m_buffer
.
AddAtStart
(
opt
.GetSerializedSize());
72
73
opt
.Serialize(
m_buffer
.
Begin
());
74
}
75
76
void
77
TcpOptionWSTestCase::TestDeserialize
()
78
{
79
TcpOptionWinScale
opt
;
80
81
Buffer::Iterator
start =
m_buffer
.
Begin
();
82
uint8_t
kind
= start.PeekU8();
83
84
NS_TEST_EXPECT_MSG_EQ
(
kind
,
TcpOption::WINSCALE
,
"Different kind found"
);
85
86
opt
.Deserialize(start);
87
88
NS_TEST_EXPECT_MSG_EQ
(
m_scale
,
opt
.GetScale(),
"Different scale found"
);
89
}
90
91
void
92
TcpOptionWSTestCase::DoTeardown
()
93
{
94
}
95
96
/**
97
* @ingroup internet-test
98
*
99
* @brief TCP TimeStamp option Test
100
*/
101
class
TcpOptionTSTestCase
:
public
TestCase
102
{
103
public
:
104
/**
105
* @brief Constructor.
106
* @param name Test description.
107
*/
108
TcpOptionTSTestCase
(std::string name);
109
110
/**
111
* @brief Serialization test.
112
*/
113
void
TestSerialize
();
114
/**
115
* @brief Deserialization test.
116
*/
117
void
TestDeserialize
();
118
119
private
:
120
void
DoRun
()
override
;
121
void
DoTeardown
()
override
;
122
123
uint32_t
m_timestamp
;
//!< TimeStamp.
124
uint32_t
m_echo
;
//!< Echoed TimeStamp.
125
Buffer
m_buffer
;
//!< Buffer.
126
};
127
128
TcpOptionTSTestCase::TcpOptionTSTestCase
(std::string name)
129
:
TestCase
(name)
130
{
131
m_timestamp
= 0;
132
m_echo
= 0;
133
}
134
135
void
136
TcpOptionTSTestCase::DoRun
()
137
{
138
Ptr<UniformRandomVariable>
x =
CreateObject<UniformRandomVariable>
();
139
140
for
(
uint32_t
i
= 0;
i
< 1000; ++
i
)
141
{
142
m_timestamp
= x->GetInteger();
143
m_echo
= x->GetInteger();
144
TestSerialize
();
145
TestDeserialize
();
146
}
147
}
148
149
void
150
TcpOptionTSTestCase::TestSerialize
()
151
{
152
TcpOptionTS
opt
;
153
154
opt
.
SetTimestamp
(
m_timestamp
);
155
opt
.SetEcho(
m_echo
);
156
157
NS_TEST_EXPECT_MSG_EQ
(
m_timestamp
,
opt
.GetTimestamp(),
"TS isn't saved correctly"
);
158
NS_TEST_EXPECT_MSG_EQ
(
m_echo
,
opt
.GetEcho(),
"echo isn't saved correctly"
);
159
160
m_buffer
.
AddAtStart
(
opt
.GetSerializedSize());
161
162
opt
.Serialize(
m_buffer
.
Begin
());
163
}
164
165
void
166
TcpOptionTSTestCase::TestDeserialize
()
167
{
168
TcpOptionTS
opt
;
169
170
Buffer::Iterator
start =
m_buffer
.
Begin
();
171
uint8_t
kind
= start.PeekU8();
172
173
NS_TEST_EXPECT_MSG_EQ
(
kind
,
TcpOption::TS
,
"Different kind found"
);
174
175
opt
.Deserialize(start);
176
177
NS_TEST_EXPECT_MSG_EQ
(
m_timestamp
,
opt
.GetTimestamp(),
"Different TS found"
);
178
NS_TEST_EXPECT_MSG_EQ
(
m_echo
,
opt
.GetEcho(),
"Different echo found"
);
179
}
180
181
void
182
TcpOptionTSTestCase::DoTeardown
()
183
{
184
}
185
186
/**
187
* @ingroup internet-test
188
*
189
* @brief TCP options TestSuite
190
*/
191
class
TcpOptionTestSuite
:
public
TestSuite
192
{
193
public
:
194
TcpOptionTestSuite
()
195
:
TestSuite
(
"tcp-option"
,
Type
::
UNIT
)
196
{
197
for
(uint8_t
i
= 0;
i
< 15; ++
i
)
198
{
199
AddTestCase
(
new
TcpOptionWSTestCase
(
"Testing window scale value"
,
i
),
200
TestCase::Duration::QUICK);
201
}
202
AddTestCase
(
new
TcpOptionTSTestCase
(
"Testing serialization of random values for timestamp"
),
203
TestCase::Duration::QUICK);
204
}
205
};
206
207
static
TcpOptionTestSuite
g_TcpOptionTestSuite
;
//!< Static variable for test initialization
TcpOptionTSTestCase
TCP TimeStamp option Test.
Definition
tcp-option-test.cc:102
TcpOptionTSTestCase::TestSerialize
void TestSerialize()
Serialization test.
Definition
tcp-option-test.cc:150
TcpOptionTSTestCase::m_timestamp
uint32_t m_timestamp
TimeStamp.
Definition
tcp-option-test.cc:123
TcpOptionTSTestCase::m_echo
uint32_t m_echo
Echoed TimeStamp.
Definition
tcp-option-test.cc:124
TcpOptionTSTestCase::m_buffer
Buffer m_buffer
Buffer.
Definition
tcp-option-test.cc:125
TcpOptionTSTestCase::TestDeserialize
void TestDeserialize()
Deserialization test.
Definition
tcp-option-test.cc:166
TcpOptionTSTestCase::DoTeardown
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition
tcp-option-test.cc:182
TcpOptionTSTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-option-test.cc:136
TcpOptionTSTestCase::TcpOptionTSTestCase
TcpOptionTSTestCase(std::string name)
Constructor.
Definition
tcp-option-test.cc:128
TcpOptionTestSuite
TCP options TestSuite.
Definition
tcp-option-test.cc:192
TcpOptionTestSuite::TcpOptionTestSuite
TcpOptionTestSuite()
Definition
tcp-option-test.cc:194
TcpOptionWSTestCase
TCP Window Scaling option Test.
Definition
tcp-option-test.cc:24
TcpOptionWSTestCase::TestSerialize
void TestSerialize()
Serialization test.
Definition
tcp-option-test.cc:64
TcpOptionWSTestCase::TestDeserialize
void TestDeserialize()
Deserialization test.
Definition
tcp-option-test.cc:77
TcpOptionWSTestCase::m_scale
uint8_t m_scale
Window scaling.
Definition
tcp-option-test.cc:46
TcpOptionWSTestCase::DoTeardown
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition
tcp-option-test.cc:92
TcpOptionWSTestCase::m_buffer
Buffer m_buffer
Buffer.
Definition
tcp-option-test.cc:47
TcpOptionWSTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-option-test.cc:57
TcpOptionWSTestCase::TcpOptionWSTestCase
TcpOptionWSTestCase(std::string name, uint8_t scale)
Constructor.
Definition
tcp-option-test.cc:50
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer
automatically resized byte buffer
Definition
buffer.h:83
ns3::Buffer::AddAtStart
void AddAtStart(uint32_t start)
Definition
buffer.cc:303
ns3::Buffer::Begin
Buffer::Iterator Begin() const
Definition
buffer.h:1063
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::TcpOption::TS
@ TS
TS.
Definition
tcp-option.h:53
ns3::TcpOption::WINSCALE
@ WINSCALE
WINSCALE.
Definition
tcp-option.h:50
ns3::TcpOptionTS
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323
Definition
tcp-option-ts.h:26
ns3::TcpOptionTS::SetTimestamp
void SetTimestamp(uint32_t ts)
Set the timestamp stored in the Option.
Definition
tcp-option-ts.cc:111
ns3::TcpOptionWinScale
Defines the TCP option of kind 3 (window scale option) as in RFC 1323
Definition
tcp-option-winscale.h:40
ns3::TcpOptionWinScale::SetScale
void SetScale(uint8_t scale)
Set the scale option.
Definition
tcp-option-winscale.cc:104
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition
test.h:241
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
string.h
ns3::StringValue attribute value declarations.
g_TcpOptionTestSuite
static TcpOptionTestSuite g_TcpOptionTestSuite
Static variable for test initialization.
Definition
tcp-option-test.cc:207
src
internet
test
tcp-option-test.cc
Generated on Mon Dec 15 2025 15:21:55 for ns-3 by
1.9.8