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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-general-test.h"
9
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/tcp-header.h"
13#include "ns3/tcp-rx-buffer.h"
14#include "ns3/tcp-tx-buffer.h"
15#include "ns3/test.h"
16
17using namespace ns3;
18
19NS_LOG_COMPONENT_DEFINE("WScalingTestSuite");
20
21// TODO: Check the buffer size and scaling option value
22/**
23 * @ingroup internet-test
24 *
25 * @brief TCP Window Scaling enabling Test.
26 */
28{
29 public:
30 /**
31 * Window Scaling configuration.
32 */
40
41 /**
42 * @brief Constructor.
43 * @param conf Test configuration.
44 * @param maxRcvBufferSize Maximum receiver buffer size.
45 * @param maxSndBufferSize Maximum sender buffer size.
46 * @param name Test description.
47 */
49 uint32_t maxRcvBufferSize,
50 uint32_t maxSndBufferSize,
51 std::string name);
52
53 protected:
56
57 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
58
59 Configuration m_configuration; //!< Test configuration.
60 uint32_t m_maxRcvBufferSize; //!< Maximum receiver buffer size.
61 uint32_t m_maxSndBufferSize; //!< Maximum sender buffer size.
62};
63
65 uint32_t maxRcvBufferSize,
66 uint32_t maxSndBufferSize,
67 std::string name)
68 : TcpGeneralTest(name)
69{
71 m_maxRcvBufferSize = maxRcvBufferSize;
72 m_maxSndBufferSize = maxSndBufferSize;
73}
74
77{
79
80 switch (m_configuration)
81 {
82 case DISABLED:
83 socket->SetAttribute("WindowScaling", BooleanValue(false));
84 break;
85
87 socket->SetAttribute("WindowScaling", BooleanValue(true));
88 break;
89
90 case ENABLED_SENDER:
91 socket->SetAttribute("WindowScaling", BooleanValue(false));
92 break;
93
94 case ENABLED:
95 socket->SetAttribute("WindowScaling", BooleanValue(true));
96 break;
97 }
98
99 return socket;
100}
101
104{
106
107 switch (m_configuration)
108 {
109 case DISABLED:
110 case ENABLED_RECEIVER:
111 socket->SetAttribute("WindowScaling", BooleanValue(false));
112 break;
113
114 case ENABLED_SENDER:
115 case ENABLED:
116 socket->SetAttribute("WindowScaling", BooleanValue(true));
117 break;
118 }
119
120 return socket;
121}
122
123void
125{
126 NS_LOG_INFO(h);
127
128 if (!(h.GetFlags() & TcpHeader::SYN))
129 {
131 false,
132 "wscale present in non-SYN packets");
133 }
134 else
135 {
137 {
139 false,
140 "wscale disabled but option enabled");
141 }
142 else if (m_configuration == ENABLED)
143 {
145 true,
146 "wscale enabled but option disabled");
147
148 if (who == RECEIVER)
149 {
150 uint16_t advWin = h.GetWindowSize();
151 uint32_t maxSize = GetRxBuffer(RECEIVER)->MaxBufferSize();
152
153 if (maxSize > 65535)
154 {
155 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
156 }
157 else
158 {
159 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
160 }
161 }
162 }
163
164 if (who == SENDER)
165 {
167 {
169 false,
170 "wscale disabled but option enabled");
171 }
173 {
175 true,
176 "wscale enabled but option disabled");
177
178 uint16_t advWin = h.GetWindowSize();
179 uint32_t maxSize = GetRxBuffer(SENDER)->MaxBufferSize();
180
181 if (maxSize > 65535)
182 {
183 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
184 }
185 else
186 {
187 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
188 }
189 }
190 }
191 else if (who == RECEIVER)
192 {
194 {
196 false,
197 "sender has not ws, but receiver sent anyway");
198 }
200 {
202 false,
203 "receiver has not ws enabled but sent anyway");
204 }
205 }
206 }
207}
208
209/**
210 * @ingroup internet-test
211 *
212 * @brief TCP Window Scaling TestSuite.
213 */
215{
216 public:
218 : TestSuite("tcp-wscaling", Type::UNIT)
219 {
221 new WScalingTestCase(WScalingTestCase::ENABLED, 200000, 65535, "WS only server"),
222 TestCase::Duration::QUICK);
224 65535,
225 65535,
226 "Window scaling not used, all enabled"),
227 TestCase::Duration::QUICK);
228 AddTestCase(new WScalingTestCase(WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"),
229 TestCase::Duration::QUICK);
231 65535,
232 65535,
233 "WS enabled client"),
234 TestCase::Duration::QUICK);
236 65535,
237 65535,
238 "WS disabled client"),
239 TestCase::Duration::QUICK);
240
242 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 200000, "WS only client"),
243 TestCase::Duration::QUICK);
245 new WScalingTestCase(WScalingTestCase::ENABLED, 131072, 65535, "WS only server"),
246 TestCase::Duration::QUICK);
248 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 131072, "WS only client"),
249 TestCase::Duration::QUICK);
251 new WScalingTestCase(WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"),
252 TestCase::Duration::QUICK);
254 4000,
255 4000,
256 "WS small window, sender"),
257 TestCase::Duration::QUICK);
258 }
259};
260
261static 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:26
Smart pointer class similar to boost::intrusive_ptr.
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:36
uint16_t GetWindowSize() const
Get the window size.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
uint8_t GetFlags() const
Get the flags.
@ WINSCALE
WINSCALE.
Definition tcp-option.h:50
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#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:134
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.