A Discrete-Event Network Simulator
API
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
40{
41 public:
46 {
51 };
52
61 uint32_t maxRcvBufferSize,
62 uint32_t maxSndBufferSize,
63 std::string name);
64
65 protected:
68
69 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
70
74};
75
77 uint32_t maxRcvBufferSize,
78 uint32_t maxSndBufferSize,
79 std::string name)
80 : TcpGeneralTest(name)
81{
83 m_maxRcvBufferSize = maxRcvBufferSize;
84 m_maxSndBufferSize = maxSndBufferSize;
85}
86
89{
90 Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket(node);
91
92 switch (m_configuration)
93 {
94 case DISABLED:
95 socket->SetAttribute("WindowScaling", BooleanValue(false));
96 break;
97
99 socket->SetAttribute("WindowScaling", BooleanValue(true));
100 break;
101
102 case ENABLED_SENDER:
103 socket->SetAttribute("WindowScaling", BooleanValue(false));
104 break;
105
106 case ENABLED:
107 socket->SetAttribute("WindowScaling", BooleanValue(true));
108 break;
109 }
110
111 return socket;
112}
113
116{
117 Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateSenderSocket(node);
118
119 switch (m_configuration)
120 {
121 case DISABLED:
122 socket->SetAttribute("WindowScaling", BooleanValue(false));
123 break;
124
125 case ENABLED_RECEIVER:
126 socket->SetAttribute("WindowScaling", BooleanValue(false));
127 break;
128
129 case ENABLED_SENDER:
130 socket->SetAttribute("WindowScaling", BooleanValue(true));
131 break;
132
133 case ENABLED:
134 socket->SetAttribute("WindowScaling", BooleanValue(true));
135 break;
136 }
137
138 return socket;
139}
140
141void
143{
144 NS_LOG_INFO(h);
145
146 if (!(h.GetFlags() & TcpHeader::SYN))
147 {
148 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
149 false,
150 "wscale present in non-SYN packets");
151 }
152 else
153 {
155 {
156 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
157 false,
158 "wscale disabled but option enabled");
159 }
160 else if (m_configuration == ENABLED)
161 {
162 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
163 true,
164 "wscale enabled but option disabled");
165
166 if (who == RECEIVER)
167 {
168 uint16_t advWin = h.GetWindowSize();
169 uint32_t maxSize = GetRxBuffer(RECEIVER)->MaxBufferSize();
170
171 if (maxSize > 65535)
172 {
173 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
174 }
175 else
176 {
177 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
178 }
179 }
180 }
181
182 if (who == SENDER)
183 {
185 {
186 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
187 false,
188 "wscale disabled but option enabled");
189 }
191 {
192 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
193 true,
194 "wscale enabled but option disabled");
195
196 uint16_t advWin = h.GetWindowSize();
197 uint32_t maxSize = GetRxBuffer(SENDER)->MaxBufferSize();
198
199 if (maxSize > 65535)
200 {
201 NS_TEST_ASSERT_MSG_EQ(advWin, 65535, "Scaling SYN segment");
202 }
203 else
204 {
205 NS_TEST_ASSERT_MSG_EQ(advWin, maxSize, "Not advertising all window");
206 }
207 }
208 }
209 else if (who == RECEIVER)
210 {
212 {
213 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
214 false,
215 "sender has not ws, but receiver sent anyway");
216 }
218 {
219 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
220 false,
221 "receiver has not ws enabled but sent anyway");
222 }
223 }
224 }
225}
226
234{
235 public:
237 : TestSuite("tcp-wscaling", UNIT)
238 {
240 new WScalingTestCase(WScalingTestCase::ENABLED, 200000, 65535, "WS only server"),
241 TestCase::QUICK);
243 65535,
244 65535,
245 "Window scaling not used, all enabled"),
246 TestCase::QUICK);
247 AddTestCase(new WScalingTestCase(WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"),
248 TestCase::QUICK);
250 65535,
251 65535,
252 "WS enabled client"),
253 TestCase::QUICK);
255 65535,
256 65535,
257 "WS disabled client"),
258 TestCase::QUICK);
259
261 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 200000, "WS only client"),
262 TestCase::QUICK);
264 new WScalingTestCase(WScalingTestCase::ENABLED, 131072, 65535, "WS only server"),
265 TestCase::QUICK);
267 new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 131072, "WS only client"),
268 TestCase::QUICK);
270 new WScalingTestCase(WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"),
271 TestCase::QUICK);
273 4000,
274 4000,
275 "WS small window, sender"),
276 TestCase::QUICK);
277 }
278};
279
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:78
General infrastructure for TCP testing.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:173
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:502
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:167
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
#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:144
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.