A Discrete-Event Network Simulator
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
11using namespace ns3;
12
13NS_LOG_COMPONENT_DEFINE("TcpRxBufferTestSuite");
14
15/**
16 * @ingroup internet-test
17 * @ingroup tests
18 *
19 * @brief The TcpRxBuffer Test
20 */
22{
23 public:
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
37 : TestCase("TcpRxBuffer Test")
38{
39}
40
41void
46
47void
49{
50 TcpRxBuffer rxBuf;
53 TcpHeader h;
54
55 // In order sequence
58 rxBuf.Add(p, h);
59
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)
67 rxBuf.Add(p, h);
68
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)
80 rxBuf.Add(p, h);
81
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
93 rxBuf.Add(p, h);
94
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
106 rxBuf.Add(p, h);
107
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)
119 rxBuf.Add(p, h);
120
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)
135 rxBuf.Add(p, h);
136
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)
154 rxBuf.Add(p, h);
155
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..
176 rxBuf.Add(p, h);
177
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..
186 rxBuf.Add(p, h);
187
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
206 rxBuf.Add(p, h);
207
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..
226 rxBuf.Add(p, h);
227
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
243 rxBuf.Add(p, h);
244
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
257 rxBuf.Add(p, h);
258
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
271 rxBuf.Add(p, h);
272
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
280void
284
285/**
286 * @ingroup internet-test
287 *
288 * @brief the TestSuite for the TcpRxBuffer test case
289 */
291{
292 public:
294 : TestSuite("tcp-rx-buffer", Type::UNIT)
295 {
296 AddTestCase(new TcpRxBufferTestCase, TestCase::Duration::QUICK);
297 }
298};
299
The TcpRxBuffer Test.
void TestUpdateSACKList()
Test the SACK list update.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
the TestSuite for the TcpRxBuffer test case
Smart pointer class similar to boost::intrusive_ptr.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition tcp-header.cc:65
std::list< SackBlock > SackList
SACK list definition.
Rx reordering buffer for TCP.
SequenceNumber32 NextRxSequence() const
Get Next Rx Sequence number.
void SetNextRxSequence(const SequenceNumber32 &s)
Set the Next Sequence number.
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...
TcpOptionSack::SackList GetSackList() const
Get the sack list.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRxBufferTestSuite g_tcpRxBufferTestSuite