A Discrete-Event Network Simulator
API
tcp-illinois-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  */
26 
27 #include "ns3/test.h"
28 #include "ns3/log.h"
29 #include "ns3/tcp-congestion-ops.h"
30 #include "ns3/tcp-socket-base.h"
31 #include "ns3/tcp-illinois.h"
32 
33 using namespace ns3;
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpIllinoisTestSuite");
36 
43 class TcpIllinoisTest : public TestCase
44 {
45 public:
58  TcpIllinoisTest (uint32_t cWnd,
59  uint32_t ssThresh,
60  uint32_t segmentSize,
61  uint32_t cntRtt,
62  Time maxRtt,
63  uint32_t segmentsAcked,
64  SequenceNumber32 nextTxSeq,
65  SequenceNumber32 lastAckedSeq,
66  const std::string &name);
67 
68 private:
69  virtual void DoRun ();
74  void IncreaseWindow (Ptr<TcpIllinois> cong);
79  void RecalcParam (Ptr<TcpIllinois> cong);
84  Time CalculateMaxDelay ();
89  Time CalculateAvgDelay ();
96  void CalculateAlpha (Ptr<TcpIllinois> cong, double da, double dm);
103  void CalculateBeta (Ptr<TcpIllinois> cong, double da, double dm);
107  void GetSsThresh ();
108 
109  uint32_t m_cWnd;
110  uint32_t m_ssThresh;
111  uint32_t m_segmentSize;
114  uint32_t m_segmentsAcked;
117  double m_alpha;
118  double m_beta;
119  uint32_t m_cntRtt;
121  bool m_rttAbove;
122  uint8_t m_rttLow;
123  uint32_t m_ackCnt;
124 };
125 
127  uint32_t ssThresh,
128  uint32_t segmentSize,
129  uint32_t cntRtt,
130  Time maxRtt,
131  uint32_t segmentsAcked,
132  SequenceNumber32 nextTxSeq,
133  SequenceNumber32 lastAckedSeq,
134  const std::string & name)
135  : TestCase (name),
136  m_cWnd (cWnd),
137  m_ssThresh (ssThresh),
138  m_segmentSize (segmentSize),
139  m_baseRtt (MilliSeconds (100)),
140  m_maxRtt (maxRtt),
141  m_segmentsAcked (segmentsAcked),
142  m_nextTxSeq (nextTxSeq),
143  m_lastAckedSeq (lastAckedSeq),
144  m_alpha (0.0),
145  m_beta (0.0),
146  m_cntRtt (cntRtt),
147  m_sumRtt (0),
148  m_rttAbove (false),
149  m_rttLow (0),
150  m_ackCnt (0)
151 {
152 }
153 
154 void
156 {
157  Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
158  state->m_cWnd = m_cWnd;
159  state->m_ssThresh = m_ssThresh;
160  state->m_segmentSize = m_segmentSize;
161  state->m_nextTxSequence = m_nextTxSeq;
163 
164  Ptr<TcpIllinois> cong = CreateObject <TcpIllinois> ();
165 
166  // Set baseRtt to 100 ms
167  cong->PktsAcked (state, m_segmentsAcked, m_baseRtt);
168 
169  m_sumRtt += m_baseRtt;
170 
171  // Set maxRtt and update sumRtt based on cntRtt value
172  for (uint32_t count = 1; count < m_cntRtt; ++count)
173  {
174  cong->PktsAcked (state, m_segmentsAcked, m_maxRtt);
175  m_sumRtt += m_maxRtt;
176  }
177 
178  /*
179  * Test cWnd modification during additive increase
180  */
181  cong->IncreaseWindow (state, m_segmentsAcked);
182  IncreaseWindow (cong);
184  "CWnd has not updated correctly");
185 
186  /*
187  * Test ssThresh modification during multiplicative decrease
188  */
189  uint32_t ssThresh = cong->GetSsThresh (state, m_cWnd);
190  GetSsThresh ();
192  "SsThresh has not updated correctly");
193 
194 
195 }
196 
197 void
199 {
200  uint32_t segCwnd = m_cWnd / m_segmentSize;
201 
203  {
204  RecalcParam (cong);
205  }
206  if (m_cWnd < m_ssThresh)
207  { // NewReno slow start
208  if (m_segmentsAcked >= 1)
209  {
211  m_segmentsAcked -= 1;
212  }
213  NS_LOG_INFO ("In SlowStart, updated to cwnd " << m_cWnd <<
214  " ssthresh " << m_ssThresh);
215  }
216  else
217  {
218  uint32_t oldCwnd = segCwnd;
219 
220  if (m_segmentsAcked > 0)
221  {
223  }
224 
225  while (m_ackCnt >= segCwnd)
226  {
227  m_ackCnt -= segCwnd;
228  segCwnd += 1;
229  }
230 
231  if (segCwnd != oldCwnd)
232  {
233  m_cWnd = segCwnd * m_segmentSize;
234  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << m_cWnd <<
235  " ssthresh " << m_ssThresh);
236  }
237  }
238 
239 }
240 
241 void
243 {
244  DoubleValue alphaBase;
245  cong->GetAttribute ("AlphaBase", alphaBase);
246  UintegerValue winThresh;
247  cong->GetAttribute ("WinThresh", winThresh);
248 
249  if (m_cWnd < winThresh.Get ())
250  {
251  NS_LOG_INFO ("cWnd < winThresh, set alpha & beta to base values");
252  m_alpha = alphaBase.Get ();
253  }
254  else if (m_cntRtt > 0)
255  {
256  double dm = (double) CalculateMaxDelay ().GetMilliSeconds ();
257  double da = (double) CalculateAvgDelay ().GetMilliSeconds ();
258 
259  NS_LOG_INFO ("Updated to dm = " << dm << " da = " << da);
260 
261  CalculateAlpha (cong, da, dm);
262  CalculateBeta (cong, da, dm);
263  }
264 }
265 
266 Time
268 {
269  return (m_maxRtt - m_baseRtt);
270 }
271 
272 Time
274 {
275  return (m_sumRtt / m_cntRtt - m_baseRtt);
276 }
277 
278 void
280 {
281  DoubleValue alphaMax;
282  cong->GetAttribute ("AlphaMax", alphaMax);
283  UintegerValue theta;
284  cong->GetAttribute ("Theta", theta);
285  DoubleValue alphaMin;
286  cong->GetAttribute ("AlphaMin", alphaMin);
287 
288  double d1 = dm / 100;
289 
290  if (da <= d1)
291  {
292  if (!m_rttAbove)
293  {
294  m_alpha = alphaMax.Get ();
295  }
296  if (++m_rttLow >= theta.Get ())
297  {
298  m_rttLow = 0;
299  m_rttAbove = false;
300  m_alpha = alphaMax.Get ();
301  }
302  }
303  else
304  {
305  m_rttAbove = true;
306  dm -= d1;
307  da -= d1;
308  m_alpha = (dm * alphaMax.Get ()) / (dm + (da * (alphaMax.Get () - alphaMin.Get ())) / alphaMin.Get ());
309  }
310  NS_LOG_INFO ("Updated to alpha = " << m_alpha);
311 }
312 
313 void
315 {
316  DoubleValue betaMin;
317  cong->GetAttribute ("BetaMin", betaMin);
318  DoubleValue betaMax;
319  cong->GetAttribute ("BetaMax", betaMax);
320 
321  double d2, d3;
322  d2 = dm / 10;
323  d3 = (8 * dm) / 10;
324 
325  if (da <= d2)
326  {
327  m_beta = betaMin.Get ();
328  }
329  else if (da > d2 && da < d3)
330  {
331  m_beta = (betaMin.Get () * d3 - betaMax.Get () * d2 + (betaMax.Get () - betaMin.Get ()) * da) / (d3 - d2);
332  }
333 
334  else if (da >= d3 || d3 <= d2)
335  {
336  m_beta = betaMax.Get ();
337  }
338  NS_LOG_INFO ("Updated to beta = " << m_beta);
339 }
340 
341 void
343 {
344  uint32_t segCwnd = m_cWnd / m_segmentSize;
345  uint32_t ssThresh = std::max (2.0, (1.0 - m_beta) * segCwnd);
346 
347  NS_LOG_DEBUG ("Calculated ssThresh (in segments) = " << ssThresh);
348 
349  m_ssThresh = ssThresh * m_segmentSize;
350 }
351 
352 
353 
361 {
362 public:
363  TcpIllinoisTestSuite () : TestSuite ("tcp-illinois-test", UNIT)
364  {
365  AddTestCase (new TcpIllinoisTest (38 * 1446, 40 * 1446, 1446, 2, MilliSeconds (105), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
366  "Illinois test on cWnd and ssThresh when in slow start"),
367  TestCase::QUICK);
368  AddTestCase (new TcpIllinoisTest (60 * 346, 40 * 346, 346, 2, MilliSeconds (100), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
369  "Illinois test on cWnd and ssThresh when avg queueing delay is at minimum"),
370  TestCase::QUICK);
371  AddTestCase (new TcpIllinoisTest (38 * 1446, 40 * 1446, 1446, 5, MilliSeconds (110), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
372  "Illinois test on cWnd and ssThresh when avg queueing delay is at maximum"),
373  TestCase::QUICK);
374  AddTestCase (new TcpIllinoisTest (40 * 1446, 38 * 1446, 1446, 2, MilliSeconds (105), 55, SequenceNumber32 (2893), SequenceNumber32 (5785),
375  "Illinois test on cWnd and ssThresh when avg queueing delay is in between its min & max"),
376  TestCase::QUICK);
377  }
378 };
379 
double m_alpha
TCP Illinois alpha parameter.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void CalculateBeta(Ptr< TcpIllinois > cong, double da, double dm)
Calculate the TCP Illinois beta param.
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold after congestion event.
uint32_t m_ackCnt
ACK counter.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Illinois congestion avoidance algorithm.
Time CalculateAvgDelay()
Calculate the average delay.
A suite of tests to run.
Definition: test.h:1342
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
uint32_t m_segmentSize
Segment size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
uint32_t m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:1155
uint8_t m_rttLow
RTT low counter.
void RecalcParam(Ptr< TcpIllinois > cong)
Recalculate the internal TCP Illinois params.
#define max(a, b)
Definition: 80211b.c:43
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
uint32_t m_segmentsAcked
Number of segments ACKed.
virtual void DoRun()
Implementation to actually run this TestCase.
Hold an unsigned integer type.
Definition: uinteger.h:44
TCP Illinois TestSuite.
#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:168
SequenceNumber32 m_lastAckedSeq
Last ACKed sequence number.
bool m_rttAbove
RTT above threshold.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
TcpIllinoisTest(uint32_t cWnd, uint32_t ssThresh, uint32_t segmentSize, uint32_t cntRtt, Time maxRtt, uint32_t segmentsAcked, SequenceNumber32 nextTxSeq, SequenceNumber32 lastAckedSeq, const std::string &name)
Constructor.
Time m_sumRtt
Sum of all the RTTs.
Time m_baseRtt
Base RTT.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint64_t Get(void) const
Definition: uinteger.cc:35
double Get(void) const
Definition: double.cc:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void GetSsThresh()
brief Get and check the SSH threshold.
double m_beta
TCP Illinois beta parameter.
void CalculateAlpha(Ptr< TcpIllinois > cong, double da, double dm)
Calculate the TCP Illinois alpha param.
TracedValue< uint32_t > m_cWnd
Congestion window.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
uint32_t m_cntRtt
RTT counter.
SequenceNumber32 m_nextTxSeq
Next Tx sequence number.
void IncreaseWindow(Ptr< TcpIllinois > cong)
Increases the TCP window.
Time m_maxRtt
Max RTT.
uint32_t m_segmentSize
Segment size.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Measure RTT for each ACK Keep track of min and max RTT.
This test suite implements a Unit Test.
Definition: test.h:1352
uint32_t m_ssThresh
Slow Start Threshold.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
Time CalculateMaxDelay()
Calculate the maximum delay.
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
static TcpIllinoisTestSuite g_tcpIllinoisTest
Static variable for test initialization.
TcpIllinois C-AIMD algorithm tests.