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 
25 using namespace ns3;
26 
27 NS_LOG_COMPONENT_DEFINE("TcpBicTestSuite");
28 
35 {
36  public:
46  TcpBicIncrementTest(uint32_t cWnd,
47  uint32_t segmentSize,
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 
61  uint32_t Update(Ptr<TcpSocketState> tcb);
62 
66  void ExecuteTest();
67 
68  uint32_t m_cWnd;
69  uint32_t m_segmentSize;
70  uint32_t m_ssThresh;
71  uint32_t m_segmentsAcked;
72  uint32_t m_lastMaxCwnd;
74 };
75 
77  uint32_t segmentSize,
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 
91 void
93 {
94  m_state = CreateObject<TcpSocketState>();
95 
99 
100  Simulator::Schedule(Seconds(0.0), &TcpBicIncrementTest::ExecuteTest, this);
101  Simulator::Run();
102  Simulator::Destroy();
103 }
104 
105 void
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 
128 uint32_t
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 
197 {
198  public:
207  TcpBicDecrementTest(uint32_t cWnd,
208  uint32_t segmentSize,
209  BooleanValue fastConvergence,
210  uint32_t lastMaxCwnd,
211  const std::string& name);
212 
213  private:
214  void DoRun() override;
215 
219  void ExecuteTest();
220 
221  uint32_t m_cWnd;
222  uint32_t m_segmentSize;
224  uint32_t m_lastMaxCwnd;
226 };
227 
229  uint32_t segmentSize,
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 
241 void
243 {
244  m_state = CreateObject<TcpSocketState>();
245 
246  m_state->m_cWnd = m_cWnd;
248 
249  Simulator::Schedule(Seconds(0.0), &TcpBicDecrementTest::ExecuteTest, this);
250  Simulator::Run();
251  Simulator::Destroy();
252 }
253 
254 void
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 
310 {
311  public:
313  : TestSuite("tcp-bic-test", UNIT)
314  {
315  AddTestCase(
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::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::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::QUICK);
339  AddTestCase(
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::QUICK);
347  AddTestCase(new TcpBicIncrementTest(19 * 1,
348  1,
349  17 * 1,
350  2,
351  83,
352  "Bic increment test: binary search increase"),
353  TestCase::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::QUICK);
361  AddTestCase(
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::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::QUICK);
377 
379  5 * 1446,
380  1446,
381  true,
382  10,
383  "Bic decrement test: fast convergence & cwnd less than lowWindow"),
384  TestCase::QUICK);
386  5 * 1446,
387  1446,
388  false,
389  10,
390  "Bic decrement test: not in fast convergence & cwnd less than lowWindow"),
391  TestCase::QUICK);
392  AddTestCase(
394  15 * 1446,
395  1446,
396  false,
397  10,
398  "Bic decrement test: not in fast convergence & cwnd greater than lowWindow"),
399  TestCase::QUICK);
400  }
401 };
402 
#define max(a, b)
Definition: 80211b.c:42
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.
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:301
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:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBicTestSuite g_tcpBicTest
Static variable for test initialization.