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 
143  if (who == SENDER)
144  {
146  {
148  "wscale disabled but option enabled");
149  }
150  else if (m_configuration == ENABLED_SENDER)
151  {
153  "wscale enabled but option disabled");
154  }
155  }
156  else if (who == RECEIVER)
157  {
159  {
161  "sender has not ws, but receiver sent anyway");
162  }
163  else if (m_configuration == ENABLED_SENDER)
164  {
166  "receiver has not ws enabled but sent anyway");
167  }
168  }
169  }
170 }
171 
172 static class TcpWScalingTestSuite : public TestSuite
173 {
174 public:
176  : TestSuite ("tcp-wscaling", UNIT)
177  {
178  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 200000, 65535, "WS only server"), TestCase::QUICK);
179  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 65535, "Window scaling not used, all enabled"), TestCase::QUICK);
180  AddTestCase (new WScalingTestCase (WScalingTestCase::DISABLED, 65535, 65535, "WS disabled"), TestCase::QUICK);
181  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_SENDER, 65535, 65535, "WS enabled client"), TestCase::QUICK);
182  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED_RECEIVER, 65535, 65535, "WS disabled client"), TestCase::QUICK);
183 
184  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 200000, "WS only client"), TestCase::QUICK);
185  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 131072, 65535, "WS only server"), TestCase::QUICK);
186  AddTestCase (new WScalingTestCase (WScalingTestCase::ENABLED, 65535, 131072, "WS only client"), TestCase::QUICK);
187  }
188 
190 
191 } // namespace ns3
192 
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:297
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.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:502