A Discrete-Event Network Simulator
API
tcp-sack-permitted-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include "tcp-general-test.h"
20
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/tcp-header.h"
24#include "ns3/tcp-option-sack-permitted.h"
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE("SackPermittedTestSuite");
29
38{
39 public:
42 {
47 };
48
54
55 protected:
58
59 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
60
62};
63
65 : TcpGeneralTest("Testing the TCP Sack Permitted option")
66{
68}
69
72{
73 Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket(node);
74
75 switch (m_configuration)
76 {
77 case DISABLED:
78 socket->SetAttribute("Sack", BooleanValue(false));
79 break;
80
82 socket->SetAttribute("Sack", BooleanValue(true));
83 break;
84
85 case ENABLED_SENDER:
86 socket->SetAttribute("Sack", BooleanValue(false));
87 break;
88
89 case ENABLED:
90 socket->SetAttribute("Sack", BooleanValue(true));
91 break;
92 }
93
94 return socket;
95}
96
99{
100 Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateSenderSocket(node);
101
102 switch (m_configuration)
103 {
104 case DISABLED:
105 socket->SetAttribute("Sack", BooleanValue(false));
106 break;
107
108 case ENABLED_RECEIVER:
109 socket->SetAttribute("Sack", BooleanValue(false));
110 break;
111
112 case ENABLED_SENDER:
113 socket->SetAttribute("Sack", BooleanValue(true));
114 break;
115
116 case ENABLED:
117 socket->SetAttribute("Sack", BooleanValue(true));
118 break;
119 }
120
121 return socket;
122}
123
124void
126{
127 if (!(h.GetFlags() & TcpHeader::SYN))
128 {
129 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
130 false,
131 "SackPermitted in non-SYN segment");
132 return;
133 }
134
136 {
137 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
138 false,
139 "SackPermitted disabled but option enabled");
140 }
141 else if (m_configuration == ENABLED)
142 {
143 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
144 true,
145 "SackPermitted enabled but option disabled");
146 }
147
148 NS_LOG_INFO(h);
149 if (who == SENDER)
150 {
151 if (h.GetFlags() & TcpHeader::SYN)
152 {
154 {
155 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
156 false,
157 "SackPermitted disabled but option enabled");
158 }
160 {
161 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
162 true,
163 "SackPermitted enabled but option disabled");
164 }
165 }
166 else
167 {
169 {
170 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
171 false,
172 "SackPermitted disabled but option enabled");
173 }
174 }
175 }
176 else if (who == RECEIVER)
177 {
178 if (h.GetFlags() & TcpHeader::SYN)
179 {
180 // Sender has not sent SackPermitted, so implementation should disable ts
182 {
183 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
184 false,
185 "sender has not ts, but receiver sent anyway");
186 }
188 {
189 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
190 false,
191 "receiver has not ts enabled but sent anyway");
192 }
193 }
194 else
195 {
197 {
198 NS_TEST_ASSERT_MSG_EQ(h.HasOption(TcpOption::SACKPERMITTED),
199 false,
200 "SackPermitted disabled but option enabled");
201 }
202 }
203 }
204}
205
213{
214 public:
217 : TestSuite("tcp-sack-permitted", UNIT)
218 {
221 TestCase::QUICK);
223 TestCase::QUICK);
225 }
226};
227
Test case for checking the SACK-PERMITTED option.
Configuration
Configuration of the test.
SackPermittedTestCase(SackPermittedTestCase::Configuration conf)
Constructor.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
Configuration m_configuration
The configuration.
The test case for testing the TCP SACK PERMITTED option.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
General infrastructure for TCP testing.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:502
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:167
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:144
Definition: conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpSackPermittedTestSuite g_tcpSackPermittedTestSuite
Static variable for test initialization.