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 
28 using namespace ns3;
29 
30 NS_LOG_COMPONENT_DEFINE("WScalingTestSuite");
31 
32 // TODO: Check the buffer size and scaling option value
39 {
40  public:
45  {
49  ENABLED
50  };
51 
60  uint32_t maxRcvBufferSize,
61  uint32_t maxSndBufferSize,
62  std::string name);
63 
64  protected:
65  Ptr<TcpSocketMsgBase> CreateReceiverSocket(Ptr<Node> node) override;
66  Ptr<TcpSocketMsgBase> CreateSenderSocket(Ptr<Node> node) override;
67 
68  void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
69 
71  uint32_t m_maxRcvBufferSize;
72  uint32_t m_maxSndBufferSize;
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 {
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 
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
142 {
143  NS_LOG_INFO(h);
144 
145  if (!(h.GetFlags() & TcpHeader::SYN))
146  {
147  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
148  false,
149  "wscale present in non-SYN packets");
150  }
151  else
152  {
153  if (m_configuration == DISABLED)
154  {
155  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
156  false,
157  "wscale disabled but option enabled");
158  }
159  else if (m_configuration == ENABLED)
160  {
161  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
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  {
185  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
186  false,
187  "wscale disabled but option enabled");
188  }
189  else if (m_configuration == ENABLED_SENDER)
190  {
191  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
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  {
212  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
213  false,
214  "sender has not ws, but receiver sent anyway");
215  }
216  else if (m_configuration == ENABLED_SENDER)
217  {
218  NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::WINSCALE),
219  false,
220  "receiver has not ws enabled but sent anyway");
221  }
222  }
223  }
224 }
225 
232 {
233  public:
235  : TestSuite("tcp-wscaling", UNIT)
236  {
237  AddTestCase(
238  new WScalingTestCase(WScalingTestCase::ENABLED, 200000, 65535, "WS only server"),
239  TestCase::QUICK);
241  65535,
242  65535,
243  "Window scaling not used, all enabled"),
244  TestCase::QUICK);
245  AddTestCase(new WScalingTestCase(WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"),
246  TestCase::QUICK);
248  65535,
249  65535,
250  "WS enabled client"),
251  TestCase::QUICK);
253  65535,
254  65535,
255  "WS disabled client"),
256  TestCase::QUICK);
257 
258  AddTestCase(
259  new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 200000, "WS only client"),
260  TestCase::QUICK);
261  AddTestCase(
262  new WScalingTestCase(WScalingTestCase::ENABLED, 131072, 65535, "WS only server"),
263  TestCase::QUICK);
264  AddTestCase(
265  new WScalingTestCase(WScalingTestCase::ENABLED, 65535, 131072, "WS only client"),
266  TestCase::QUICK);
267  AddTestCase(
268  new WScalingTestCase(WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"),
269  TestCase::QUICK);
271  4000,
272  4000,
273  "WS small window, sender"),
274  TestCase::QUICK);
275  }
276 };
277 
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.
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: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
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
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.