A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
tcp-wscaling-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013 Natale Patriciello <natale.patriciello@gmail.com>
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
*/
19
20
#include "ns3/test.h"
21
#include "
tcp-general-test.h
"
22
#include "ns3/node.h"
23
#include "ns3/log.h"
24
#include "ns3/tcp-header.h"
25
#include "ns3/tcp-tx-buffer.h"
26
#include "ns3/tcp-rx-buffer.h"
27
28
using namespace
ns3
;
29
30
31
NS_LOG_COMPONENT_DEFINE
(
"WScalingTestSuite"
);
32
33
// TODO: Check the buffer size and scaling option value
40
class
WScalingTestCase
:
public
TcpGeneralTest
41
{
42
public
:
46
enum
Configuration
47
{
48
DISABLED
,
49
ENABLED_SENDER
,
50
ENABLED_RECEIVER
,
51
ENABLED
52
};
53
61
WScalingTestCase
(
WScalingTestCase::Configuration
conf
,
62
uint32_t maxRcvBufferSize,
63
uint32_t maxSndBufferSize, std::string name);
64
65
protected
:
66
virtual
Ptr<TcpSocketMsgBase>
CreateReceiverSocket (
Ptr<Node>
node);
67
virtual
Ptr<TcpSocketMsgBase>
CreateSenderSocket (
Ptr<Node>
node);
68
69
virtual
void
Tx (
const
Ptr<const Packet>
p,
const
TcpHeader
&h, SocketWho who);
70
71
Configuration
m_configuration
;
72
uint32_t
m_maxRcvBufferSize
;
73
uint32_t
m_maxSndBufferSize
;
74
};
75
76
WScalingTestCase::WScalingTestCase
(
WScalingTestCase::Configuration
conf
,
77
uint32_t maxRcvBufferSize,
78
uint32_t maxSndBufferSize, std::string name)
79
:
TcpGeneralTest
(name)
80
{
81
m_configuration
=
conf
;
82
m_maxRcvBufferSize
= maxRcvBufferSize;
83
m_maxSndBufferSize
= maxSndBufferSize;
84
}
85
86
Ptr<TcpSocketMsgBase>
87
WScalingTestCase::CreateReceiverSocket
(
Ptr<Node>
node)
88
{
89
Ptr<TcpSocketMsgBase>
socket = TcpGeneralTest::CreateReceiverSocket (node);
90
91
switch
(
m_configuration
)
92
{
93
case
DISABLED
:
94
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
false
));
95
break
;
96
97
case
ENABLED_RECEIVER
:
98
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
true
));
99
break
;
100
101
case
ENABLED_SENDER
:
102
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
false
));
103
break
;
104
105
case
ENABLED
:
106
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
true
));
107
break
;
108
}
109
110
return
socket;
111
}
112
113
Ptr<TcpSocketMsgBase>
114
WScalingTestCase::CreateSenderSocket
(
Ptr<Node>
node)
115
{
116
Ptr<TcpSocketMsgBase>
socket = TcpGeneralTest::CreateSenderSocket (node);
117
118
switch
(
m_configuration
)
119
{
120
case
DISABLED
:
121
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
false
));
122
break
;
123
124
case
ENABLED_RECEIVER
:
125
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
false
));
126
break
;
127
128
case
ENABLED_SENDER
:
129
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
true
));
130
break
;
131
132
case
ENABLED
:
133
socket->
SetAttribute
(
"WindowScaling"
,
BooleanValue
(
true
));
134
break
;
135
}
136
137
return
socket;
138
}
139
140
void
141
WScalingTestCase::Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
&h,
SocketWho
who)
142
{
143
NS_LOG_INFO
(h);
144
145
if
(! (h.
GetFlags
() & TcpHeader::SYN))
146
{
147
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
false
,
148
"wscale present in non-SYN packets"
);
149
}
150
else
151
{
152
if
(
m_configuration
==
DISABLED
)
153
{
154
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
false
,
155
"wscale disabled but option enabled"
);
156
}
157
else
if
(
m_configuration
==
ENABLED
)
158
{
159
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
true
,
160
"wscale enabled but option disabled"
);
161
162
if
(who ==
RECEIVER
)
163
{
164
uint16_t advWin = h.
GetWindowSize
();
165
uint32_t maxSize =
GetRxBuffer
(
RECEIVER
)->MaxBufferSize ();
166
167
if
(maxSize > 65535)
168
{
169
NS_TEST_ASSERT_MSG_EQ
(advWin, 65535,
"Scaling SYN segment"
);
170
}
171
else
172
{
173
NS_TEST_ASSERT_MSG_EQ
(advWin, maxSize,
"Not advertising all window"
);
174
}
175
}
176
}
177
178
if
(who ==
SENDER
)
179
{
180
if
(
m_configuration
==
ENABLED_RECEIVER
)
181
{
182
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
false
,
183
"wscale disabled but option enabled"
);
184
}
185
else
if
(
m_configuration
==
ENABLED_SENDER
)
186
{
187
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
true
,
188
"wscale enabled but option disabled"
);
189
190
uint16_t advWin = h.
GetWindowSize
();
191
uint32_t maxSize =
GetRxBuffer
(
SENDER
)->MaxBufferSize ();
192
193
if
(maxSize > 65535)
194
{
195
NS_TEST_ASSERT_MSG_EQ
(advWin, 65535,
"Scaling SYN segment"
);
196
}
197
else
198
{
199
NS_TEST_ASSERT_MSG_EQ
(advWin, maxSize,
"Not advertising all window"
);
200
}
201
}
202
}
203
else
if
(who ==
RECEIVER
)
204
{
205
if
(
m_configuration
==
ENABLED_RECEIVER
)
206
{
207
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
false
,
208
"sender has not ws, but receiver sent anyway"
);
209
}
210
else
if
(
m_configuration
==
ENABLED_SENDER
)
211
{
212
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(TcpOption::WINSCALE),
false
,
213
"receiver has not ws enabled but sent anyway"
);
214
}
215
}
216
}
217
}
218
225
class
TcpWScalingTestSuite
:
public
TestSuite
226
{
227
public
:
228
TcpWScalingTestSuite
()
229
:
TestSuite
(
"tcp-wscaling"
,
UNIT
)
230
{
231
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 200000, 65535,
"WS only server"
), TestCase::QUICK);
232
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 65535,
"Window scaling not used, all enabled"
), TestCase::QUICK);
233
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::DISABLED
, 65535, 65535,
"WS disabled"
), TestCase::QUICK);
234
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED_SENDER
, 65535, 65535,
"WS enabled client"
), TestCase::QUICK);
235
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED_RECEIVER
, 65535, 65535,
"WS disabled client"
), TestCase::QUICK);
236
237
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 200000,
"WS only client"
), TestCase::QUICK);
238
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 131072, 65535,
"WS only server"
), TestCase::QUICK);
239
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 131072,
"WS only client"
), TestCase::QUICK);
240
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 4000, 4000,
"WS small window, all"
), TestCase::QUICK);
241
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED_SENDER
, 4000, 4000,
"WS small window, sender"
), TestCase::QUICK);
242
}
243
244
};
245
246
static
TcpWScalingTestSuite
g_tcpWScalingTestSuite
;
247
WScalingTestCase::m_configuration
Configuration m_configuration
Test configuration.
Definition:
tcp-wscaling-test.cc:71
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
TcpWScalingTestSuite::TcpWScalingTestSuite
TcpWScalingTestSuite()
Definition:
tcp-wscaling-test.cc:228
ns3::TcpHeader::GetWindowSize
uint16_t GetWindowSize() const
Get the window size.
Definition:
tcp-header.cc:179
WScalingTestCase::CreateReceiverSocket
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Definition:
tcp-wscaling-test.cc:87
ns3::TcpGeneralTest::SocketWho
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Definition:
tcp-general-test.h:275
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
WScalingTestCase::ENABLED
@ ENABLED
Definition:
tcp-wscaling-test.cc:51
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition:
boolean.h:37
WScalingTestCase::ENABLED_SENDER
@ ENABLED_SENDER
Definition:
tcp-wscaling-test.cc:49
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpGeneralTest::SENDER
@ SENDER
Sender node.
Definition:
tcp-general-test.h:276
WScalingTestCase::WScalingTestCase
WScalingTestCase(WScalingTestCase::Configuration conf, uint32_t maxRcvBufferSize, uint32_t maxSndBufferSize, std::string name)
Constructor.
Definition:
tcp-wscaling-test.cc:76
WScalingTestCase::DISABLED
@ DISABLED
Definition:
tcp-wscaling-test.cc:48
WScalingTestCase
TCP Window Scaling enabling Test.
Definition:
tcp-wscaling-test.cc:41
WScalingTestCase::CreateSenderSocket
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Definition:
tcp-wscaling-test.cc:114
ns3::ObjectBase::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition:
object-base.cc:185
g_tcpWScalingTestSuite
static TcpWScalingTestSuite g_tcpWScalingTestSuite
Static variable for test initialization.
Definition:
tcp-wscaling-test.cc:246
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:281
WScalingTestCase::m_maxRcvBufferSize
uint32_t m_maxRcvBufferSize
Maximum receiver buffer size.
Definition:
tcp-wscaling-test.cc:72
ns3::TcpGeneralTest::RECEIVER
@ RECEIVER
Receiver node.
Definition:
tcp-general-test.h:277
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:45
WScalingTestCase::Tx
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
Definition:
tcp-wscaling-test.cc:141
ns3::TcpGeneralTest::GetRxBuffer
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
Definition:
tcp-general-test.cc:869
WScalingTestCase::m_maxSndBufferSize
uint32_t m_maxSndBufferSize
Maximum sender buffer size.
Definition:
tcp-wscaling-test.cc:73
tcp-general-test.h
ns3::TcpGeneralTest
General infrastructure for TCP testing.
Definition:
tcp-general-test.h:257
WScalingTestCase::ENABLED_RECEIVER
@ ENABLED_RECEIVER
Definition:
tcp-wscaling-test.cc:50
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition:
tcp-header.cc:511
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition:
test.h:166
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1353
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition:
tcp-header.cc:173
WScalingTestCase::Configuration
Configuration
Window Scaling configuration.
Definition:
tcp-wscaling-test.cc:47
TcpWScalingTestSuite
TCP Window Scaling TestSuite.
Definition:
tcp-wscaling-test.cc:226
conf
Definition:
conf.py:1
src
internet
test
tcp-wscaling-test.cc
Generated on Fri Oct 1 2021 17:03:13 for ns-3 by
1.8.20