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 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("WScalingTestSuite");
28 
29 // TODO: Check the buffer size and scaling option value
31 {
32 public:
34  {
39  };
40 
42  uint32_t maxRcvBufferSize,
43  uint32_t maxSndBufferSize, std::string name);
44 
45 protected:
48 
49  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
50 
54 };
55 
57  uint32_t maxRcvBufferSize,
58  uint32_t maxSndBufferSize, std::string name)
59  : TcpGeneralTest (name)
60 {
61  m_configuration = conf;
62  m_maxRcvBufferSize = maxRcvBufferSize;
63  m_maxSndBufferSize = maxSndBufferSize;
64 }
65 
68 {
70 
71  switch (m_configuration)
72  {
73  case DISABLED:
74  socket->SetAttribute ("WindowScaling", BooleanValue (false));
75  break;
76 
77  case ENABLED_RECEIVER:
78  socket->SetAttribute ("WindowScaling", BooleanValue (true));
79  break;
80 
81  case ENABLED_SENDER:
82  socket->SetAttribute ("WindowScaling", BooleanValue (false));
83  break;
84 
85  case ENABLED:
86  socket->SetAttribute ("WindowScaling", BooleanValue (true));
87  break;
88  }
89 
90  return socket;
91 }
92 
95 {
97 
98  switch (m_configuration)
99  {
100  case DISABLED:
101  socket->SetAttribute ("WindowScaling", BooleanValue (false));
102  break;
103 
104  case ENABLED_RECEIVER:
105  socket->SetAttribute ("WindowScaling", BooleanValue (false));
106  break;
107 
108  case ENABLED_SENDER:
109  socket->SetAttribute ("WindowScaling", BooleanValue (true));
110  break;
111 
112  case ENABLED:
113  socket->SetAttribute ("WindowScaling", BooleanValue (true));
114  break;
115  }
116 
117  return socket;
118 }
119 
120 void
122 {
123  NS_LOG_INFO (h);
124 
125  if (! (h.GetFlags() & TcpHeader::SYN))
126  {
128  "wscale present in non-SYN packets");
129  }
130  else
131  {
132  if (m_configuration == DISABLED)
133  {
135  "wscale disabled but option enabled");
136  }
137  else if (m_configuration == ENABLED)
138  {
140  "wscale enabled but option disabled");
141 
142  if (who == RECEIVER)
143  {
144  uint16_t advWin = h.GetWindowSize ();
145  uint32_t maxSize = GetRxBuffer (RECEIVER)->MaxBufferSize ();
146 
147  if (maxSize > 65535)
148  {
149  NS_TEST_ASSERT_MSG_EQ (advWin, 65535, "Scaling SYN segment");
150  }
151  else
152  {
153  NS_TEST_ASSERT_MSG_EQ (advWin, maxSize, "Not advertising all window");
154  }
155  }
156  }
157 
158  if (who == SENDER)
159  {
161  {
163  "wscale disabled but option enabled");
164  }
165  else if (m_configuration == ENABLED_SENDER)
166  {
168  "wscale enabled but option disabled");
169 
170  uint16_t advWin = h.GetWindowSize ();
171  uint32_t maxSize = GetRxBuffer (SENDER)->MaxBufferSize ();
172 
173  if (maxSize > 65535)
174  {
175  NS_TEST_ASSERT_MSG_EQ (advWin, 65535, "Scaling SYN segment");
176  }
177  else
178  {
179  NS_TEST_ASSERT_MSG_EQ (advWin, maxSize, "Not advertising all window");
180  }
181  }
182  }
183  else if (who == RECEIVER)
184  {
186  {
188  "sender has not ws, but receiver sent anyway");
189  }
190  else if (m_configuration == ENABLED_SENDER)
191  {
193  "receiver has not ws enabled but sent anyway");
194  }
195  }
196  }
197 }
198 
199 static class TcpWScalingTestSuite : public TestSuite
200 {
201 public:
203  : TestSuite ("tcp-wscaling", UNIT)
204  {
205  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 200000, 65535, "WS only server"), TestCase::QUICK);
206  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 65535, "Window scaling not used, all enabled"), TestCase::QUICK);
207  AddTestCase (new WScalingTestCase (WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"), TestCase::QUICK);
208  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 65535, 65535, "WS enabled client"), TestCase::QUICK);
209  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_RECEIVER, 65535, 65535, "WS disabled client"), TestCase::QUICK);
210 
211  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 200000, "WS only client"), TestCase::QUICK);
212  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 131072, 65535, "WS only server"), TestCase::QUICK);
213  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 131072, "WS only client"), TestCase::QUICK);
214  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 4000, 4000, "WS small window, all"), TestCase::QUICK);
215  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 4000, 4000, "WS small window, sender"), TestCase::QUICK);
216  }
217 
219 
220 } // namespace ns3
221 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:34
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
ns3::TcpWScalingTestSuite g_tcpWScalingTestSuite
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
Definition: conf.py:1
This test suite implements a Unit Test.
Definition: test.h:1343
Configuration m_configuration
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:179
WScalingTestCase(WScalingTestCase::Configuration conf, uint32_t maxRcvBufferSize, uint32_t maxSndBufferSize, std::string name)
#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:161
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:505