A Discrete-Event Network Simulator
API
tcp-sack-permitted-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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 "tcp-general-test.h"
21 #include "ns3/node.h"
22 #include "ns3/log.h"
23 #include "ns3/tcp-option-sack-permitted.h"
24 
25 using namespace ns3;
26 
27 NS_LOG_COMPONENT_DEFINE ("SackPermittedTestSuite");
28 
37 {
38 public:
41  {
45  ENABLED
46  };
47 
53 protected:
54  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
55  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
56 
57  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
58 
60 };
61 
63  : TcpGeneralTest ("Testing the TCP Sack Permitted option")
64 {
65  m_configuration = conf;
66 }
67 
70 {
71  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket (node);
72 
73  switch (m_configuration)
74  {
75  case DISABLED:
76  socket->SetAttribute ("Sack", BooleanValue (false));
77  break;
78 
79  case ENABLED_RECEIVER:
80  socket->SetAttribute ("Sack", BooleanValue (true));
81  break;
82 
83  case ENABLED_SENDER:
84  socket->SetAttribute ("Sack", BooleanValue (false));
85  break;
86 
87  case ENABLED:
88  socket->SetAttribute ("Sack", BooleanValue (true));
89  break;
90  }
91 
92  return socket;
93 }
94 
97 {
98  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateSenderSocket (node);
99 
100  switch (m_configuration)
101  {
102  case DISABLED:
103  socket->SetAttribute ("Sack", BooleanValue (false));
104  break;
105 
106  case ENABLED_RECEIVER:
107  socket->SetAttribute ("Sack", BooleanValue (false));
108  break;
109 
110  case ENABLED_SENDER:
111  socket->SetAttribute ("Sack", BooleanValue (true));
112  break;
113 
114  case ENABLED:
115  socket->SetAttribute ("Sack", BooleanValue (true));
116  break;
117  }
118 
119  return socket;
120 }
121 
122 void
124 {
125 
126  if (!(h.GetFlags () & TcpHeader::SYN))
127  {
128  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
129  "SackPermitted in non-SYN segment");
130  return;
131  }
132 
133  if (m_configuration == DISABLED)
134  {
135  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
136  "SackPermitted disabled but option enabled");
137  }
138  else if (m_configuration == ENABLED)
139  {
140  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), true,
141  "SackPermitted enabled but option disabled");
142  }
143 
144  NS_LOG_INFO (h);
145  if (who == SENDER)
146  {
147  if (h.GetFlags () & TcpHeader::SYN)
148  {
150  {
151  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
152  "SackPermitted disabled but option enabled");
153  }
154  else if (m_configuration == ENABLED_SENDER)
155  {
156  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), true,
157  "SackPermitted enabled but option disabled");
158  }
159  }
160  else
161  {
162  if (m_configuration != ENABLED)
163  {
164  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
165  "SackPermitted disabled but option enabled");
166  }
167  }
168  }
169  else if (who == RECEIVER)
170  {
171  if (h.GetFlags () & TcpHeader::SYN)
172  {
173  // Sender has not sent SackPermitted, so implementation should disable ts
175  {
176  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
177  "sender has not ts, but receiver sent anyway");
178  }
179  else if (m_configuration == ENABLED_SENDER)
180  {
181  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
182  "receiver has not ts enabled but sent anyway");
183  }
184  }
185  else
186  {
187  if (m_configuration != ENABLED)
188  {
189  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
190  "SackPermitted disabled but option enabled");
191  }
192  }
193  }
194 }
195 
203 {
204 public:
207  : TestSuite ("tcp-sack-permitted", UNIT)
208  {
213  }
214 
215 };
216 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
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
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
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.
General infrastructure for TCP testing.
Configuration
Configuration of the test.
SackPermittedTestCase(SackPermittedTestCase::Configuration conf)
Constructor.
static TcpSackPermittedTestSuite g_tcpSackPermittedTestSuite
Static variable for test initialization.
Test case for checking the SACK-PERMITTED option.
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
The test case for testing the TCP SACK PERMITTED option.
Configuration m_configuration
The configuration.