A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
15
using namespace
ns3
;
16
17
NS_LOG_COMPONENT_DEFINE
(
"SackPermittedTestSuite"
);
18
19
/**
20
* @ingroup internet-test
21
*
22
* @brief Test case for checking the SACK-PERMITTED option.
23
*
24
*/
25
class
SackPermittedTestCase
:
public
TcpGeneralTest
26
{
27
public
:
28
/** @brief Configuration of the test */
29
enum
Configuration
30
{
31
DISABLED
,
32
ENABLED_RECEIVER
,
33
ENABLED_SENDER
,
34
ENABLED
35
};
36
37
/**
38
* @brief Constructor
39
* @param conf Test configuration.
40
* */
41
SackPermittedTestCase
(
SackPermittedTestCase::Configuration
conf
);
42
43
protected
:
44
Ptr<TcpSocketMsgBase>
CreateReceiverSocket
(
Ptr<Node>
node)
override
;
45
Ptr<TcpSocketMsgBase>
CreateSenderSocket
(
Ptr<Node>
node)
override
;
46
47
void
Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
& h,
SocketWho
who)
override
;
48
49
Configuration
m_configuration
;
//!< The configuration
50
};
51
52
SackPermittedTestCase::SackPermittedTestCase
(
SackPermittedTestCase::Configuration
conf
)
53
:
TcpGeneralTest
(
"Testing the TCP Sack Permitted option"
)
54
{
55
m_configuration
=
conf
;
56
}
57
58
Ptr<TcpSocketMsgBase>
59
SackPermittedTestCase::CreateReceiverSocket
(
Ptr<Node>
node)
60
{
61
Ptr<TcpSocketMsgBase>
socket =
TcpGeneralTest::CreateReceiverSocket
(node);
62
63
switch
(
m_configuration
)
64
{
65
case
DISABLED
:
66
socket->SetAttribute(
"Sack"
,
BooleanValue
(
false
));
67
break
;
68
69
case
ENABLED_RECEIVER
:
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
85
Ptr<TcpSocketMsgBase>
86
SackPermittedTestCase::CreateSenderSocket
(
Ptr<Node>
node)
87
{
88
Ptr<TcpSocketMsgBase>
socket =
TcpGeneralTest::CreateSenderSocket
(node);
89
90
switch
(
m_configuration
)
91
{
92
case
DISABLED
:
93
case
ENABLED_RECEIVER
:
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
106
void
107
SackPermittedTestCase::Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
& h,
SocketWho
who)
108
{
109
if
(!(h.
GetFlags
() &
TcpHeader::SYN
))
110
{
111
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
112
false
,
113
"SackPermitted in non-SYN segment"
);
114
return
;
115
}
116
117
if
(
m_configuration
==
DISABLED
)
118
{
119
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
120
false
,
121
"SackPermitted disabled but option enabled"
);
122
}
123
else
if
(
m_configuration
==
ENABLED
)
124
{
125
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
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
{
135
if
(
m_configuration
==
ENABLED_RECEIVER
)
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_SENDER
)
142
{
143
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
144
true
,
145
"SackPermitted enabled but option disabled"
);
146
}
147
}
148
else
149
{
150
if
(
m_configuration
!=
ENABLED
)
151
{
152
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
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
163
if
(
m_configuration
==
ENABLED_RECEIVER
)
164
{
165
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
166
false
,
167
"sender has not ts, but receiver sent anyway"
);
168
}
169
else
if
(
m_configuration
==
ENABLED_SENDER
)
170
{
171
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
172
false
,
173
"receiver has not ts enabled but sent anyway"
);
174
}
175
}
176
else
177
{
178
if
(
m_configuration
!=
ENABLED
)
179
{
180
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
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
*/
194
class
TcpSackPermittedTestSuite
:
public
TestSuite
195
{
196
public
:
197
/** @brief Constructor */
198
TcpSackPermittedTestSuite
()
199
:
TestSuite
(
"tcp-sack-permitted"
,
Type
::
UNIT
)
200
{
201
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::DISABLED
),
202
TestCase::Duration::QUICK);
203
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED_RECEIVER
),
204
TestCase::Duration::QUICK);
205
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED_SENDER
),
206
TestCase::Duration::QUICK);
207
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED
),
208
TestCase::Duration::QUICK);
209
}
210
};
211
212
static
TcpSackPermittedTestSuite
213
g_tcpSackPermittedTestSuite
;
//!< Static variable for test initialization
SackPermittedTestCase
Test case for checking the SACK-PERMITTED option.
Definition
tcp-sack-permitted-test.cc:26
SackPermittedTestCase::Configuration
Configuration
Configuration of the test.
Definition
tcp-sack-permitted-test.cc:30
SackPermittedTestCase::ENABLED_RECEIVER
@ ENABLED_RECEIVER
Definition
tcp-sack-permitted-test.cc:32
SackPermittedTestCase::ENABLED
@ ENABLED
Definition
tcp-sack-permitted-test.cc:34
SackPermittedTestCase::DISABLED
@ DISABLED
Definition
tcp-sack-permitted-test.cc:31
SackPermittedTestCase::ENABLED_SENDER
@ ENABLED_SENDER
Definition
tcp-sack-permitted-test.cc:33
SackPermittedTestCase::SackPermittedTestCase
SackPermittedTestCase(SackPermittedTestCase::Configuration conf)
Constructor.
Definition
tcp-sack-permitted-test.cc:52
SackPermittedTestCase::CreateSenderSocket
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
Definition
tcp-sack-permitted-test.cc:86
SackPermittedTestCase::Tx
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
Definition
tcp-sack-permitted-test.cc:107
SackPermittedTestCase::CreateReceiverSocket
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
Definition
tcp-sack-permitted-test.cc:59
SackPermittedTestCase::m_configuration
Configuration m_configuration
The configuration.
Definition
tcp-sack-permitted-test.cc:49
TcpSackPermittedTestSuite
The test case for testing the TCP SACK PERMITTED option.
Definition
tcp-sack-permitted-test.cc:195
TcpSackPermittedTestSuite::TcpSackPermittedTestSuite
TcpSackPermittedTestSuite()
Constructor.
Definition
tcp-sack-permitted-test.cc:198
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition
boolean.h:26
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TcpGeneralTest
General infrastructure for TCP testing.
Definition
tcp-general-test.h:244
ns3::TcpGeneralTest::CreateSenderSocket
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Definition
tcp-general-test.cc:327
ns3::TcpGeneralTest::SocketWho
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Definition
tcp-general-test.h:262
ns3::TcpGeneralTest::RECEIVER
@ RECEIVER
Receiver node.
Definition
tcp-general-test.h:264
ns3::TcpGeneralTest::SENDER
@ SENDER
Sender node.
Definition
tcp-general-test.h:263
ns3::TcpGeneralTest::CreateReceiverSocket
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Definition
tcp-general-test.cc:333
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition
tcp-header.h:36
ns3::TcpHeader::SYN
@ SYN
SYN.
Definition
tcp-header.h:269
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition
tcp-header.cc:467
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition
tcp-header.cc:137
ns3::TcpOption::SACKPERMITTED
@ SACKPERMITTED
SACKPERMITTED.
Definition
tcp-option.h:51
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
NS_TEST_ASSERT_MSG_EQ
#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
conf
Definition
conf.py:1
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
tcp-general-test.h
g_tcpSackPermittedTestSuite
static TcpSackPermittedTestSuite g_tcpSackPermittedTestSuite
Static variable for test initialization.
Definition
tcp-sack-permitted-test.cc:213
src
internet
test
tcp-sack-permitted-test.cc
Generated on Fri Dec 13 2024 09:20:42 for ns-3 by
1.11.0