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 case ENABLED_RECEIVER:
122 socket->SetAttribute("WindowScaling", BooleanValue(false));
123 break;
124
125 case ENABLED_SENDER:
126 case ENABLED:
127 socket->SetAttribute("WindowScaling", BooleanValue(true));
128 break;
129 }
130
131 return socket;
132}
133
134void
136{
137 NS_LOG_INFO(h);
138
139 if (!(h.GetFlags() & TcpHeader::SYN))
140 {
142 false,
143 "wscale present in non-SYN packets");
144 }
145 else
146 {
148 {
150 false,
151 "wscale disabled but option enabled");
152 }
153 else if (m_configuration == ENABLED)
154 {
156 true,
157 "wscale enabled but option disabled");
158
159 if (who == RECEIVER)
160 {
161 uint16_t advWin = h.GetWindowSize();
162 uint32_t maxSize = GetRxBuffer(RECEIVER)->MaxBufferSize();
163
164 if (maxSize > 65535)
165 {
166 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
167 }
168 else
169 {
170 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
171 }
172 }
173 }
174
175 if (who == SENDER)
176 {
178 {
180 false,
181 "wscale disabled but option enabled");
182 }
184 {
186 true,
187 "wscale enabled but option disabled");
188
189 uint16_t advWin = h.GetWindowSize();
190 uint32_t maxSize = GetRxBuffer(SENDER)->MaxBufferSize();
191
192 if (maxSize > 65535)
193 {
194 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
195 }
196 else
197 {
198 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
199 }
200 }
201 }
202 else if (who == RECEIVER)
203 {
205 {
207 false,
208 "sender has not ws, but receiver sent anyway");
209 }
211 {
213 false,
214 "receiver has not ws enabled but sent anyway");
215 }
216 }
217 }
218}
219
220/**
221 * \ingroup internet-test
222 *
223 * \brief TCP Window Scaling TestSuite.
224 */
226{
227 public:
229 : TestSuite("tcp-wscaling", Type::UNIT)
230 {
232 new WScalingTestCase(WScalingTestCase::ENABLED, 200000, 65535, "WS only server"),
233 TestCase::Duration::QUICK);
235 65535,
236 65535,
237 "Window scaling not used, all enabled"),
238 TestCase::Duration::QUICK);
239 AddTestCase(new WScalingTestCase(WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"),
240 TestCase::Duration::QUICK);
242 65535,
243 65535,
244 "WS enabled client"),
245 TestCase::Duration::QUICK);
247 65535,
248 65535,
249 "WS disabled client"),
250 TestCase::Duration::QUICK);
251
253 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 200000, "WS only client"),
254 TestCase::Duration::QUICK);
256 new WScalingTestCase(WScalingTestCase::ENABLED, 131072, 65535, "WS only server"),
257 TestCase::Duration::QUICK);
259 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 131072, "WS only client"),
260 TestCase::Duration::QUICK);
262 new WScalingTestCase(WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"),
263 TestCase::Duration::QUICK);
265 4000,
266 4000,
267 "WS small window, sender"),
268 TestCase::Duration::QUICK);
269 }
270};
271
272static 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.
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:302
A suite of tests to run.
Definition: test.h:1273
Type
Type of test.
Definition: test.h:1280
static constexpr auto UNIT
Definition: test.h:1291
#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.