A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
22using namespace ns3;
23
24NS_LOG_COMPONENT_DEFINE("TcpRxBufferTestSuite");
25
26/**
27 * \ingroup internet-test
28 * \ingroup tests
29 *
30 * \brief The TcpRxBuffer Test
31 */
33{
34 public:
36
37 private:
38 void DoRun() override;
39 void DoTeardown() override;
40
41 /**
42 * \brief Test the SACK list update.
43 */
44 void TestUpdateSACKList();
45};
46
48 : TestCase("TcpRxBuffer Test")
49{
50}
51
52void
54{
56}
57
58void
60{
61 TcpRxBuffer rxBuf;
63 Ptr<Packet> p = Create<Packet>(100);
64 TcpHeader h;
65
66 // In order sequence
69 rxBuf.Add(p, h);
70
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)
78 rxBuf.Add(p, h);
79
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)
91 rxBuf.Add(p, h);
92
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
104 rxBuf.Add(p, h);
105
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
117 rxBuf.Add(p, h);
118
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)
130 rxBuf.Add(p, h);
131
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)
146 rxBuf.Add(p, h);
147
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)
165 rxBuf.Add(p, h);
166
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..
187 rxBuf.Add(p, h);
188
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..
197 rxBuf.Add(p, h);
198
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
217 rxBuf.Add(p, h);
218
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..
237 rxBuf.Add(p, h);
238
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
254 rxBuf.Add(p, h);
255
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
268 rxBuf.Add(p, h);
269
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
282 rxBuf.Add(p, h);
283
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
291void
293{
294}
295
296/**
297 * \ingroup internet-test
298 *
299 * \brief the TestSuite for the TcpRxBuffer test case
300 */
302{
303 public:
305 : TestSuite("tcp-rx-buffer", Type::UNIT)
306 {
307 AddTestCase(new TcpRxBufferTestCase, TestCase::Duration::QUICK);
308 }
309};
310
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.
Definition: ptr.h:77
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition: tcp-header.cc:76
std::list< SackBlock > SackList
SACK list definition.
Rx reordering buffer for TCP.
Definition: tcp-rx-buffer.h:76
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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
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:145
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRxBufferTestSuite g_tcpRxBufferTestSuite