A Discrete-Event Network Simulator
API
tcp-wscaling-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Natale Patriciello <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "ns3/test.h"
21 #include "tcp-general-test.h"
22 #include "ns3/node.h"
23 #include "ns3/log.h"
24 #include "ns3/tcp-header.h"
25 #include "ns3/tcp-tx-buffer.h"
26 #include "ns3/tcp-rx-buffer.h"
27 
28 using namespace ns3;
29 
30 
31 NS_LOG_COMPONENT_DEFINE ("WScalingTestSuite");
32 
33 // TODO: Check the buffer size and scaling option value
41 {
42 public:
47  {
51  ENABLED
52  };
53 
62  uint32_t maxRcvBufferSize,
63  uint32_t maxSndBufferSize, std::string name);
64 
65 protected:
66  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
67  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
68 
69  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
70 
72  uint32_t m_maxRcvBufferSize;
73  uint32_t m_maxSndBufferSize;
74 };
75 
77  uint32_t maxRcvBufferSize,
78  uint32_t maxSndBufferSize, 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), false,
148  "wscale present in non-SYN packets");
149  }
150  else
151  {
152  if (m_configuration == DISABLED)
153  {
154  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
155  "wscale disabled but option enabled");
156  }
157  else if (m_configuration == ENABLED)
158  {
159  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), true,
160  "wscale enabled but option disabled");
161 
162  if (who == RECEIVER)
163  {
164  uint16_t advWin = h.GetWindowSize ();
165  uint32_t maxSize = GetRxBuffer (RECEIVER)->MaxBufferSize ();
166 
167  if (maxSize > 65535)
168  {
169  NS_TEST_ASSERT_MSG_EQ (advWin, 65535, "Scaling SYN segment");
170  }
171  else
172  {
173  NS_TEST_ASSERT_MSG_EQ (advWin, maxSize, "Not advertising all window");
174  }
175  }
176  }
177 
178  if (who == SENDER)
179  {
181  {
182  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
183  "wscale disabled but option enabled");
184  }
185  else if (m_configuration == ENABLED_SENDER)
186  {
187  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), true,
188  "wscale enabled but option disabled");
189 
190  uint16_t advWin = h.GetWindowSize ();
191  uint32_t maxSize = GetRxBuffer (SENDER)->MaxBufferSize ();
192 
193  if (maxSize > 65535)
194  {
195  NS_TEST_ASSERT_MSG_EQ (advWin, 65535, "Scaling SYN segment");
196  }
197  else
198  {
199  NS_TEST_ASSERT_MSG_EQ (advWin, maxSize, "Not advertising all window");
200  }
201  }
202  }
203  else if (who == RECEIVER)
204  {
206  {
207  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
208  "sender has not ws, but receiver sent anyway");
209  }
210  else if (m_configuration == ENABLED_SENDER)
211  {
212  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
213  "receiver has not ws enabled but sent anyway");
214  }
215  }
216  }
217 }
218 
226 {
227 public:
229  : TestSuite ("tcp-wscaling", UNIT)
230  {
231  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 200000, 65535, "WS only server"), TestCase::QUICK);
232  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 65535, "Window scaling not used, all enabled"), TestCase::QUICK);
233  AddTestCase (new WScalingTestCase (WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"), TestCase::QUICK);
234  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 65535, 65535, "WS enabled client"), TestCase::QUICK);
235  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_RECEIVER, 65535, 65535, "WS disabled client"), TestCase::QUICK);
236 
237  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 200000, "WS only client"), TestCase::QUICK);
238  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 131072, 65535, "WS only server"), TestCase::QUICK);
239  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 131072, "WS only client"), TestCase::QUICK);
240  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"), TestCase::QUICK);
241  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 4000, 4000, "WS small window, sender"), TestCase::QUICK);
242  }
243 
244 };
245 
247 
uint32_t m_maxSndBufferSize
Maximum sender buffer size.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:36
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
A suite of tests to run.
Definition: test.h:1342
#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:278
Definition: conf.py:1
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:168
WScalingTestCase(WScalingTestCase::Configuration conf, uint32_t maxRcvBufferSize, uint32_t maxSndBufferSize, std::string name)
Constructor.
uint32_t m_maxRcvBufferSize
Maximum receiver buffer size.
Configuration m_configuration
Test configuration.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:511
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
Configuration
Window Scaling configuration.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
TCP Window Scaling TestSuite.
General infrastructure for TCP testing.
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
TCP Window Scaling enabling Test.
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:179
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
This test suite implements a Unit Test.
Definition: test.h:1352
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
static TcpWScalingTestSuite g_tcpWScalingTestSuite
Static variable for test initialization.