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
* 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
26
using namespace
ns3
;
27
28
NS_LOG_COMPONENT_DEFINE
(
"SackPermittedTestSuite"
);
29
30
/**
31
* \ingroup internet-test
32
*
33
* \brief Test case for checking the SACK-PERMITTED option.
34
*
35
*/
36
class
SackPermittedTestCase
:
public
TcpGeneralTest
37
{
38
public
:
39
/** \brief Configuration of the test */
40
enum
Configuration
41
{
42
DISABLED
,
43
ENABLED_RECEIVER
,
44
ENABLED_SENDER
,
45
ENABLED
46
};
47
48
/**
49
* \brief Constructor
50
* \param conf Test configuration.
51
* */
52
SackPermittedTestCase
(
SackPermittedTestCase::Configuration
conf
);
53
54
protected
:
55
Ptr<TcpSocketMsgBase>
CreateReceiverSocket
(
Ptr<Node>
node)
override
;
56
Ptr<TcpSocketMsgBase>
CreateSenderSocket
(
Ptr<Node>
node)
override
;
57
58
void
Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
& h,
SocketWho
who)
override
;
59
60
Configuration
m_configuration
;
//!< The configuration
61
};
62
63
SackPermittedTestCase::SackPermittedTestCase
(
SackPermittedTestCase::Configuration
conf
)
64
:
TcpGeneralTest
(
"Testing the TCP Sack Permitted option"
)
65
{
66
m_configuration
=
conf
;
67
}
68
69
Ptr<TcpSocketMsgBase>
70
SackPermittedTestCase::CreateReceiverSocket
(
Ptr<Node>
node)
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
96
Ptr<TcpSocketMsgBase>
97
SackPermittedTestCase::CreateSenderSocket
(
Ptr<Node>
node)
98
{
99
Ptr<TcpSocketMsgBase>
socket =
TcpGeneralTest::CreateSenderSocket
(node);
100
101
switch
(
m_configuration
)
102
{
103
case
DISABLED
:
104
case
ENABLED_RECEIVER
:
105
socket->SetAttribute(
"Sack"
,
BooleanValue
(
false
));
106
break
;
107
108
case
ENABLED_SENDER
:
109
case
ENABLED
:
110
socket->SetAttribute(
"Sack"
,
BooleanValue
(
true
));
111
break
;
112
}
113
114
return
socket;
115
}
116
117
void
118
SackPermittedTestCase::Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
& h,
SocketWho
who)
119
{
120
if
(!(h.
GetFlags
() &
TcpHeader::SYN
))
121
{
122
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
123
false
,
124
"SackPermitted in non-SYN segment"
);
125
return
;
126
}
127
128
if
(
m_configuration
==
DISABLED
)
129
{
130
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
131
false
,
132
"SackPermitted disabled but option enabled"
);
133
}
134
else
if
(
m_configuration
==
ENABLED
)
135
{
136
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
137
true
,
138
"SackPermitted enabled but option disabled"
);
139
}
140
141
NS_LOG_INFO
(h);
142
if
(who ==
SENDER
)
143
{
144
if
(h.
GetFlags
() &
TcpHeader::SYN
)
145
{
146
if
(
m_configuration
==
ENABLED_RECEIVER
)
147
{
148
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
149
false
,
150
"SackPermitted disabled but option enabled"
);
151
}
152
else
if
(
m_configuration
==
ENABLED_SENDER
)
153
{
154
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
155
true
,
156
"SackPermitted enabled but option disabled"
);
157
}
158
}
159
else
160
{
161
if
(
m_configuration
!=
ENABLED
)
162
{
163
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
164
false
,
165
"SackPermitted disabled but option enabled"
);
166
}
167
}
168
}
169
else
if
(who ==
RECEIVER
)
170
{
171
if
(h.
GetFlags
() &
TcpHeader::SYN
)
172
{
173
// Sender has not sent SackPermitted, so implementation should disable ts
174
if
(
m_configuration
==
ENABLED_RECEIVER
)
175
{
176
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
177
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
),
183
false
,
184
"receiver has not ts enabled but sent anyway"
);
185
}
186
}
187
else
188
{
189
if
(
m_configuration
!=
ENABLED
)
190
{
191
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::SACKPERMITTED
),
192
false
,
193
"SackPermitted disabled but option enabled"
);
194
}
195
}
196
}
197
}
198
199
/**
200
* \ingroup internet-test
201
* \ingroup tests
202
*
203
* The test case for testing the TCP SACK PERMITTED option.
204
*/
205
class
TcpSackPermittedTestSuite
:
public
TestSuite
206
{
207
public
:
208
/** \brief Constructor */
209
TcpSackPermittedTestSuite
()
210
:
TestSuite
(
"tcp-sack-permitted"
,
Type
::
UNIT
)
211
{
212
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::DISABLED
),
213
TestCase::Duration::QUICK);
214
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED_RECEIVER
),
215
TestCase::Duration::QUICK);
216
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED_SENDER
),
217
TestCase::Duration::QUICK);
218
AddTestCase
(
new
SackPermittedTestCase
(
SackPermittedTestCase::ENABLED
),
219
TestCase::Duration::QUICK);
220
}
221
};
222
223
static
TcpSackPermittedTestSuite
224
g_tcpSackPermittedTestSuite
;
//!< Static variable for test initialization
SackPermittedTestCase
Test case for checking the SACK-PERMITTED option.
Definition:
tcp-sack-permitted-test.cc:37
SackPermittedTestCase::Configuration
Configuration
Configuration of the test.
Definition:
tcp-sack-permitted-test.cc:41
SackPermittedTestCase::ENABLED_RECEIVER
@ ENABLED_RECEIVER
Definition:
tcp-sack-permitted-test.cc:43
SackPermittedTestCase::ENABLED
@ ENABLED
Definition:
tcp-sack-permitted-test.cc:45
SackPermittedTestCase::DISABLED
@ DISABLED
Definition:
tcp-sack-permitted-test.cc:42
SackPermittedTestCase::ENABLED_SENDER
@ ENABLED_SENDER
Definition:
tcp-sack-permitted-test.cc:44
SackPermittedTestCase::SackPermittedTestCase
SackPermittedTestCase(SackPermittedTestCase::Configuration conf)
Constructor.
Definition:
tcp-sack-permitted-test.cc:63
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:97
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:118
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:70
SackPermittedTestCase::m_configuration
Configuration m_configuration
The configuration.
Definition:
tcp-sack-permitted-test.cc:60
TcpSackPermittedTestSuite
The test case for testing the TCP SACK PERMITTED option.
Definition:
tcp-sack-permitted-test.cc:206
TcpSackPermittedTestSuite::TcpSackPermittedTestSuite
TcpSackPermittedTestSuite()
Constructor.
Definition:
tcp-sack-permitted-test.cc:209
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition:
boolean.h:37
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::TcpGeneralTest
General infrastructure for TCP testing.
Definition:
tcp-general-test.h:255
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:338
ns3::TcpGeneralTest::SocketWho
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Definition:
tcp-general-test.h:273
ns3::TcpGeneralTest::RECEIVER
@ RECEIVER
Receiver node.
Definition:
tcp-general-test.h:275
ns3::TcpGeneralTest::SENDER
@ SENDER
Sender node.
Definition:
tcp-general-test.h:274
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:344
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:47
ns3::TcpHeader::SYN
@ SYN
SYN.
Definition:
tcp-header.h:280
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition:
tcp-header.cc:478
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition:
tcp-header.cc:148
ns3::TcpOption::SACKPERMITTED
@ SACKPERMITTED
SACKPERMITTED.
Definition:
tcp-option.h:62
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:302
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1273
ns3::TestSuite::Type
Type
Type of test.
Definition:
test.h:1280
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:202
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:275
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:145
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:224
src
internet
test
tcp-sack-permitted-test.cc
Generated on Tue May 28 2024 23:36:44 for ns-3 by
1.9.6