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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-general-test.h"
9
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/tcp-header.h"
13#include "ns3/tcp-option-sack-permitted.h"
14
15using namespace ns3;
16
17NS_LOG_COMPONENT_DEFINE("SackPermittedTestSuite");
18
19/**
20 * @ingroup internet-test
21 *
22 * @brief Test case for checking the SACK-PERMITTED option.
23 *
24 */
26{
27 public:
28 /** @brief Configuration of the test */
36
37 /**
38 * @brief Constructor
39 * @param conf Test configuration.
40 * */
42
43 protected:
46
47 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
48
49 Configuration m_configuration; //!< The configuration
50};
51
57
60{
62
63 switch (m_configuration)
64 {
65 case DISABLED:
66 socket->SetAttribute("Sack", BooleanValue(false));
67 break;
68
70 socket->SetAttribute("Sack", BooleanValue(true));
71 break;
72
73 case ENABLED_SENDER:
74 socket->SetAttribute("Sack", BooleanValue(false));
75 break;
76
77 case ENABLED:
78 socket->SetAttribute("Sack", BooleanValue(true));
79 break;
80 }
81
82 return socket;
83}
84
87{
89
90 switch (m_configuration)
91 {
92 case DISABLED:
94 socket->SetAttribute("Sack", BooleanValue(false));
95 break;
96
97 case ENABLED_SENDER:
98 case ENABLED:
99 socket->SetAttribute("Sack", BooleanValue(true));
100 break;
101 }
102
103 return socket;
104}
105
106void
108{
109 if (!(h.GetFlags() & TcpHeader::SYN))
110 {
112 false,
113 "SackPermitted in non-SYN segment");
114 return;
115 }
116
118 {
120 false,
121 "SackPermitted disabled but option enabled");
122 }
123 else if (m_configuration == ENABLED)
124 {
126 true,
127 "SackPermitted enabled but option disabled");
128 }
129
130 NS_LOG_INFO(h);
131 if (who == SENDER)
132 {
133 if (h.GetFlags() & TcpHeader::SYN)
134 {
136 {
138 false,
139 "SackPermitted disabled but option enabled");
140 }
142 {
144 true,
145 "SackPermitted enabled but option disabled");
146 }
147 }
148 else
149 {
151 {
153 false,
154 "SackPermitted disabled but option enabled");
155 }
156 }
157 }
158 else if (who == RECEIVER)
159 {
160 if (h.GetFlags() & TcpHeader::SYN)
161 {
162 // Sender has not sent SackPermitted, so implementation should disable ts
164 {
166 false,
167 "sender has not ts, but receiver sent anyway");
168 }
170 {
172 false,
173 "receiver has not ts enabled but sent anyway");
174 }
175 }
176 else
177 {
179 {
181 false,
182 "SackPermitted disabled but option enabled");
183 }
184 }
185 }
186}
187
188/**
189 * @ingroup internet-test
190 * @ingroup tests
191 *
192 * The test case for testing the TCP SACK PERMITTED option.
193 */
195{
196 public:
197 /** @brief Constructor */
199 : TestSuite("tcp-sack-permitted", Type::UNIT)
200 {
202 TestCase::Duration::QUICK);
204 TestCase::Duration::QUICK);
206 TestCase::Duration::QUICK);
208 TestCase::Duration::QUICK);
209 }
210};
211
213 g_tcpSackPermittedTestSuite; //!< Static variable for test initialization
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:26
Smart pointer class similar to boost::intrusive_ptr.
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:36
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
uint8_t GetFlags() const
Get the flags.
@ SACKPERMITTED
SACKPERMITTED.
Definition tcp-option.h:51
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#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:134
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.