A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
tcp-rx-buffer-test.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
*/
16
17
#include "ns3/log.h"
18
#include "ns3/packet.h"
19
#include "ns3/tcp-rx-buffer.h"
20
#include "ns3/test.h"
21
22
using namespace
ns3
;
23
24
NS_LOG_COMPONENT_DEFINE
(
"TcpRxBufferTestSuite"
);
25
32
class
TcpRxBufferTestCase
:
public
TestCase
33
{
34
public
:
35
TcpRxBufferTestCase
();
36
37
private
:
38
void
DoRun()
override
;
39
void
DoTeardown()
override
;
40
44
void
TestUpdateSACKList();
45
};
46
47
TcpRxBufferTestCase::TcpRxBufferTestCase
()
48
:
TestCase
(
"TcpRxBuffer Test"
)
49
{
50
}
51
52
void
53
TcpRxBufferTestCase::DoRun
()
54
{
55
TestUpdateSACKList
();
56
}
57
58
void
59
TcpRxBufferTestCase::TestUpdateSACKList
()
60
{
61
TcpRxBuffer
rxBuf;
62
TcpOptionSack::SackList
sackList;
63
Ptr<Packet>
p = Create<Packet>(100);
64
TcpHeader
h;
65
66
// In order sequence
67
h.
SetSequenceNumber
(
SequenceNumber32
(1));
68
rxBuf.
SetNextRxSequence
(
SequenceNumber32
(1));
69
rxBuf.
Add
(p, h);
70
71
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
72
SequenceNumber32
(101),
73
"Sequence number differs from expected"
);
74
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 0,
"SACK list with an element, while should be empty"
);
75
76
// Out-of-order sequence (SACK generated)
77
h.
SetSequenceNumber
(
SequenceNumber32
(501));
78
rxBuf.
Add
(p, h);
79
80
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
81
SequenceNumber32
(101),
82
"Sequence number differs from expected"
);
83
sackList = rxBuf.
GetSackList
();
84
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
85
auto
it = sackList.begin();
86
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(501),
"SACK block different than expected"
);
87
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
88
89
// In order sequence, not greater than the previous (the old SACK still in place)
90
h.
SetSequenceNumber
(
SequenceNumber32
(101));
91
rxBuf.
Add
(p, h);
92
93
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
94
SequenceNumber32
(201),
95
"Sequence number differs from expected"
);
96
sackList = rxBuf.
GetSackList
();
97
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
98
it = sackList.begin();
99
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(501),
"SACK block different than expected"
);
100
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
101
102
// Out of order sequence, merge on the right
103
h.
SetSequenceNumber
(
SequenceNumber32
(401));
104
rxBuf.
Add
(p, h);
105
106
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
107
SequenceNumber32
(201),
108
"Sequence number differs from expected"
);
109
sackList = rxBuf.
GetSackList
();
110
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
111
it = sackList.begin();
112
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
113
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(601),
"SACK block different than expected"
);
114
115
// Out of order sequence, merge on the left
116
h.
SetSequenceNumber
(
SequenceNumber32
(601));
117
rxBuf.
Add
(p, h);
118
119
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
120
SequenceNumber32
(201),
121
"Sequence number differs from expected"
);
122
sackList = rxBuf.
GetSackList
();
123
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
124
it = sackList.begin();
125
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
126
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
127
128
// out of order sequence, different block, check also the order (newer first)
129
h.
SetSequenceNumber
(
SequenceNumber32
(901));
130
rxBuf.
Add
(p, h);
131
132
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
133
SequenceNumber32
(201),
134
"Sequence number differs from expected"
);
135
sackList = rxBuf.
GetSackList
();
136
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 2,
"SACK list should contain two element"
);
137
it = sackList.begin();
138
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
139
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
140
++it;
141
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
142
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
143
144
// another out of order seq, different block, check the order (newer first)
145
h.
SetSequenceNumber
(
SequenceNumber32
(1201));
146
rxBuf.
Add
(p, h);
147
148
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
149
SequenceNumber32
(201),
150
"Sequence number differs from expected"
);
151
sackList = rxBuf.
GetSackList
();
152
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
153
it = sackList.begin();
154
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
155
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
156
++it;
157
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
158
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
159
++it;
160
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
161
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
162
163
// another out of order seq, different block, check the order (newer first)
164
h.
SetSequenceNumber
(
SequenceNumber32
(1401));
165
rxBuf.
Add
(p, h);
166
167
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
168
SequenceNumber32
(201),
169
"Sequence number differs from expected"
);
170
sackList = rxBuf.
GetSackList
();
171
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 4,
"SACK list should contain four element"
);
172
it = sackList.begin();
173
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
174
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
175
++it;
176
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
177
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
178
++it;
179
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
180
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
181
++it;
182
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(401),
"SACK block different than expected"
);
183
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(701),
"SACK block different than expected"
);
184
185
// in order block! See if something get stripped off..
186
h.
SetSequenceNumber
(
SequenceNumber32
(201));
187
rxBuf.
Add
(p, h);
188
189
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
190
SequenceNumber32
(301),
191
"Sequence number differs from expected"
);
192
sackList = rxBuf.
GetSackList
();
193
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 4,
"SACK list should contain four element"
);
194
195
// in order block! See if something get stripped off..
196
h.
SetSequenceNumber
(
SequenceNumber32
(301));
197
rxBuf.
Add
(p, h);
198
199
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
200
SequenceNumber32
(701),
201
"Sequence number differs from expected"
);
202
sackList = rxBuf.
GetSackList
();
203
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
204
205
it = sackList.begin();
206
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
207
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
208
++it;
209
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
210
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
211
++it;
212
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(901),
"SACK block different than expected"
);
213
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
214
215
// out of order block, I'm expecting a left-merge with a move on the top
216
h.
SetSequenceNumber
(
SequenceNumber32
(801));
217
rxBuf.
Add
(p, h);
218
219
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
220
SequenceNumber32
(701),
221
"Sequence number differs from expected"
);
222
sackList = rxBuf.
GetSackList
();
223
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 3,
"SACK list should contain three element"
);
224
225
it = sackList.begin();
226
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(801),
"SACK block different than expected"
);
227
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1001),
"SACK block different than expected"
);
228
++it;
229
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
230
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
231
++it;
232
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
233
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
234
235
// In order block! Strip things away..
236
h.
SetSequenceNumber
(
SequenceNumber32
(701));
237
rxBuf.
Add
(p, h);
238
239
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
240
SequenceNumber32
(1001),
241
"Sequence number differs from expected"
);
242
sackList = rxBuf.
GetSackList
();
243
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 2,
"SACK list should contain two element"
);
244
245
it = sackList.begin();
246
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1401),
"SACK block different than expected"
);
247
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
248
++it;
249
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
250
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1301),
"SACK block different than expected"
);
251
252
// out of order... I'm expecting a right-merge with a move on top
253
h.
SetSequenceNumber
(
SequenceNumber32
(1301));
254
rxBuf.
Add
(p, h);
255
256
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
257
SequenceNumber32
(1001),
258
"Sequence number differs from expected"
);
259
sackList = rxBuf.
GetSackList
();
260
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
261
262
it = sackList.begin();
263
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
264
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
265
266
// In order
267
h.
SetSequenceNumber
(
SequenceNumber32
(1001));
268
rxBuf.
Add
(p, h);
269
270
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
271
SequenceNumber32
(1101),
272
"Sequence number differs from expected"
);
273
sackList = rxBuf.
GetSackList
();
274
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 1,
"SACK list should contain one element"
);
275
276
it = sackList.begin();
277
NS_TEST_ASSERT_MSG_EQ
(it->first,
SequenceNumber32
(1201),
"SACK block different than expected"
);
278
NS_TEST_ASSERT_MSG_EQ
(it->second,
SequenceNumber32
(1501),
"SACK block different than expected"
);
279
280
// In order, empty the list
281
h.
SetSequenceNumber
(
SequenceNumber32
(1101));
282
rxBuf.
Add
(p, h);
283
284
NS_TEST_ASSERT_MSG_EQ
(rxBuf.
NextRxSequence
(),
285
SequenceNumber32
(1501),
286
"Sequence number differs from expected"
);
287
sackList = rxBuf.
GetSackList
();
288
NS_TEST_ASSERT_MSG_EQ
(sackList.size(), 0,
"SACK list should contain no element"
);
289
}
290
291
void
292
TcpRxBufferTestCase::DoTeardown
()
293
{
294
}
295
301
class
TcpRxBufferTestSuite
:
public
TestSuite
302
{
303
public
:
304
TcpRxBufferTestSuite
()
305
:
TestSuite
(
"tcp-rx-buffer"
,
UNIT
)
306
{
307
AddTestCase
(
new
TcpRxBufferTestCase
, TestCase::QUICK);
308
}
309
};
310
311
static
TcpRxBufferTestSuite
g_tcpRxBufferTestSuite
;
TcpRxBufferTestCase
The TcpRxBuffer Test.
Definition:
tcp-rx-buffer-test.cc:33
TcpRxBufferTestCase::TestUpdateSACKList
void TestUpdateSACKList()
Test the SACK list update.
Definition:
tcp-rx-buffer-test.cc:59
TcpRxBufferTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
tcp-rx-buffer-test.cc:53
TcpRxBufferTestCase::DoTeardown
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition:
tcp-rx-buffer-test.cc:292
TcpRxBufferTestCase::TcpRxBufferTestCase
TcpRxBufferTestCase()
Definition:
tcp-rx-buffer-test.cc:47
TcpRxBufferTestSuite
the TestSuite for the TcpRxBuffer test case
Definition:
tcp-rx-buffer-test.cc:302
TcpRxBufferTestSuite::TcpRxBufferTestSuite
TcpRxBufferTestSuite()
Definition:
tcp-rx-buffer-test.cc:304
ns3::Ptr< Packet >
ns3::SequenceNumber< uint32_t, int32_t >
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:47
ns3::TcpHeader::SetSequenceNumber
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition:
tcp-header.cc:76
ns3::TcpOptionSack::SackList
std::list< SackBlock > SackList
SACK list definition.
Definition:
tcp-option-sack.h:61
ns3::TcpRxBuffer
Rx reordering buffer for TCP.
Definition:
tcp-rx-buffer.h:76
ns3::TcpRxBuffer::NextRxSequence
SequenceNumber32 NextRxSequence() const
Get Next Rx Sequence number.
Definition:
tcp-rx-buffer.cc:67
ns3::TcpRxBuffer::SetNextRxSequence
void SetNextRxSequence(const SequenceNumber32 &s)
Set the Next Sequence number.
Definition:
tcp-rx-buffer.cc:73
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:147
ns3::TcpRxBuffer::GetSackList
TcpOptionSack::SackList GetSackList() const
Get the sack list.
Definition:
tcp-rx-buffer.cc:373
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1265
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::SequenceNumber32
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
Definition:
sequence-number.h:426
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:144
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:311
src
internet
test
tcp-rx-buffer-test.cc
Generated on Sun Mar 3 2024 17:11:00 for ns-3 by
1.9.1