A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-bic-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/log.h"
9#include "ns3/tcp-bic.h"
10#include "ns3/tcp-congestion-ops.h"
11#include "ns3/tcp-socket-base.h"
12#include "ns3/test.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpBicTestSuite");
17
18/**
19 * \ingroup internet-test
20 *
21 * \brief Testing the congestion avoidance increment on TcpBic
22 */
24{
25 public:
26 /**
27 * \brief Constructor.
28 * \param cWnd Congestion window.
29 * \param segmentSize Segment size.
30 * \param ssThresh Slow Start Threshold.
31 * \param segmentsAcked Number of segments acked.
32 * \param lastMaxCwnd Last max Cwnd.
33 * \param name Test description.
34 */
37 uint32_t ssThresh,
38 uint32_t segmentsAcked,
39 uint32_t lastMaxCwnd,
40 const std::string& name);
41
42 private:
43 void DoRun() override;
44
45 /**
46 * \brief Update the TCP socket state.
47 * \param tcb The TCP socket state.
48 * \returns The ack counter.
49 */
51
52 /**
53 * \brief Execute the test.
54 */
55 void ExecuteTest();
56
57 uint32_t m_cWnd; //!< Congestion window.
58 uint32_t m_segmentSize; //!< Segment size.
59 uint32_t m_ssThresh; //!< Slow Start Threshold.
60 uint32_t m_segmentsAcked; //!< Number of segments acked.
61 uint32_t m_lastMaxCwnd; //!< Last max Cwnd.
62 Ptr<TcpSocketState> m_state; //!< TCP socket state.
63};
64
67 uint32_t ssThresh,
68 uint32_t segmentsAcked,
69 uint32_t lastMaxCwnd,
70 const std::string& name)
71 : TestCase(name),
72 m_cWnd(cWnd),
73 m_segmentSize(segmentSize),
74 m_ssThresh(ssThresh),
75 m_segmentsAcked(segmentsAcked),
76 m_lastMaxCwnd(lastMaxCwnd)
77{
78}
79
80void
93
94void
96{
97 uint32_t segCwnd = m_cWnd / m_segmentSize;
98
99 uint32_t ackCnt = Update(m_state);
100
101 if (m_segmentsAcked > ackCnt)
102 {
103 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(),
104 segCwnd * m_segmentSize + m_segmentSize,
105 "Bic has not increment cWnd");
106 /* NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), 27000,
107 "Bic has not increment cWnd");*/
108 }
109 else
110 {
111 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(),
112 segCwnd * m_segmentSize,
113 "Bic has modified cWnd");
114 }
115}
116
119{
120 uint32_t segCwnd = tcb->m_cWnd / tcb->m_segmentSize;
122 cong->m_lastMaxCwnd = m_lastMaxCwnd;
123 UintegerValue lowWindow;
124 UintegerValue bsCoeff;
125 UintegerValue wMax;
126 UintegerValue smoothPart;
127 cong->GetAttribute("LowWnd", lowWindow);
128 cong->GetAttribute("BinarySearchCoefficient", bsCoeff);
129 cong->GetAttribute("MaxIncr", wMax);
130 cong->GetAttribute("SmoothPart", smoothPart);
131
132 cong->IncreaseWindow(m_state, m_segmentsAcked);
133
134 uint32_t ackCnt = 0;
135
136 if (segCwnd < lowWindow.Get())
137 {
138 ackCnt = segCwnd;
139 return ackCnt;
140 }
141 if (segCwnd < m_lastMaxCwnd)
142 {
143 double midPt = (m_lastMaxCwnd - segCwnd) / bsCoeff.Get();
144 if (midPt > wMax.Get())
145 {
146 // Linear increase
147 ackCnt = segCwnd / wMax.Get();
148 }
149 else if (midPt <= 1)
150 {
151 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
152 }
153 else
154 {
155 // Binary search increase
156 ackCnt = segCwnd / midPt;
157 }
158 }
159 else
160 {
161 if (segCwnd < m_lastMaxCwnd + bsCoeff.Get())
162 {
163 /* slow start AMD linear increase */
164 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
165 }
166 else if (segCwnd < m_lastMaxCwnd + wMax.Get() * (bsCoeff.Get() - 1))
167 {
168 /* slow start */
169 ackCnt = (segCwnd * (bsCoeff.Get() - 1)) / (segCwnd - m_lastMaxCwnd);
170 }
171 else
172 {
173 /* linear increase */
174 ackCnt = segCwnd / wMax.Get();
175 }
176 }
177 return ackCnt;
178}
179
180/**
181 * \ingroup internet-test
182 *
183 * \brief Testing the congestion avoidance decrement on TcpBic
184 */
186{
187 public:
188 /**
189 * \brief Constructor.
190 * \param cWnd Congestion window.
191 * \param segmentSize Segment size.
192 * \param fastConvergence Fast convergence.
193 * \param lastMaxCwnd Last max Cwnd.
194 * \param name Test description.
195 */
198 BooleanValue fastConvergence,
199 uint32_t lastMaxCwnd,
200 const std::string& name);
201
202 private:
203 void DoRun() override;
204
205 /**
206 * \brief Execute the test.
207 */
208 void ExecuteTest();
209
210 uint32_t m_cWnd; //!< Congestion window.
211 uint32_t m_segmentSize; //!< Segment size.
212 BooleanValue m_fastConvergence; //!< Fast convergence.
213 uint32_t m_lastMaxCwnd; //!< Last max Cwnd.
214 Ptr<TcpSocketState> m_state; //!< TCP socket state.
215};
216
219 BooleanValue fastConvergence,
220 uint32_t lastMaxCwnd,
221 const std::string& name)
222 : TestCase(name),
223 m_cWnd(cWnd),
224 m_segmentSize(segmentSize),
225 m_fastConvergence(fastConvergence),
226 m_lastMaxCwnd(lastMaxCwnd)
227{
228}
229
230void
242
243void
245{
247 cong->m_lastMaxCwnd = m_lastMaxCwnd;
248 cong->SetAttribute("FastConvergence", m_fastConvergence);
249
250 uint32_t segCwnd = m_cWnd / m_segmentSize;
251 uint32_t retSsThresh = cong->GetSsThresh(m_state, m_state->m_cWnd);
252 uint32_t retLastMaxCwnd = cong->m_lastMaxCwnd;
253
254 DoubleValue beta;
255 UintegerValue lowWindow;
256 cong->GetAttribute("Beta", beta);
257 cong->GetAttribute("LowWnd", lowWindow);
258
259 uint32_t lastMaxCwnd;
260 uint32_t ssThresh;
261
262 if (segCwnd < m_lastMaxCwnd && m_fastConvergence.Get())
263 {
264 lastMaxCwnd = beta.Get() * segCwnd;
265 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
266 lastMaxCwnd,
267 "Bic has not updated lastMaxCwnd during fast convergence");
268 }
269 else
270 {
271 lastMaxCwnd = segCwnd;
272 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
273 lastMaxCwnd,
274 "Bic has not reset lastMaxCwnd to current cwnd (in segments)");
275 }
276
277 if (segCwnd < lowWindow.Get())
278 {
279 ssThresh = std::max(2 * m_segmentSize, m_cWnd / 2);
280 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
281 ssThresh,
282 "Bic has not updated ssThresh when cWnd less than lowWindow");
283 }
284 else
285 {
286 ssThresh = std::max(segCwnd * beta.Get(), 2.0) * m_segmentSize;
287 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
288 ssThresh,
289 "Bic has not updated ssThresh when cWnd greater than lowWindow");
290 }
291}
292
293/**
294 * \ingroup internet-test
295 *
296 * \brief TCP Bic TestSuite
297 */
299{
300 public:
302 : TestSuite("tcp-bic-test", Type::UNIT)
303 {
305 new TcpBicIncrementTest(10 * 536,
306 536,
307 9 * 536,
308 11,
309 0,
310 "Bic increment test: under lowCwnd & enough ACKs received"),
311 TestCase::Duration::QUICK);
313 10 * 536,
314 536,
315 9 * 536,
316 8,
317 0,
318 "Bic increment test: under lowCwnd but not enough ACKs received"),
319 TestCase::Duration::QUICK);
321 18 * 1446,
322 1446,
323 15 * 1446,
324 5,
325 90,
326 "Bic increment test: linear increase when distance exceeds S_max"),
327 TestCase::Duration::QUICK);
329 new TcpBicIncrementTest(18 * 1446,
330 1446,
331 15 * 1446,
332 24,
333 20,
334 "Bic increment test: binary search increase with smooth part"),
335 TestCase::Duration::QUICK);
337 1,
338 17 * 1,
339 2,
340 83,
341 "Bic increment test: binary search increase"),
342 TestCase::Duration::QUICK);
343 AddTestCase(new TcpBicIncrementTest(15 * 536,
344 536,
345 9 * 536,
346 19,
347 13,
348 "Bic increment test: slow start AMD linear increase"),
349 TestCase::Duration::QUICK);
351 new TcpBicIncrementTest(22 * 1000,
352 1000,
353 9 * 1000,
354 9,
355 16,
356 "Bic increment test: slow start but not enough ACKs received"),
357 TestCase::Duration::QUICK);
359 65 * 1000,
360 1000,
361 9 * 1000,
362 2,
363 16,
364 "Bic increment test: linear increase but not enough ACKs received"),
365 TestCase::Duration::QUICK);
366
368 5 * 1446,
369 1446,
370 true,
371 10,
372 "Bic decrement test: fast convergence & cwnd less than lowWindow"),
373 TestCase::Duration::QUICK);
375 5 * 1446,
376 1446,
377 false,
378 10,
379 "Bic decrement test: not in fast convergence & cwnd less than lowWindow"),
380 TestCase::Duration::QUICK);
383 15 * 1446,
384 1446,
385 false,
386 10,
387 "Bic decrement test: not in fast convergence & cwnd greater than lowWindow"),
388 TestCase::Duration::QUICK);
389 }
390};
391
392static TcpBicTestSuite g_tcpBicTest; //!< Static variable for test initialization
Testing the congestion avoidance decrement on TcpBic.
uint32_t m_cWnd
Congestion window.
uint32_t m_segmentSize
Segment size.
void ExecuteTest()
Execute the test.
uint32_t m_lastMaxCwnd
Last max Cwnd.
Ptr< TcpSocketState > m_state
TCP socket state.
BooleanValue m_fastConvergence
Fast convergence.
TcpBicDecrementTest(uint32_t cWnd, uint32_t segmentSize, BooleanValue fastConvergence, uint32_t lastMaxCwnd, const std::string &name)
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
Testing the congestion avoidance increment on TcpBic.
uint32_t Update(Ptr< TcpSocketState > tcb)
Update the TCP socket state.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_ssThresh
Slow Start Threshold.
void ExecuteTest()
Execute the test.
uint32_t m_lastMaxCwnd
Last max Cwnd.
uint32_t m_segmentsAcked
Number of segments acked.
uint32_t m_cWnd
Congestion window.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
TcpBicIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, uint32_t lastMaxCwnd, const std::string &name)
Constructor.
TCP Bic TestSuite.
bool Get() const
Definition boolean.cc:44
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
double Get() const
Definition double.cc:26
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
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
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
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBicTestSuite g_tcpBicTest
Static variable for test initialization.