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