A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-wscaling-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include "tcp-general-test.h"
20
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/tcp-header.h"
24#include "ns3/tcp-rx-buffer.h"
25#include "ns3/tcp-tx-buffer.h"
26#include "ns3/test.h"
27
28using namespace ns3;
29
30NS_LOG_COMPONENT_DEFINE("WScalingTestSuite");
31
32// TODO: Check the buffer size and scaling option value
33/**
34 * \ingroup internet-test
35 *
36 * \brief TCP Window Scaling enabling Test.
37 */
39{
40 public:
41 /**
42 * Window Scaling configuration.
43 */
45 {
50 };
51
52 /**
53 * \brief Constructor.
54 * \param conf Test configuration.
55 * \param maxRcvBufferSize Maximum receiver buffer size.
56 * \param maxSndBufferSize Maximum sender buffer size.
57 * \param name Test description.
58 */
60 uint32_t maxRcvBufferSize,
61 uint32_t maxSndBufferSize,
62 std::string name);
63
64 protected:
67
68 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
69
70 Configuration m_configuration; //!< Test configuration.
71 uint32_t m_maxRcvBufferSize; //!< Maximum receiver buffer size.
72 uint32_t m_maxSndBufferSize; //!< Maximum sender buffer size.
73};
74
76 uint32_t maxRcvBufferSize,
77 uint32_t maxSndBufferSize,
78 std::string name)
79 : TcpGeneralTest(name)
80{
82 m_maxRcvBufferSize = maxRcvBufferSize;
83 m_maxSndBufferSize = maxSndBufferSize;
84}
85
88{
90
91 switch (m_configuration)
92 {
93 case DISABLED:
94 socket->SetAttribute("WindowScaling", BooleanValue(false));
95 break;
96
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
115{
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
140void
142{
143 NS_LOG_INFO(h);
144
145 if (!(h.GetFlags() & TcpHeader::SYN))
146 {
148 false,
149 "wscale present in non-SYN packets");
150 }
151 else
152 {
154 {
156 false,
157 "wscale disabled but option enabled");
158 }
159 else if (m_configuration == ENABLED)
160 {
162 true,
163 "wscale enabled but option disabled");
164
165 if (who == RECEIVER)
166 {
167 uint16_t advWin = h.GetWindowSize();
168 uint32_t maxSize = GetRxBuffer(RECEIVER)->MaxBufferSize();
169
170 if (maxSize > 65535)
171 {
172 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
173 }
174 else
175 {
176 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
177 }
178 }
179 }
180
181 if (who == SENDER)
182 {
184 {
186 false,
187 "wscale disabled but option enabled");
188 }
190 {
192 true,
193 "wscale enabled but option disabled");
194
195 uint16_t advWin = h.GetWindowSize();
196 uint32_t maxSize = GetRxBuffer(SENDER)->MaxBufferSize();
197
198 if (maxSize > 65535)
199 {
200 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
201 }
202 else
203 {
204 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
205 }
206 }
207 }
208 else if (who == RECEIVER)
209 {
211 {
213 false,
214 "sender has not ws, but receiver sent anyway");
215 }
217 {
219 false,
220 "receiver has not ws enabled but sent anyway");
221 }
222 }
223 }
224}
225
226/**
227 * \ingroup internet-test
228 *
229 * \brief TCP Window Scaling TestSuite.
230 */
232{
233 public:
235 : TestSuite("tcp-wscaling", Type::UNIT)
236 {
238 new WScalingTestCase(WScalingTestCase::ENABLED, 200000, 65535, "WS only server"),
239 TestCase::Duration::QUICK);
241 65535,
242 65535,
243 "Window scaling not used, all enabled"),
244 TestCase::Duration::QUICK);
245 AddTestCase(new WScalingTestCase(WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"),
246 TestCase::Duration::QUICK);
248 65535,
249 65535,
250 "WS enabled client"),
251 TestCase::Duration::QUICK);
253 65535,
254 65535,
255 "WS disabled client"),
256 TestCase::Duration::QUICK);
257
259 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 200000, "WS only client"),
260 TestCase::Duration::QUICK);
262 new WScalingTestCase(WScalingTestCase::ENABLED, 131072, 65535, "WS only server"),
263 TestCase::Duration::QUICK);
265 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 131072, "WS only client"),
266 TestCase::Duration::QUICK);
268 new WScalingTestCase(WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"),
269 TestCase::Duration::QUICK);
271 4000,
272 4000,
273 "WS small window, sender"),
274 TestCase::Duration::QUICK);
275 }
276};
277
278static TcpWScalingTestSuite g_tcpWScalingTestSuite; //!< Static variable for test initialization
TCP Window Scaling TestSuite.
TCP Window Scaling enabling Test.
WScalingTestCase(WScalingTestCase::Configuration conf, uint32_t maxRcvBufferSize, uint32_t maxSndBufferSize, std::string name)
Constructor.
Configuration
Window Scaling configuration.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
Configuration m_configuration
Test configuration.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
uint32_t m_maxRcvBufferSize
Maximum receiver buffer size.
uint32_t m_maxSndBufferSize
Maximum sender buffer size.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
General infrastructure for TCP testing.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:154
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:478
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:148
@ WINSCALE
WINSCALE.
Definition: tcp-option.h:61
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:145
Definition: conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpWScalingTestSuite g_tcpWScalingTestSuite
Static variable for test initialization.