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 
25 using namespace ns3;
26 
27 
28 NS_LOG_COMPONENT_DEFINE ("WScalingTestSuite");
29 
30 // TODO: Check the buffer size and scaling option value
38 {
39 public:
44  {
48  ENABLED
49  };
50 
59  uint32_t maxRcvBufferSize,
60  uint32_t maxSndBufferSize, std::string name);
61 
62 protected:
63  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
64  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
65 
66  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
67 
69  uint32_t m_maxRcvBufferSize;
70  uint32_t m_maxSndBufferSize;
71 };
72 
74  uint32_t maxRcvBufferSize,
75  uint32_t maxSndBufferSize, std::string name)
76  : TcpGeneralTest (name)
77 {
78  m_configuration = conf;
79  m_maxRcvBufferSize = maxRcvBufferSize;
80  m_maxSndBufferSize = maxSndBufferSize;
81 }
82 
85 {
86  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket (node);
87 
88  switch (m_configuration)
89  {
90  case DISABLED:
91  socket->SetAttribute ("WindowScaling", BooleanValue (false));
92  break;
93 
94  case ENABLED_RECEIVER:
95  socket->SetAttribute ("WindowScaling", BooleanValue (true));
96  break;
97 
98  case ENABLED_SENDER:
99  socket->SetAttribute ("WindowScaling", BooleanValue (false));
100  break;
101 
102  case ENABLED:
103  socket->SetAttribute ("WindowScaling", BooleanValue (true));
104  break;
105  }
106 
107  return socket;
108 }
109 
112 {
113  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateSenderSocket (node);
114 
115  switch (m_configuration)
116  {
117  case DISABLED:
118  socket->SetAttribute ("WindowScaling", BooleanValue (false));
119  break;
120 
121  case ENABLED_RECEIVER:
122  socket->SetAttribute ("WindowScaling", BooleanValue (false));
123  break;
124 
125  case ENABLED_SENDER:
126  socket->SetAttribute ("WindowScaling", BooleanValue (true));
127  break;
128 
129  case ENABLED:
130  socket->SetAttribute ("WindowScaling", BooleanValue (true));
131  break;
132  }
133 
134  return socket;
135 }
136 
137 void
139 {
140  NS_LOG_INFO (h);
141 
142  if (! (h.GetFlags() & TcpHeader::SYN))
143  {
144  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
145  "wscale present in non-SYN packets");
146  }
147  else
148  {
149  if (m_configuration == DISABLED)
150  {
151  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
152  "wscale disabled but option enabled");
153  }
154  else if (m_configuration == ENABLED)
155  {
156  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), 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  {
179  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
180  "wscale disabled but option enabled");
181  }
182  else if (m_configuration == ENABLED_SENDER)
183  {
184  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), true,
185  "wscale enabled but option disabled");
186 
187  uint16_t advWin = h.GetWindowSize ();
188  uint32_t maxSize = GetRxBuffer (SENDER)->MaxBufferSize ();
189 
190  if (maxSize > 65535)
191  {
192  NS_TEST_ASSERT_MSG_EQ (advWin, 65535, "Scaling SYN segment");
193  }
194  else
195  {
196  NS_TEST_ASSERT_MSG_EQ (advWin, maxSize, "Not advertising all window");
197  }
198  }
199  }
200  else if (who == RECEIVER)
201  {
203  {
204  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
205  "sender has not ws, but receiver sent anyway");
206  }
207  else if (m_configuration == ENABLED_SENDER)
208  {
209  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::WINSCALE), false,
210  "receiver has not ws enabled but sent anyway");
211  }
212  }
213  }
214 }
215 
223 {
224 public:
226  : TestSuite ("tcp-wscaling", UNIT)
227  {
228  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 200000, 65535, "WS only server"), TestCase::QUICK);
229  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 65535, "Window scaling not used, all enabled"), TestCase::QUICK);
230  AddTestCase (new WScalingTestCase (WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"), TestCase::QUICK);
231  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 65535, 65535, "WS enabled client"), TestCase::QUICK);
232  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_RECEIVER, 65535, 65535, "WS disabled client"), TestCase::QUICK);
233 
234  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 200000, "WS only client"), TestCase::QUICK);
235  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 131072, 65535, "WS only server"), TestCase::QUICK);
236  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 131072, "WS only client"), TestCase::QUICK);
237  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"), TestCase::QUICK);
238  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 4000, 4000, "WS small window, sender"), TestCase::QUICK);
239  }
240 
241 };
242 
244 
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
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
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:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
Definition: conf.py:1
This test suite implements a Unit Test.
Definition: test.h:1352
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:179
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
#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.
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.
TCP Window Scaling TestSuite.
General infrastructure for TCP testing.
TCP Window Scaling enabling Test.
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.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:511
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.