A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-prr-recovery-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Viyom Mittal <viyommittal@gmail.com>
7 * Vivek Jain <jain.vivek.anand@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 *
10 */
11
12#include "ns3/log.h"
13#include "ns3/string.h"
14#include "ns3/tcp-congestion-ops.h"
15#include "ns3/tcp-prr-recovery.h"
16#include "ns3/tcp-recovery-ops.h"
17#include "ns3/tcp-socket-base.h"
18#include "ns3/test.h"
19
20using namespace ns3;
21
22NS_LOG_COMPONENT_DEFINE("TcpPrrRecoveryTestSuite");
23
24/**
25 * @brief PRR Recovery algorithm test
26 */
28{
29 public:
30 /**
31 * @brief Constructor.
32 * @param cWnd Congestion window.
33 * @param segmentSize Segment size.
34 * @param ssThresh Slow Start Threshold.
35 * @param unAckDataCount Unacknowledged data at the start of recovery.
36 * @param bytesInFlight Current bytes in flight.
37 * @param m_deliveredBytes Bytes SACKed on last acknowledgment.
38 * @param bytesSent Bytes sent while in recovery phase.
39 * @param name Test description.
40 */
43 uint32_t ssThresh,
44 uint32_t unAckDataCount,
45 uint32_t bytesInFlight,
47 uint32_t bytesSent,
48 const std::string& name);
49
50 private:
51 void DoRun() override;
52
53 uint32_t m_cWnd; //!< Congestion window.
54 uint32_t m_segmentSize; //!< Segment size.
55 uint32_t m_ssThresh; //!< Slow Start Threshold.
56 uint32_t m_unAckDataCount; //!< Unacknowledged data at the start of recovery.
57 uint32_t m_bytesInFlight; //!< Current bytes in flight.
58 uint32_t m_deliveredBytes; //!< Bytes SACKed on last acknowledgment.
59 uint32_t m_bytesSent; //!< Bytes sent while in recovery phase.
60
61 Ptr<TcpSocketState> m_state; //!< TCP socket state.
62};
63
66 uint32_t ssThresh,
67 uint32_t unAckDataCount,
68 uint32_t bytesInFlight,
69 uint32_t deliveredBytes,
70 uint32_t bytesSent,
71 const std::string& name)
72 : TestCase(name),
73 m_cWnd(cWnd),
75 m_ssThresh(ssThresh),
76 m_unAckDataCount(unAckDataCount),
77 m_bytesInFlight(bytesInFlight),
78 m_deliveredBytes(deliveredBytes),
79 m_bytesSent(bytesSent)
80{
81}
82
83void
85{
87
88 m_state->m_cWnd = m_cWnd;
89 m_state->m_cWndInfl = m_cWnd;
90 m_state->m_segmentSize = m_segmentSize;
91 m_state->m_ssThresh = m_ssThresh;
92 m_state->m_bytesInFlight = m_bytesInFlight;
93 // This test drives DoRecovery with deliveredBytes = 0 and relies on PRR's
94 // "+1 SMSS per duplicate ACK" DeliveredData estimate, which (per RFC 9937
95 // Section 6.2) applies only to connections without SACK.
96 m_state->m_sackEnabled = false;
97
99
100 recovery->EnterRecovery(m_state, 3, m_unAckDataCount, 0, 0);
101
104 "There should be at least one transmission on entering recovery");
105
106 for (uint32_t iterator = 0; iterator < m_bytesSent;)
107 {
108 recovery->UpdateBytesSent(m_segmentSize);
109 iterator += m_segmentSize;
110 }
111
112 m_bytesInFlight += m_state->m_cWnd.Get() - m_cWnd;
113 m_state->m_bytesInFlight = m_bytesInFlight;
114 m_cWnd = m_state->m_cWnd.Get();
115 recovery->DoRecovery(m_state, m_deliveredBytes, false);
116
117 if (m_bytesInFlight > m_state->m_ssThresh)
118 {
120 m_state->m_cWnd.Get(),
121 m_cWnd,
122 "Updated cwnd should be less than or equal to the existing cwnd");
123 }
124 else
125 {
127 m_state->m_cWnd.Get(),
128 m_cWnd,
129 "Updated cwnd should be greater than or equal to the existing cwnd");
130 }
131}
132
133/**
134 * @ingroup internet-test
135 *
136 * @brief PRR Recovery regression test for integer overflow and unsigned wrap
137 *
138 * Regression tests for issue #1282. Calls TcpPrrRecovery::DoRecovery directly and
139 * checks the resulting cwnd * against a value computed with correct 64-bit / signed
140 * arithmetic. The two scenarios exercise the arithmetic defects fixed in
141 * tcp-prr-recovery.cc (MR !2807):
142 * - the proportional branch (inflight > ssThresh), where the product
143 * m_prrDelivered * m_ssThresh overflowed a 32-bit integer; and
144 * - the PRR-CRB branch (inflight <= ssThresh), where m_prrDelivered - m_prrOut
145 * wrapped when m_prrOut exceeded m_prrDelivered.
146 */
148{
149 public:
150 /**
151 * @brief Constructor.
152 * @param segmentSize Segment size.
153 * @param ssThresh Slow Start Threshold.
154 * @param bytesInFlight Bytes in flight at recovery entry (also the RecoverFS).
155 * @param bytesSentInRecovery Bytes reported sent (via UpdateBytesSent) before the tested ACK.
156 * @param deliveredBytes Bytes delivered on the tested (non-dupack) acknowledgment.
157 * @param expectedCWnd Expected cwnd after the tested acknowledgment.
158 * @param name Test description.
159 */
161 uint32_t ssThresh,
162 uint32_t bytesInFlight,
163 uint32_t bytesSentInRecovery,
164 uint32_t deliveredBytes,
165 uint32_t expectedCWnd,
166 const std::string& name);
167
168 private:
169 void DoRun() override;
170
171 uint32_t m_segmentSize; //!< Segment size.
172 uint32_t m_ssThresh; //!< Slow Start Threshold.
173 uint32_t m_bytesInFlight; //!< Bytes in flight at recovery entry.
174 uint32_t m_bytesSentInRecovery; //!< Bytes reported sent before the tested ACK.
175 uint32_t m_deliveredBytes; //!< Bytes delivered on the tested ACK.
176 uint32_t m_expectedCWnd; //!< Expected cwnd after the tested ACK.
177};
178
180 uint32_t ssThresh,
181 uint32_t bytesInFlight,
182 uint32_t bytesSentInRecovery,
183 uint32_t deliveredBytes,
184 uint32_t expectedCWnd,
185 const std::string& name)
186 : TestCase(name),
188 m_ssThresh(ssThresh),
189 m_bytesInFlight(bytesInFlight),
190 m_bytesSentInRecovery(bytesSentInRecovery),
191 m_deliveredBytes(deliveredBytes),
192 m_expectedCWnd(expectedCWnd)
193{
194}
195
196void
198{
200 state->m_segmentSize = m_segmentSize;
201 state->m_ssThresh = m_ssThresh;
202 state->m_bytesInFlight = m_bytesInFlight;
203 // These regression scenarios rely on the "+1 SMSS per duplicate ACK"
204 // DeliveredData estimate (the "dupack bump"), which PRR applies only to
205 // connections without SACK (RFC 9937 Section 6.2).
206 state->m_sackEnabled = false;
207
209
210 // EnterRecovery sets RecoverFS = bytesInFlight and performs the first DoRecovery.
211 recovery->EnterRecovery(state, 3, m_bytesInFlight, 0, 0);
212
213 // Report data sent during recovery, advancing m_prrOut one segment at a time.
214 for (uint32_t sent = 0; sent < m_bytesSentInRecovery; sent += m_segmentSize)
215 {
216 recovery->UpdateBytesSent(m_segmentSize);
217 }
218
219 // The acknowledgment under test (not a dupack, so deliveredBytes is used as-is).
220 recovery->DoRecovery(state, m_deliveredBytes, false);
221
222 NS_TEST_ASSERT_MSG_EQ(state->m_cWnd.Get(),
224 "cwnd does not match value computed with correct arithmetic");
225}
226
227/**
228 * @ingroup internet-test
229 *
230 * @brief PRR Recovery TestSuite
231 */
233{
234 public:
236 : TestSuite("tcp-prr-recovery-test", Type::UNIT)
237 {
239 3000,
240 500,
241 2500,
242 3000,
243 3000,
244 500,
245 1000,
246 "Prr test on cWnd when bytesInFlight is greater than ssThresh with SSRB"),
249 1000,
250 500,
251 2500,
252 3000,
253 1000,
254 500,
255 1000,
256 "Prr test on cWnd when bytesInFlight is lower than ssThresh with SSRB"),
259 3000,
260 500,
261 2500,
262 3000,
263 3000,
264 500,
265 1000,
266 "Prr test on cWnd when bytesInFlight is greater than ssThresh with CRB"),
269 1000,
270 500,
271 2500,
272 3000,
273 1000,
274 500,
275 1000,
276 "Prr test on cWnd when bytesInFlight is lower than ssThresh with CRB"),
278
279 // Regression: proportional branch (inflight > ssThresh) must not overflow a
280 // 32-bit intermediate value. EnterRecovery sets RecoverFS = 200000 and (via the
281 // dupack bump) m_prrDelivered = segmentSize = 1000; the tested ACK delivers
282 // 50000 bytes, so m_prrDelivered becomes 51000. Correct arithmetic gives
283 // ceil(51000 * 100000 / 200000) = 25500 and cwnd = 200000 + 25500 = 225500.
284 // Before the fix, 51000 * 100000 = 5.1e9 overflowed the uint32_t product.
286 1000,
287 100000,
288 200000,
289 0,
290 50000,
291 225500,
292 "Prr proportional branch must not overflow 32-bit product"),
294
295 // Regression: PRR-CRB branch (inflight <= ssThresh) must not wrap the unsigned
296 // subtraction m_prrDelivered - m_prrOut. After EnterRecovery m_prrDelivered is
297 // 1000; 50000 bytes are reported sent so m_prrOut is 50000; the tested ACK
298 // delivers 1000 bytes (m_prrDelivered -> 2000). Signed arithmetic gives
299 // max(2000 - 50000, 1000) = 1000 and cwnd = 50000 + 1000 = 51000. Before the
300 // fix, the unsigned subtraction wrapped.
303 100000,
304 50000,
305 50000,
306 1000,
307 51000,
308 "Prr CRB branch must not wrap unsigned subtraction"),
310 }
311};
312
313static PrrRecoveryTestSuite g_TcpPrrRecoveryTest; //!< Static variable for test initialization
PRR Recovery regression test for integer overflow and unsigned wrap.
uint32_t m_segmentSize
Segment size.
PrrRecoveryArithmeticTest(uint32_t segmentSize, uint32_t ssThresh, uint32_t bytesInFlight, uint32_t bytesSentInRecovery, uint32_t deliveredBytes, uint32_t expectedCWnd, const std::string &name)
Constructor.
uint32_t m_expectedCWnd
Expected cwnd after the tested ACK.
uint32_t m_bytesInFlight
Bytes in flight at recovery entry.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_deliveredBytes
Bytes delivered on the tested ACK.
uint32_t m_ssThresh
Slow Start Threshold.
uint32_t m_bytesSentInRecovery
Bytes reported sent before the tested ACK.
PRR Recovery algorithm test.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_bytesInFlight
Current bytes in flight.
uint32_t m_bytesSent
Bytes sent while in recovery phase.
PrrRecoveryTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t unAckDataCount, uint32_t bytesInFlight, uint32_t m_deliveredBytes, uint32_t bytesSent, const std::string &name)
Constructor.
uint32_t m_segmentSize
Segment size.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_ssThresh
Slow Start Threshold.
uint32_t m_deliveredBytes
Bytes SACKed on last acknowledgment.
uint32_t m_cWnd
Congestion window.
uint32_t m_unAckDataCount
Unacknowledged data at the start of recovery.
PRR Recovery TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#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:133
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Definition test.h:739
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition test.h:904
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static PrrRecoveryTestSuite g_TcpPrrRecoveryTest
Static variable for test initialization.