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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include "ns3/log.h"
20#include "ns3/tcp-bic.h"
21#include "ns3/tcp-congestion-ops.h"
22#include "ns3/tcp-socket-base.h"
23#include "ns3/test.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpBicTestSuite");
28
29/**
30 * \ingroup internet-test
31 *
32 * \brief Testing the congestion avoidance increment on TcpBic
33 */
35{
36 public:
37 /**
38 * \brief Constructor.
39 * \param cWnd Congestion window.
40 * \param segmentSize Segment size.
41 * \param ssThresh Slow Start Threshold.
42 * \param segmentsAcked Number of segments acked.
43 * \param lastMaxCwnd Last max Cwnd.
44 * \param name Test description.
45 */
48 uint32_t ssThresh,
49 uint32_t segmentsAcked,
50 uint32_t lastMaxCwnd,
51 const std::string& name);
52
53 private:
54 void DoRun() override;
55
56 /**
57 * \brief Update the TCP socket state.
58 * \param tcb The TCP socket state.
59 * \returns The ack counter.
60 */
62
63 /**
64 * \brief Execute the test.
65 */
66 void ExecuteTest();
67
68 uint32_t m_cWnd; //!< Congestion window.
69 uint32_t m_segmentSize; //!< Segment size.
70 uint32_t m_ssThresh; //!< Slow Start Threshold.
71 uint32_t m_segmentsAcked; //!< Number of segments acked.
72 uint32_t m_lastMaxCwnd; //!< Last max Cwnd.
73 Ptr<TcpSocketState> m_state; //!< TCP socket state.
74};
75
78 uint32_t ssThresh,
79 uint32_t segmentsAcked,
80 uint32_t lastMaxCwnd,
81 const std::string& name)
82 : TestCase(name),
83 m_cWnd(cWnd),
84 m_segmentSize(segmentSize),
85 m_ssThresh(ssThresh),
86 m_segmentsAcked(segmentsAcked),
87 m_lastMaxCwnd(lastMaxCwnd)
88{
89}
90
91void
93{
94 m_state = CreateObject<TcpSocketState>();
95
99
103}
104
105void
107{
108 uint32_t segCwnd = m_cWnd / m_segmentSize;
109
110 uint32_t ackCnt = Update(m_state);
111
112 if (m_segmentsAcked > ackCnt)
113 {
115 segCwnd * m_segmentSize + m_segmentSize,
116 "Bic has not increment cWnd");
117 /* NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), 27000,
118 "Bic has not increment cWnd");*/
119 }
120 else
121 {
123 segCwnd * m_segmentSize,
124 "Bic has modified cWnd");
125 }
126}
127
130{
131 uint32_t segCwnd = tcb->m_cWnd / tcb->m_segmentSize;
132 Ptr<TcpBic> cong = CreateObject<TcpBic>();
133 cong->m_lastMaxCwnd = m_lastMaxCwnd;
134 UintegerValue lowWindow;
135 UintegerValue bsCoeff;
136 UintegerValue wMax;
137 UintegerValue smoothPart;
138 cong->GetAttribute("LowWnd", lowWindow);
139 cong->GetAttribute("BinarySearchCoefficient", bsCoeff);
140 cong->GetAttribute("MaxIncr", wMax);
141 cong->GetAttribute("SmoothPart", smoothPart);
142
143 cong->IncreaseWindow(m_state, m_segmentsAcked);
144
145 uint32_t ackCnt = 0;
146
147 if (segCwnd < lowWindow.Get())
148 {
149 ackCnt = segCwnd;
150 return ackCnt;
151 }
152 if (segCwnd < m_lastMaxCwnd)
153 {
154 double midPt = (m_lastMaxCwnd - segCwnd) / bsCoeff.Get();
155 if (midPt > wMax.Get())
156 {
157 // Linear increase
158 ackCnt = segCwnd / wMax.Get();
159 }
160 else if (midPt <= 1)
161 {
162 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
163 }
164 else
165 {
166 // Binary search increase
167 ackCnt = segCwnd / midPt;
168 }
169 }
170 else
171 {
172 if (segCwnd < m_lastMaxCwnd + bsCoeff.Get())
173 {
174 /* slow start AMD linear increase */
175 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
176 }
177 else if (segCwnd < m_lastMaxCwnd + wMax.Get() * (bsCoeff.Get() - 1))
178 {
179 /* slow start */
180 ackCnt = (segCwnd * (bsCoeff.Get() - 1)) / (segCwnd - m_lastMaxCwnd);
181 }
182 else
183 {
184 /* linear increase */
185 ackCnt = segCwnd / wMax.Get();
186 }
187 }
188 return ackCnt;
189}
190
191/**
192 * \ingroup internet-test
193 *
194 * \brief Testing the congestion avoidance decrement on TcpBic
195 */
197{
198 public:
199 /**
200 * \brief Constructor.
201 * \param cWnd Congestion window.
202 * \param segmentSize Segment size.
203 * \param fastConvergence Fast convergence.
204 * \param lastMaxCwnd Last max Cwnd.
205 * \param name Test description.
206 */
209 BooleanValue fastConvergence,
210 uint32_t lastMaxCwnd,
211 const std::string& name);
212
213 private:
214 void DoRun() override;
215
216 /**
217 * \brief Execute the test.
218 */
219 void ExecuteTest();
220
221 uint32_t m_cWnd; //!< Congestion window.
222 uint32_t m_segmentSize; //!< Segment size.
223 BooleanValue m_fastConvergence; //!< Fast convergence.
224 uint32_t m_lastMaxCwnd; //!< Last max Cwnd.
225 Ptr<TcpSocketState> m_state; //!< TCP socket state.
226};
227
230 BooleanValue fastConvergence,
231 uint32_t lastMaxCwnd,
232 const std::string& name)
233 : TestCase(name),
234 m_cWnd(cWnd),
235 m_segmentSize(segmentSize),
236 m_fastConvergence(fastConvergence),
237 m_lastMaxCwnd(lastMaxCwnd)
238{
239}
240
241void
243{
244 m_state = CreateObject<TcpSocketState>();
245
248
252}
253
254void
256{
257 Ptr<TcpBic> cong = CreateObject<TcpBic>();
258 cong->m_lastMaxCwnd = m_lastMaxCwnd;
259 cong->SetAttribute("FastConvergence", m_fastConvergence);
260
261 uint32_t segCwnd = m_cWnd / m_segmentSize;
262 uint32_t retSsThresh = cong->GetSsThresh(m_state, m_state->m_cWnd);
263 uint32_t retLastMaxCwnd = cong->m_lastMaxCwnd;
264
265 DoubleValue beta;
266 UintegerValue lowWindow;
267 cong->GetAttribute("Beta", beta);
268 cong->GetAttribute("LowWnd", lowWindow);
269
270 uint32_t lastMaxCwnd;
271 uint32_t ssThresh;
272
273 if (segCwnd < m_lastMaxCwnd && m_fastConvergence.Get())
274 {
275 lastMaxCwnd = beta.Get() * segCwnd;
276 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
277 lastMaxCwnd,
278 "Bic has not updated lastMaxCwnd during fast convergence");
279 }
280 else
281 {
282 lastMaxCwnd = segCwnd;
283 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
284 lastMaxCwnd,
285 "Bic has not reset lastMaxCwnd to current cwnd (in segments)");
286 }
287
288 if (segCwnd < lowWindow.Get())
289 {
290 ssThresh = std::max(2 * m_segmentSize, m_cWnd / 2);
291 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
292 ssThresh,
293 "Bic has not updated ssThresh when cWnd less than lowWindow");
294 }
295 else
296 {
297 ssThresh = std::max(segCwnd * beta.Get(), 2.0) * m_segmentSize;
298 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
299 ssThresh,
300 "Bic has not updated ssThresh when cWnd greater than lowWindow");
301 }
302}
303
304/**
305 * \ingroup internet-test
306 *
307 * \brief TCP Bic TestSuite
308 */
310{
311 public:
313 : TestSuite("tcp-bic-test", Type::UNIT)
314 {
316 new TcpBicIncrementTest(10 * 536,
317 536,
318 9 * 536,
319 11,
320 0,
321 "Bic increment test: under lowCwnd & enough ACKs received"),
322 TestCase::Duration::QUICK);
324 10 * 536,
325 536,
326 9 * 536,
327 8,
328 0,
329 "Bic increment test: under lowCwnd but not enough ACKs received"),
330 TestCase::Duration::QUICK);
332 18 * 1446,
333 1446,
334 15 * 1446,
335 5,
336 90,
337 "Bic increment test: linear increase when distance exceeds S_max"),
338 TestCase::Duration::QUICK);
340 new TcpBicIncrementTest(18 * 1446,
341 1446,
342 15 * 1446,
343 24,
344 20,
345 "Bic increment test: binary search increase with smooth part"),
346 TestCase::Duration::QUICK);
348 1,
349 17 * 1,
350 2,
351 83,
352 "Bic increment test: binary search increase"),
353 TestCase::Duration::QUICK);
354 AddTestCase(new TcpBicIncrementTest(15 * 536,
355 536,
356 9 * 536,
357 19,
358 13,
359 "Bic increment test: slow start AMD linear increase"),
360 TestCase::Duration::QUICK);
362 new TcpBicIncrementTest(22 * 1000,
363 1000,
364 9 * 1000,
365 9,
366 16,
367 "Bic increment test: slow start but not enough ACKs received"),
368 TestCase::Duration::QUICK);
370 65 * 1000,
371 1000,
372 9 * 1000,
373 2,
374 16,
375 "Bic increment test: linear incrase but not enough ACKs received"),
376 TestCase::Duration::QUICK);
377
379 5 * 1446,
380 1446,
381 true,
382 10,
383 "Bic decrement test: fast convergence & cwnd less than lowWindow"),
384 TestCase::Duration::QUICK);
386 5 * 1446,
387 1446,
388 false,
389 10,
390 "Bic decrement test: not in fast convergence & cwnd less than lowWindow"),
391 TestCase::Duration::QUICK);
394 15 * 1446,
395 1446,
396 false,
397 10,
398 "Bic decrement test: not in fast convergence & cwnd greater than lowWindow"),
399 TestCase::Duration::QUICK);
400 }
401};
402
403static 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.
Definition: tcp-bic-test.cc:35
uint32_t Update(Ptr< TcpSocketState > tcb)
Update the TCP socket state.
void DoRun() override
Implementation to actually run this TestCase.
Definition: tcp-bic-test.cc:92
uint32_t m_ssThresh
Slow Start Threshold.
Definition: tcp-bic-test.cc:70
void ExecuteTest()
Execute the test.
uint32_t m_lastMaxCwnd
Last max Cwnd.
Definition: tcp-bic-test.cc:72
uint32_t m_segmentsAcked
Number of segments acked.
Definition: tcp-bic-test.cc:71
uint32_t m_cWnd
Congestion window.
Definition: tcp-bic-test.cc:68
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-bic-test.cc:73
uint32_t m_segmentSize
Segment size.
Definition: tcp-bic-test.cc:69
TcpBicIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, uint32_t lastMaxCwnd, const std::string &name)
Constructor.
Definition: tcp-bic-test.cc:76
TCP Bic TestSuite.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
bool Get() const
Definition: boolean.cc:55
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double Get() const
Definition: double.cc:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
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
T Get() const
Get the underlying value.
Definition: traced-value.h:249
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBicTestSuite g_tcpBicTest
Static variable for test initialization.