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 #include "ns3/tcp-header.h"
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("SackPermittedTestSuite");
29 
38 {
39 public:
42  {
46  ENABLED
47  };
48 
54 protected:
55  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
56  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
57 
58  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
59 
61 };
62 
64  : TcpGeneralTest ("Testing the TCP Sack Permitted option")
65 {
67 }
68 
71 {
72  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket (node);
73 
74  switch (m_configuration)
75  {
76  case DISABLED:
77  socket->SetAttribute ("Sack", BooleanValue (false));
78  break;
79 
80  case ENABLED_RECEIVER:
81  socket->SetAttribute ("Sack", BooleanValue (true));
82  break;
83 
84  case ENABLED_SENDER:
85  socket->SetAttribute ("Sack", BooleanValue (false));
86  break;
87 
88  case ENABLED:
89  socket->SetAttribute ("Sack", BooleanValue (true));
90  break;
91  }
92 
93  return socket;
94 }
95 
98 {
99  Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateSenderSocket (node);
100 
101  switch (m_configuration)
102  {
103  case DISABLED:
104  socket->SetAttribute ("Sack", BooleanValue (false));
105  break;
106 
107  case ENABLED_RECEIVER:
108  socket->SetAttribute ("Sack", BooleanValue (false));
109  break;
110 
111  case ENABLED_SENDER:
112  socket->SetAttribute ("Sack", BooleanValue (true));
113  break;
114 
115  case ENABLED:
116  socket->SetAttribute ("Sack", BooleanValue (true));
117  break;
118  }
119 
120  return socket;
121 }
122 
123 void
125 {
126 
127  if (!(h.GetFlags () & TcpHeader::SYN))
128  {
129  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
130  "SackPermitted in non-SYN segment");
131  return;
132  }
133 
134  if (m_configuration == DISABLED)
135  {
136  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
137  "SackPermitted disabled but option enabled");
138  }
139  else if (m_configuration == ENABLED)
140  {
141  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), true,
142  "SackPermitted enabled but option disabled");
143  }
144 
145  NS_LOG_INFO (h);
146  if (who == SENDER)
147  {
148  if (h.GetFlags () & TcpHeader::SYN)
149  {
151  {
152  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
153  "SackPermitted disabled but option enabled");
154  }
155  else if (m_configuration == ENABLED_SENDER)
156  {
157  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), true,
158  "SackPermitted enabled but option disabled");
159  }
160  }
161  else
162  {
163  if (m_configuration != ENABLED)
164  {
165  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
166  "SackPermitted disabled but option enabled");
167  }
168  }
169  }
170  else if (who == RECEIVER)
171  {
172  if (h.GetFlags () & TcpHeader::SYN)
173  {
174  // Sender has not sent SackPermitted, so implementation should disable ts
176  {
177  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
178  "sender has not ts, but receiver sent anyway");
179  }
180  else if (m_configuration == ENABLED_SENDER)
181  {
182  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
183  "receiver has not ts enabled but sent anyway");
184  }
185  }
186  else
187  {
188  if (m_configuration != ENABLED)
189  {
190  NS_TEST_ASSERT_MSG_EQ (h.HasOption (TcpOption::SACKPERMITTED), false,
191  "SackPermitted disabled but option enabled");
192  }
193  }
194  }
195 }
196 
204 {
205 public:
208  : TestSuite ("tcp-sack-permitted", UNIT)
209  {
214  }
215 
216 };
217 
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
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:204
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
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
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:511
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.
Configuration
Configuration of the test.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
SackPermittedTestCase(SackPermittedTestCase::Configuration conf)
Constructor.
static TcpSackPermittedTestSuite g_tcpSackPermittedTestSuite
Static variable for test initialization.
Test case for checking the SACK-PERMITTED option.
This test suite implements a Unit Test.
Definition: test.h:1351
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.