A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-ledbat-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Ankit Deepak <adadeepak8@gmail.com>
7 *
8 */
9
10#include "ns3/log.h"
11#include "ns3/string.h"
12#include "ns3/tcp-congestion-ops.h"
13#include "ns3/tcp-ledbat.h"
14#include "ns3/tcp-socket-base.h"
15#include "ns3/test.h"
16
17using namespace ns3;
18
19NS_LOG_COMPONENT_DEFINE("TcpLedbatTestSuite");
20
21/**
22 * \ingroup internet-test
23 *
24 * \brief LEDBAT should be same as NewReno during slow start, and when timestamps are disabled
25 */
27{
28 public:
29 /**
30 * \brief Constructor
31 *
32 * \param cWnd congestion window
33 * \param segmentSize segment size
34 * \param ssThresh slow start threshold
35 * \param segmentsAcked segments acked
36 * \param highTxMark high tx mark
37 * \param lastAckedSeq last acked seq
38 * \param rtt RTT
39 * \param name Name of the test
40 */
43 uint32_t ssThresh,
44 uint32_t segmentsAcked,
45 SequenceNumber32 highTxMark,
46 SequenceNumber32 lastAckedSeq,
47 Time rtt,
48 const std::string& name);
49
50 private:
51 void DoRun() override;
52 /**
53 * \brief Execute the test
54 */
55 void ExecuteTest();
56
57 uint32_t m_cWnd; //!< cWnd
58 uint32_t m_segmentSize; //!< segment size
59 uint32_t m_segmentsAcked; //!< segments acked
60 uint32_t m_ssThresh; //!< ss thresh
61 Time m_rtt; //!< rtt
62 SequenceNumber32 m_highTxMark; //!< high tx mark
63 SequenceNumber32 m_lastAckedSeq; //!< last acked seq
65};
66
69 uint32_t ssThresh,
70 uint32_t segmentsAcked,
71 SequenceNumber32 highTxMark,
72 SequenceNumber32 lastAckedSeq,
73 Time rtt,
74 const std::string& name)
75 : TestCase(name),
76 m_cWnd(cWnd),
77 m_segmentSize(segmentSize),
78 m_segmentsAcked(segmentsAcked),
79 m_ssThresh(ssThresh),
80 m_rtt(rtt),
81 m_highTxMark(highTxMark),
82 m_lastAckedSeq(lastAckedSeq)
83{
84}
85
86void
93
94void
96{
98 m_state->m_cWnd = m_cWnd;
99 m_state->m_ssThresh = m_ssThresh;
100 m_state->m_segmentSize = m_segmentSize;
101 m_state->m_highTxMark = m_highTxMark;
102 m_state->m_lastAckedSeq = m_lastAckedSeq;
103
105 state->m_cWnd = m_cWnd;
106 state->m_ssThresh = m_ssThresh;
107 state->m_segmentSize = m_segmentSize;
108 state->m_highTxMark = m_highTxMark;
109 state->m_lastAckedSeq = m_lastAckedSeq;
110
112 cong->IncreaseWindow(m_state, m_segmentsAcked);
113
115 NewRenoCong->IncreaseWindow(state, m_segmentsAcked);
116
117 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(),
118 state->m_cWnd.Get(),
119 "cWnd has not updated correctly");
120}
121
122/**
123 * \ingroup internet-test
124 *
125 * \brief Test to validate cWnd increment in LEDBAT
126 */
128{
129 public:
130 /**
131 * \brief Constructor
132 *
133 * \param cWnd congestion window
134 * \param segmentSize segment size
135 * \param ssThresh slow start threshold
136 * \param segmentsAcked segments acked
137 * \param highTxMark high tx mark
138 * \param lastAckedSeq last acked seq
139 * \param rtt RTT
140 * \param name Name of the test
141 */
144 uint32_t ssThresh,
145 uint32_t segmentsAcked,
146 SequenceNumber32 highTxMark,
147 SequenceNumber32 lastAckedSeq,
148 Time rtt,
149 const std::string& name);
150
151 private:
152 void DoRun() override;
153 /**
154 * \brief Execute the test
155 */
156 void ExecuteTest();
157
158 uint32_t m_cWnd; //!< cWnd
159 uint32_t m_segmentSize; //!< segment size
160 uint32_t m_segmentsAcked; //!< segments acked
161 uint32_t m_ssThresh; //!< ss thresh
162 Time m_rtt; //!< rtt
164 SequenceNumber32 m_lastAckedSeq; //!< last acked seq
166};
167
170 uint32_t ssThresh,
171 uint32_t segmentsAcked,
172 SequenceNumber32 highTxMark,
173 SequenceNumber32 lastAckedSeq,
174 Time rtt,
175 const std::string& name)
176 : TestCase(name),
177 m_cWnd(cWnd),
178 m_segmentSize(segmentSize),
179 m_segmentsAcked(segmentsAcked),
180 m_ssThresh(ssThresh),
181 m_rtt(rtt),
182 m_highTxMark(highTxMark),
183 m_lastAckedSeq(lastAckedSeq)
184{
185}
186
187void
194
195void
197{
199 m_state->m_cWnd = m_cWnd;
200 m_state->m_ssThresh = m_ssThresh;
201 m_state->m_segmentSize = m_segmentSize;
202 m_state->m_highTxMark = m_highTxMark;
203 m_state->m_lastAckedSeq = m_lastAckedSeq;
204
206 cong->SetAttribute("SSParam", StringValue("no"));
207 cong->SetAttribute("NoiseFilterLen", UintegerValue(1));
208
209 m_state->m_rcvTimestampValue = 2;
210 m_state->m_rcvTimestampEchoReply = 1;
211 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
212
213 m_state->m_rcvTimestampValue = 7;
214 m_state->m_rcvTimestampEchoReply = 4;
215 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
216
217 cong->IncreaseWindow(m_state, m_segmentsAcked);
218
220
221 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
222}
223
224/**
225 * \ingroup internet-test
226 *
227 * \brief Test to validate cWnd decrement in LEDBAT
228 */
230{
231 public:
232 /**
233 * \brief Constructor
234 *
235 * \param cWnd congestion window
236 * \param segmentSize segment size
237 * \param ssThresh slow start threshold
238 * \param segmentsAcked segments acked
239 * \param highTxMark high tx mark
240 * \param lastAckedSeq last acked seq
241 * \param rtt RTT
242 * \param name Name of the test
243 */
246 uint32_t ssThresh,
247 uint32_t segmentsAcked,
248 SequenceNumber32 highTxMark,
249 SequenceNumber32 lastAckedSeq,
250 Time rtt,
251 const std::string& name);
252
253 private:
254 void DoRun() override;
255 /**
256 * \brief Execute the test
257 */
258 void ExecuteTest();
259
260 uint32_t m_cWnd; //!< cWnd
261 uint32_t m_segmentSize; //!< segment size
262 uint32_t m_segmentsAcked; //!< segments acked
263 uint32_t m_ssThresh; //!< ss thresh
264 Time m_rtt; //!< rtt
266 SequenceNumber32 m_lastAckedSeq; //!< last acked seq
268};
269
272 uint32_t ssThresh,
273 uint32_t segmentsAcked,
274 SequenceNumber32 highTxMark,
275 SequenceNumber32 lastAckedSeq,
276 Time rtt,
277 const std::string& name)
278 : TestCase(name),
279 m_cWnd(cWnd),
280 m_segmentSize(segmentSize),
281 m_segmentsAcked(segmentsAcked),
282 m_ssThresh(ssThresh),
283 m_rtt(rtt),
284 m_highTxMark(highTxMark),
285 m_lastAckedSeq(lastAckedSeq)
286{
287}
288
289void
296
297void
299{
300 UintegerValue minCwnd;
302 m_state->m_cWnd = m_cWnd;
303 m_state->m_ssThresh = m_ssThresh;
304 m_state->m_segmentSize = m_segmentSize;
305 m_state->m_highTxMark = m_highTxMark;
306 m_state->m_lastAckedSeq = m_lastAckedSeq;
307
309 cong->SetAttribute("SSParam", StringValue("no"));
310 cong->SetAttribute("NoiseFilterLen", UintegerValue(1));
311 cong->GetAttribute("MinCwnd", minCwnd);
312
313 m_state->m_rcvTimestampValue = 2;
314 m_state->m_rcvTimestampEchoReply = 1;
315 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
316
317 m_state->m_rcvTimestampValue = 205;
318 m_state->m_rcvTimestampEchoReply = 6;
319 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
320
321 cong->IncreaseWindow(m_state, m_segmentsAcked);
322
324 m_cWnd = std::max(m_cWnd, static_cast<uint32_t>(m_segmentSize * minCwnd.Get()));
325
326 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
327}
328
329/**
330 * \ingroup internet-test
331 *
332 * \brief TCP Ledbat TestSuite
333 */
335{
336 public:
338 : TestSuite("tcp-ledbat-test", Type::UNIT)
339 {
340 AddTestCase(new TcpLedbatToNewReno(2 * 1446,
341 1446,
342 4 * 1446,
343 2,
344 SequenceNumber32(4753),
345 SequenceNumber32(3216),
346 MilliSeconds(100),
347 "LEDBAT falls to New Reno for slowstart"),
348 TestCase::Duration::QUICK);
349 AddTestCase(new TcpLedbatToNewReno(4 * 1446,
350 1446,
351 2 * 1446,
352 2,
353 SequenceNumber32(4753),
354 SequenceNumber32(3216),
355 MilliSeconds(100),
356 "LEDBAT falls to New Reno if timestamps are not found"),
357 TestCase::Duration::QUICK);
359 1446,
360 4 * 1446,
361 2,
362 SequenceNumber32(4753),
363 SequenceNumber32(3216),
364 MilliSeconds(100),
365 "LEDBAT increment test"),
366 TestCase::Duration::QUICK);
368 1446,
369 4 * 1446,
370 2,
371 SequenceNumber32(4753),
372 SequenceNumber32(3216),
373 MilliSeconds(100),
374 "LEDBAT decrement test"),
375 TestCase::Duration::QUICK);
376 }
377};
378
379static TcpLedbatTestSuite g_tcpledbatTest; //!< static var for test initialization
Test to validate cWnd decrement in LEDBAT.
TcpLedbatDecrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
SequenceNumber32 m_highTxMark
high tx mark
uint32_t m_segmentSize
segment size
uint32_t m_ssThresh
ss thresh
void ExecuteTest()
Execute the test.
uint32_t m_segmentsAcked
segments acked
SequenceNumber32 m_lastAckedSeq
last acked seq
void DoRun() override
Implementation to actually run this TestCase.
Ptr< TcpSocketState > m_state
state
Test to validate cWnd increment in LEDBAT.
SequenceNumber32 m_highTxMark
high tx mark
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_segmentsAcked
segments acked
void ExecuteTest()
Execute the test.
uint32_t m_segmentSize
segment size
TcpLedbatIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
uint32_t m_ssThresh
ss thresh
SequenceNumber32 m_lastAckedSeq
last acked seq
Ptr< TcpSocketState > m_state
state
TCP Ledbat TestSuite.
LEDBAT should be same as NewReno during slow start, and when timestamps are disabled.
uint32_t m_segmentsAcked
segments acked
TcpLedbatToNewReno(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
SequenceNumber32 m_highTxMark
high tx mark
Ptr< TcpSocketState > m_state
state
SequenceNumber32 m_lastAckedSeq
last acked seq
void DoRun() override
Implementation to actually run this TestCase.
void ExecuteTest()
Execute the test.
uint32_t m_segmentSize
segment size
uint32_t m_ssThresh
ss thresh
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Hold an unsigned integer type.
Definition uinteger.h:34
uint64_t Get() const
Definition uinteger.cc:26
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpLedbatTestSuite g_tcpledbatTest
static var for test initialization