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
33{
34 public:
36
37 private:
38 void DoRun() override;
39 void DoTeardown() override;
40
44 void TestUpdateSACKList();
45};
46
48 : TestCase("TcpRxBuffer Test")
49{
50}
51
52void
54{
56}
57
58void
60{
61 TcpRxBuffer rxBuf;
63 TcpOptionSack::SackList::iterator it;
64 Ptr<Packet> p = Create<Packet>(100);
65 TcpHeader h;
66
67 // In order sequence
70 rxBuf.Add(p, h);
71
74 "Sequence number differs from expected");
75 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 0, "SACK list with an element, while should be empty");
76
77 // Out-of-order sequence (SACK generated)
79 rxBuf.Add(p, h);
80
83 "Sequence number differs from expected");
84 sackList = rxBuf.GetSackList();
85 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
86 it = sackList.begin();
87 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(501), "SACK block different than expected");
88 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(601), "SACK block different than expected");
89
90 // In order sequence, not greater than the previous (the old SACK still in place)
92 rxBuf.Add(p, h);
93
96 "Sequence number differs from expected");
97 sackList = rxBuf.GetSackList();
98 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
99 it = sackList.begin();
100 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(501), "SACK block different than expected");
101 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(601), "SACK block different than expected");
102
103 // Out of order sequence, merge on the right
105 rxBuf.Add(p, h);
106
108 SequenceNumber32(201),
109 "Sequence number differs from expected");
110 sackList = rxBuf.GetSackList();
111 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
112 it = sackList.begin();
113 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(401), "SACK block different than expected");
114 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(601), "SACK block different than expected");
115
116 // Out of order sequence, merge on the left
118 rxBuf.Add(p, h);
119
121 SequenceNumber32(201),
122 "Sequence number differs from expected");
123 sackList = rxBuf.GetSackList();
124 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
125 it = sackList.begin();
126 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(401), "SACK block different than expected");
127 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(701), "SACK block different than expected");
128
129 // out of order sequence, different block, check also the order (newer first)
131 rxBuf.Add(p, h);
132
134 SequenceNumber32(201),
135 "Sequence number differs from expected");
136 sackList = rxBuf.GetSackList();
137 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 2, "SACK list should contain two element");
138 it = sackList.begin();
139 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(901), "SACK block different than expected");
140 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1001), "SACK block different than expected");
141 ++it;
142 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(401), "SACK block different than expected");
143 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(701), "SACK block different than expected");
144
145 // another out of order seq, different block, check the order (newer first)
147 rxBuf.Add(p, h);
148
150 SequenceNumber32(201),
151 "Sequence number differs from expected");
152 sackList = rxBuf.GetSackList();
153 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 3, "SACK list should contain three element");
154 it = sackList.begin();
155 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
156 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1301), "SACK block different than expected");
157 ++it;
158 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(901), "SACK block different than expected");
159 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1001), "SACK block different than expected");
160 ++it;
161 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(401), "SACK block different than expected");
162 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(701), "SACK block different than expected");
163
164 // another out of order seq, different block, check the order (newer first)
166 rxBuf.Add(p, h);
167
169 SequenceNumber32(201),
170 "Sequence number differs from expected");
171 sackList = rxBuf.GetSackList();
172 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 4, "SACK list should contain four element");
173 it = sackList.begin();
174 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1401), "SACK block different than expected");
175 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
176 ++it;
177 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
178 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1301), "SACK block different than expected");
179 ++it;
180 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(901), "SACK block different than expected");
181 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1001), "SACK block different than expected");
182 ++it;
183 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(401), "SACK block different than expected");
184 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(701), "SACK block different than expected");
185
186 // in order block! See if something get stripped off..
188 rxBuf.Add(p, h);
189
191 SequenceNumber32(301),
192 "Sequence number differs from expected");
193 sackList = rxBuf.GetSackList();
194 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 4, "SACK list should contain four element");
195
196 // in order block! See if something get stripped off..
198 rxBuf.Add(p, h);
199
201 SequenceNumber32(701),
202 "Sequence number differs from expected");
203 sackList = rxBuf.GetSackList();
204 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 3, "SACK list should contain three element");
205
206 it = sackList.begin();
207 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1401), "SACK block different than expected");
208 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
209 ++it;
210 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
211 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1301), "SACK block different than expected");
212 ++it;
213 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(901), "SACK block different than expected");
214 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1001), "SACK block different than expected");
215
216 // out of order block, I'm expecting a left-merge with a move on the top
218 rxBuf.Add(p, h);
219
221 SequenceNumber32(701),
222 "Sequence number differs from expected");
223 sackList = rxBuf.GetSackList();
224 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 3, "SACK list should contain three element");
225
226 it = sackList.begin();
227 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(801), "SACK block different than expected");
228 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1001), "SACK block different than expected");
229 ++it;
230 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1401), "SACK block different than expected");
231 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
232 ++it;
233 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
234 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1301), "SACK block different than expected");
235
236 // In order block! Strip things away..
238 rxBuf.Add(p, h);
239
241 SequenceNumber32(1001),
242 "Sequence number differs from expected");
243 sackList = rxBuf.GetSackList();
244 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 2, "SACK list should contain two element");
245
246 it = sackList.begin();
247 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1401), "SACK block different than expected");
248 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
249 ++it;
250 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
251 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1301), "SACK block different than expected");
252
253 // out of order... I'm expecting a right-merge with a move on top
255 rxBuf.Add(p, h);
256
258 SequenceNumber32(1001),
259 "Sequence number differs from expected");
260 sackList = rxBuf.GetSackList();
261 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
262
263 it = sackList.begin();
264 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
265 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
266
267 // In order
269 rxBuf.Add(p, h);
270
272 SequenceNumber32(1101),
273 "Sequence number differs from expected");
274 sackList = rxBuf.GetSackList();
275 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 1, "SACK list should contain one element");
276
277 it = sackList.begin();
278 NS_TEST_ASSERT_MSG_EQ(it->first, SequenceNumber32(1201), "SACK block different than expected");
279 NS_TEST_ASSERT_MSG_EQ(it->second, SequenceNumber32(1501), "SACK block different than expected");
280
281 // In order, empty the list
283 rxBuf.Add(p, h);
284
286 SequenceNumber32(1501),
287 "Sequence number differs from expected");
288 sackList = rxBuf.GetSackList();
289 NS_TEST_ASSERT_MSG_EQ(sackList.size(), 0, "SACK list should contain no element");
290}
291
292void
294{
295}
296
303{
304 public:
306 : TestSuite("tcp-rx-buffer", UNIT)
307 {
309 }
310};
311
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:78
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition: tcp-header.cc:95
std::list< SackBlock > SackList
SACK list definition.
Rx reordering buffer for TCP.
Definition: tcp-rx-buffer.h:75
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:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
#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:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRxBufferTestSuite g_tcpRxBufferTestSuite