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-rx-buffer-test.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
*/
5
6
#include "ns3/log.h"
7
#include "ns3/packet.h"
8
#include "ns3/tcp-rx-buffer.h"
9
#include "ns3/test.h"
10
11
using namespace
ns3
;
12
13
NS_LOG_COMPONENT_DEFINE
(
"TcpRxBufferTestSuite"
);
14
15
/**
16
* \ingroup internet-test
17
* \ingroup tests
18
*
19
* \brief The TcpRxBuffer Test
20
*/
21
class
TcpRxBufferTestCase
:
public
TestCase
22
{
23
public
:
24
TcpRxBufferTestCase
();
25
26
private
:
27
void
DoRun
()
override
;
28
void
DoTeardown
()
override
;
29
30
/**
31
* \brief Test the SACK list update.
32
*/
33
void
TestUpdateSACKList
();
34
};
35
36
TcpRxBufferTestCase::TcpRxBufferTestCase
()
37
:
TestCase
(
"TcpRxBuffer Test"
)
38
{
39
}
40
41
void
42
TcpRxBufferTestCase::DoRun
()
43
{
44
TestUpdateSACKList
();
45
}
46
47
void
48
TcpRxBufferTestCase::TestUpdateSACKList
()
49
{
50
TcpRxBuffer
rxBuf;
51
TcpOptionSack::SackList
sackList;
52
Ptr<Packet>
p =
Create<Packet>
(100);
53
TcpHeader
h;
54
55
// In order sequence
56
h.
SetSequenceNumber
(
SequenceNumber32
(1));
57
rxBuf.
SetNextRxSequence
(
SequenceNumber32
(1));
58
rxBuf.
Add
(p, h);
59
60
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
61
SequenceNumber32
(101),
62
"Sequence number differs from expected"
);
63
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 0,
"SACK list with an element, while should be empty"
);
64
65
// Out-of-order sequence (SACK generated)
66
h.
SetSequenceNumber
(
SequenceNumber32
(501));
67
rxBuf.
Add
(p, h);
68
69
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
70
SequenceNumber32
(101),
71
"Sequence number differs from expected"
);
72
sackList = rxBuf.
GetSackList
();
73
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
74
auto
it = sackList.begin();
75
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(501),
"SACK block different than expected"
);
76
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
77
78
// In order sequence, not greater than the previous (the old SACK still in place)
79
h.
SetSequenceNumber
(
SequenceNumber32
(101));
80
rxBuf.
Add
(p, h);
81
82
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
83
SequenceNumber32
(201),
84
"Sequence number differs from expected"
);
85
sackList = rxBuf.
GetSackList
();
86
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
87
it = sackList.begin();
88
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(501),
"SACK block different than expected"
);
89
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
90
91
// Out of order sequence, merge on the right
92
h.
SetSequenceNumber
(
SequenceNumber32
(401));
93
rxBuf.
Add
(p, h);
94
95
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
96
SequenceNumber32
(201),
97
"Sequence number differs from expected"
);
98
sackList = rxBuf.
GetSackList
();
99
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
100
it = sackList.begin();
101
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
102
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
103
104
// Out of order sequence, merge on the left
105
h.
SetSequenceNumber
(
SequenceNumber32
(601));
106
rxBuf.
Add
(p, h);
107
108
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
109
SequenceNumber32
(201),
110
"Sequence number differs from expected"
);
111
sackList = rxBuf.
GetSackList
();
112
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
113
it = sackList.begin();
114
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
115
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
116
117
// out of order sequence, different block, check also the order (newer first)
118
h.
SetSequenceNumber
(
SequenceNumber32
(901));
119
rxBuf.
Add
(p, h);
120
121
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
122
SequenceNumber32
(201),
123
"Sequence number differs from expected"
);
124
sackList = rxBuf.
GetSackList
();
125
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 2,
"SACK list should contain two element"
);
126
it = sackList.begin();
127
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
128
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
129
++it;
130
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
131
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
132
133
// another out of order seq, different block, check the order (newer first)
134
h.
SetSequenceNumber
(
SequenceNumber32
(1201));
135
rxBuf.
Add
(p, h);
136
137
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
138
SequenceNumber32
(201),
139
"Sequence number differs from expected"
);
140
sackList = rxBuf.
GetSackList
();
141
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
142
it = sackList.begin();
143
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
144
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
145
++it;
146
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
147
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
148
++it;
149
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
150
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
151
152
// another out of order seq, different block, check the order (newer first)
153
h.
SetSequenceNumber
(
SequenceNumber32
(1401));
154
rxBuf.
Add
(p, h);
155
156
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
157
SequenceNumber32
(201),
158
"Sequence number differs from expected"
);
159
sackList = rxBuf.
GetSackList
();
160
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 4,
"SACK list should contain four element"
);
161
it = sackList.begin();
162
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
163
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
164
++it;
165
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
166
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
167
++it;
168
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
169
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
170
++it;
171
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
172
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
173
174
// in order block! See if something get stripped off..
175
h.
SetSequenceNumber
(
SequenceNumber32
(201));
176
rxBuf.
Add
(p, h);
177
178
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
179
SequenceNumber32
(301),
180
"Sequence number differs from expected"
);
181
sackList = rxBuf.
GetSackList
();
182
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 4,
"SACK list should contain four element"
);
183
184
// in order block! See if something get stripped off..
185
h.
SetSequenceNumber
(
SequenceNumber32
(301));
186
rxBuf.
Add
(p, h);
187
188
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
189
SequenceNumber32
(701),
190
"Sequence number differs from expected"
);
191
sackList = rxBuf.
GetSackList
();
192
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
193
194
it = sackList.begin();
195
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
196
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
197
++it;
198
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
199
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
200
++it;
201
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
202
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
203
204
// out of order block, I'm expecting a left-merge with a move on the top
205
h.
SetSequenceNumber
(
SequenceNumber32
(801));
206
rxBuf.
Add
(p, h);
207
208
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
209
SequenceNumber32
(701),
210
"Sequence number differs from expected"
);
211
sackList = rxBuf.
GetSackList
();
212
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
213
214
it = sackList.begin();
215
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(801),
"SACK block different than expected"
);
216
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
217
++it;
218
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
219
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
220
++it;
221
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
222
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
223
224
// In order block! Strip things away..
225
h.
SetSequenceNumber
(
SequenceNumber32
(701));
226
rxBuf.
Add
(p, h);
227
228
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
229
SequenceNumber32
(1001),
230
"Sequence number differs from expected"
);
231
sackList = rxBuf.
GetSackList
();
232
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 2,
"SACK list should contain two element"
);
233
234
it = sackList.begin();
235
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
236
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
237
++it;
238
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
239
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
240
241
// out of order... I'm expecting a right-merge with a move on top
242
h.
SetSequenceNumber
(
SequenceNumber32
(1301));
243
rxBuf.
Add
(p, h);
244
245
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
246
SequenceNumber32
(1001),
247
"Sequence number differs from expected"
);
248
sackList = rxBuf.
GetSackList
();
249
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
250
251
it = sackList.begin();
252
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
253
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
254
255
// In order
256
h.
SetSequenceNumber
(
SequenceNumber32
(1001));
257
rxBuf.
Add
(p, h);
258
259
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
260
SequenceNumber32
(1101),
261
"Sequence number differs from expected"
);
262
sackList = rxBuf.
GetSackList
();
263
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
264
265
it = sackList.begin();
266
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
267
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
268
269
// In order, empty the list
270
h.
SetSequenceNumber
(
SequenceNumber32
(1101));
271
rxBuf.
Add
(p, h);
272
273
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
274
SequenceNumber32
(1501),
275
"Sequence number differs from expected"
);
276
sackList = rxBuf.
GetSackList
();
277
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 0,
"SACK list should contain no element"
);
278
}
279
280
void
281
TcpRxBufferTestCase::DoTeardown
()
282
{
283
}
284
285
/**
286
* \ingroup internet-test
287
*
288
* \brief the TestSuite for the TcpRxBuffer test case
289
*/
290
class
TcpRxBufferTestSuite
:
public
TestSuite
291
{
292
public
:
293
TcpRxBufferTestSuite
()
294
:
TestSuite
(
"tcp-rx-buffer"
,
Type
::
UNIT
)
295
{
296
AddTestCase
(
new
TcpRxBufferTestCase
, TestCase::Duration::QUICK);
297
}
298
};
299
300
static
TcpRxBufferTestSuite
g_tcpRxBufferTestSuite
;
TcpRxBufferTestCase
The TcpRxBuffer Test.
Definition
tcp-rx-buffer-test.cc:22
TcpRxBufferTestCase::TestUpdateSACKList
void TestUpdateSACKList()
Test the SACK list update.
Definition
tcp-rx-buffer-test.cc:48
TcpRxBufferTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-rx-buffer-test.cc:42
TcpRxBufferTestCase::DoTeardown
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition
tcp-rx-buffer-test.cc:281
TcpRxBufferTestCase::TcpRxBufferTestCase
TcpRxBufferTestCase()
Definition
tcp-rx-buffer-test.cc:36
TcpRxBufferTestSuite
the TestSuite for the TcpRxBuffer test case
Definition
tcp-rx-buffer-test.cc:291
TcpRxBufferTestSuite::TcpRxBufferTestSuite
TcpRxBufferTestSuite()
Definition
tcp-rx-buffer-test.cc:293
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::SequenceNumber< uint32_t, int32_t >
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition
tcp-header.h:36
ns3::TcpHeader::SetSequenceNumber
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition
tcp-header.cc:65
ns3::TcpOptionSack::SackList
std::list< SackBlock > SackList
SACK list definition.
Definition
tcp-option-sack.h:50
ns3::TcpRxBuffer
Rx reordering buffer for TCP.
Definition
tcp-rx-buffer.h:65
ns3::TcpRxBuffer::NextRxSequence
SequenceNumber32 NextRxSequence() const
Get Next Rx Sequence number.
Definition
tcp-rx-buffer.cc:56
ns3::TcpRxBuffer::SetNextRxSequence
void SetNextRxSequence(const SequenceNumber32 &s)
Set the Next Sequence number.
Definition
tcp-rx-buffer.cc:62
ns3::TcpRxBuffer::Add
bool Add(Ptr< Packet > p, const TcpHeader &tcph)
Insert a packet into the buffer and update the availBytes counter to reflect the number of bytes read...
Definition
tcp-rx-buffer.cc:136
ns3::TcpRxBuffer::GetSackList
TcpOptionSack::SackList GetSackList() const
Get the sack list.
Definition
tcp-rx-buffer.cc:362
ns3::TestCase
encapsulates test code
Definition
test.h:1050
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
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::SequenceNumber32
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
Definition
sequence-number.h:415
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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
g_tcpRxBufferTestSuite
static TcpRxBufferTestSuite g_tcpRxBufferTestSuite
Definition
tcp-rx-buffer-test.cc:300
src
internet
test
tcp-rx-buffer-test.cc
Generated on Fri Nov 8 2024 13:59:02 for ns-3 by
1.11.0