A Discrete-Event Network Simulator
API
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
36{
37 public:
49 uint32_t ssThresh,
50 uint32_t segmentsAcked,
51 uint32_t lastMaxCwnd,
52 const std::string& name);
53
54 private:
55 void DoRun() override;
56
63
67 void ExecuteTest();
68
75};
76
79 uint32_t ssThresh,
80 uint32_t segmentsAcked,
81 uint32_t lastMaxCwnd,
82 const std::string& name)
83 : TestCase(name),
84 m_cWnd(cWnd),
85 m_segmentSize(segmentSize),
86 m_ssThresh(ssThresh),
87 m_segmentsAcked(segmentsAcked),
88 m_lastMaxCwnd(lastMaxCwnd)
89{
90}
91
92void
94{
95 m_state = CreateObject<TcpSocketState>();
96
100
101 Simulator::Schedule(Seconds(0.0), &TcpBicIncrementTest::ExecuteTest, this);
102 Simulator::Run();
103 Simulator::Destroy();
104}
105
106void
108{
109 uint32_t segCwnd = m_cWnd / m_segmentSize;
110
111 uint32_t ackCnt = Update(m_state);
112
113 if (m_segmentsAcked > ackCnt)
114 {
116 segCwnd * m_segmentSize + m_segmentSize,
117 "Bic has not increment cWnd");
118 /* NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), 27000,
119 "Bic has not increment cWnd");*/
120 }
121 else
122 {
124 segCwnd * m_segmentSize,
125 "Bic has modified cWnd");
126 }
127}
128
131{
132 uint32_t segCwnd = tcb->m_cWnd / tcb->m_segmentSize;
133 Ptr<TcpBic> cong = CreateObject<TcpBic>();
134 cong->m_lastMaxCwnd = m_lastMaxCwnd;
135 UintegerValue lowWindow;
136 UintegerValue bsCoeff;
137 UintegerValue wMax;
138 UintegerValue smoothPart;
139 cong->GetAttribute("LowWnd", lowWindow);
140 cong->GetAttribute("BinarySearchCoefficient", bsCoeff);
141 cong->GetAttribute("MaxIncr", wMax);
142 cong->GetAttribute("SmoothPart", smoothPart);
143
144 cong->IncreaseWindow(m_state, m_segmentsAcked);
145
146 uint32_t ackCnt = 0;
147
148 if (segCwnd < lowWindow.Get())
149 {
150 ackCnt = segCwnd;
151 return ackCnt;
152 }
153 if (segCwnd < m_lastMaxCwnd)
154 {
155 double midPt = (m_lastMaxCwnd - segCwnd) / bsCoeff.Get();
156 if (midPt > wMax.Get())
157 {
158 // Linear increase
159 ackCnt = segCwnd / wMax.Get();
160 }
161 else if (midPt <= 1)
162 {
163 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
164 }
165 else
166 {
167 // Binary search increase
168 ackCnt = segCwnd / midPt;
169 }
170 }
171 else
172 {
173 if (segCwnd < m_lastMaxCwnd + bsCoeff.Get())
174 {
175 /* slow start AMD linear increase */
176 ackCnt = (segCwnd * smoothPart.Get()) / bsCoeff.Get();
177 }
178 else if (segCwnd < m_lastMaxCwnd + wMax.Get() * (bsCoeff.Get() - 1))
179 {
180 /* slow start */
181 ackCnt = (segCwnd * (bsCoeff.Get() - 1)) / (segCwnd - m_lastMaxCwnd);
182 }
183 else
184 {
185 /* linear increase */
186 ackCnt = segCwnd / wMax.Get();
187 }
188 }
189 return ackCnt;
190}
191
199{
200 public:
211 BooleanValue fastConvergence,
212 uint32_t lastMaxCwnd,
213 const std::string& name);
214
215 private:
216 void DoRun() override;
217
221 void ExecuteTest();
222
228};
229
232 BooleanValue fastConvergence,
233 uint32_t lastMaxCwnd,
234 const std::string& name)
235 : TestCase(name),
236 m_cWnd(cWnd),
237 m_segmentSize(segmentSize),
238 m_fastConvergence(fastConvergence),
239 m_lastMaxCwnd(lastMaxCwnd)
240{
241}
242
243void
245{
246 m_state = CreateObject<TcpSocketState>();
247
250
251 Simulator::Schedule(Seconds(0.0), &TcpBicDecrementTest::ExecuteTest, this);
252 Simulator::Run();
253 Simulator::Destroy();
254}
255
256void
258{
259 Ptr<TcpBic> cong = CreateObject<TcpBic>();
260 cong->m_lastMaxCwnd = m_lastMaxCwnd;
261 cong->SetAttribute("FastConvergence", m_fastConvergence);
262
263 uint32_t segCwnd = m_cWnd / m_segmentSize;
264 uint32_t retSsThresh = cong->GetSsThresh(m_state, m_state->m_cWnd);
265 uint32_t retLastMaxCwnd = cong->m_lastMaxCwnd;
266
267 DoubleValue beta;
268 UintegerValue lowWindow;
269 cong->GetAttribute("Beta", beta);
270 cong->GetAttribute("LowWnd", lowWindow);
271
272 uint32_t lastMaxCwnd;
273 uint32_t ssThresh;
274
275 if (segCwnd < m_lastMaxCwnd && m_fastConvergence.Get())
276 {
277 lastMaxCwnd = beta.Get() * segCwnd;
278 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
279 lastMaxCwnd,
280 "Bic has not updated lastMaxCwnd during fast convergence");
281 }
282 else
283 {
284 lastMaxCwnd = segCwnd;
285 NS_TEST_ASSERT_MSG_EQ(retLastMaxCwnd,
286 lastMaxCwnd,
287 "Bic has not reset lastMaxCwnd to current cwnd (in segments)");
288 }
289
290 if (segCwnd < lowWindow.Get())
291 {
292 ssThresh = std::max(2 * m_segmentSize, m_cWnd / 2);
293 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
294 ssThresh,
295 "Bic has not updated ssThresh when cWnd less than lowWindow");
296 }
297 else
298 {
299 ssThresh = std::max(segCwnd * beta.Get(), 2.0) * m_segmentSize;
300 NS_TEST_ASSERT_MSG_EQ(retSsThresh,
301 ssThresh,
302 "Bic has not updated ssThresh when cWnd greater than lowWindow");
303 }
304}
305
313{
314 public:
316 : TestSuite("tcp-bic-test", UNIT)
317 {
319 new TcpBicIncrementTest(10 * 536,
320 536,
321 9 * 536,
322 11,
323 0,
324 "Bic increment test: under lowCwnd & enough ACKs received"),
325 TestCase::QUICK);
327 10 * 536,
328 536,
329 9 * 536,
330 8,
331 0,
332 "Bic increment test: under lowCwnd but not enough ACKs received"),
333 TestCase::QUICK);
335 18 * 1446,
336 1446,
337 15 * 1446,
338 5,
339 90,
340 "Bic increment test: linear increase when distance exceeds S_max"),
341 TestCase::QUICK);
343 new TcpBicIncrementTest(18 * 1446,
344 1446,
345 15 * 1446,
346 24,
347 20,
348 "Bic increment test: binary search increase with smooth part"),
349 TestCase::QUICK);
351 1,
352 17 * 1,
353 2,
354 83,
355 "Bic increment test: binary search increase"),
356 TestCase::QUICK);
357 AddTestCase(new TcpBicIncrementTest(15 * 536,
358 536,
359 9 * 536,
360 19,
361 13,
362 "Bic increment test: slow start AMD linear increase"),
363 TestCase::QUICK);
365 new TcpBicIncrementTest(22 * 1000,
366 1000,
367 9 * 1000,
368 9,
369 16,
370 "Bic increment test: slow start but not enough ACKs received"),
371 TestCase::QUICK);
373 65 * 1000,
374 1000,
375 9 * 1000,
376 2,
377 16,
378 "Bic increment test: linear incrase but not enough ACKs received"),
379 TestCase::QUICK);
380
382 5 * 1446,
383 1446,
384 true,
385 10,
386 "Bic decrement test: fast convergence & cwnd less than lowWindow"),
387 TestCase::QUICK);
389 5 * 1446,
390 1446,
391 false,
392 10,
393 "Bic decrement test: not in fast convergence & cwnd less than lowWindow"),
394 TestCase::QUICK);
397 15 * 1446,
398 1446,
399 false,
400 10,
401 "Bic decrement test: not in fast convergence & cwnd greater than lowWindow"),
402 TestCase::QUICK);
403 }
404};
405
#define max(a, b)
Definition: 80211b.c:43
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:36
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:93
uint32_t m_ssThresh
Slow Start Threshold.
Definition: tcp-bic-test.cc:71
void ExecuteTest()
Execute the test.
uint32_t m_lastMaxCwnd
Last max Cwnd.
Definition: tcp-bic-test.cc:73
uint32_t m_segmentsAcked
Number of segments acked.
Definition: tcp-bic-test.cc:72
uint32_t m_cWnd
Congestion window.
Definition: tcp-bic-test.cc:69
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-bic-test.cc:74
uint32_t m_segmentSize
Segment size.
Definition: tcp-bic-test.cc:70
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:77
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
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:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
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:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBicTestSuite g_tcpBicTest
Static variable for test initialization.