A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
37{
38 public:
41 {
46 };
47
53
54 protected:
57
58 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
59
61};
62
64 : TcpGeneralTest("Testing the TCP Sack Permitted option")
65{
67}
68
71{
73
74 switch (m_configuration)
75 {
76 case DISABLED:
77 socket->SetAttribute("Sack", BooleanValue(false));
78 break;
79
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{
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
123void
125{
126 if (!(h.GetFlags() & TcpHeader::SYN))
127 {
129 false,
130 "SackPermitted in non-SYN segment");
131 return;
132 }
133
135 {
137 false,
138 "SackPermitted disabled but option enabled");
139 }
140 else if (m_configuration == ENABLED)
141 {
143 true,
144 "SackPermitted enabled but option disabled");
145 }
146
147 NS_LOG_INFO(h);
148 if (who == SENDER)
149 {
150 if (h.GetFlags() & TcpHeader::SYN)
151 {
153 {
155 false,
156 "SackPermitted disabled but option enabled");
157 }
159 {
161 true,
162 "SackPermitted enabled but option disabled");
163 }
164 }
165 else
166 {
168 {
170 false,
171 "SackPermitted disabled but option enabled");
172 }
173 }
174 }
175 else if (who == RECEIVER)
176 {
177 if (h.GetFlags() & TcpHeader::SYN)
178 {
179 // Sender has not sent SackPermitted, so implementation should disable ts
181 {
183 false,
184 "sender has not ts, but receiver sent anyway");
185 }
187 {
189 false,
190 "receiver has not ts enabled but sent anyway");
191 }
192 }
193 else
194 {
196 {
198 false,
199 "SackPermitted disabled but option enabled");
200 }
201 }
202 }
203}
204
212{
213 public:
216 : TestSuite("tcp-sack-permitted", Type::UNIT)
217 {
219 TestCase::Duration::QUICK);
221 TestCase::Duration::QUICK);
223 TestCase::Duration::QUICK);
225 TestCase::Duration::QUICK);
226 }
227};
228
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:77
General infrastructure for TCP testing.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:478
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:148
@ SACKPERMITTED
SACKPERMITTED.
Definition: tcp-option.h:62
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#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:145
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.