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 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpIllinoisTestSuite");
36 
40 class TcpIllinoisTest : public TestCase
41 {
42 public:
43  TcpIllinoisTest (uint32_t cWnd,
44  uint32_t ssThresh,
45  uint32_t segmentSize,
46  uint32_t cntRtt,
47  Time maxRtt,
48  uint32_t segmentsAcked,
49  SequenceNumber32 nextTxSeq,
50  SequenceNumber32 lastAckedSeq,
51  const std::string &name);
52 
53 private:
54  virtual void DoRun ();
55  void IncreaseWindow (Ptr<TcpIllinois> cong);
56  void RecalcParam (Ptr<TcpIllinois> cong);
59  void CalculateAlpha (Ptr<TcpIllinois> cong, double da, double dm);
60  void CalculateBeta (Ptr<TcpIllinois> cong, double da, double dm);
61  void GetSsThresh ();
62 
63  uint32_t m_cWnd;
64  uint32_t m_ssThresh;
65  uint32_t m_segmentSize;
68  uint32_t m_segmentsAcked;
71  double m_alpha;
72  double m_beta;
73  uint32_t m_cntRtt;
75  bool m_rttAbove;
76  uint8_t m_rttLow;
77  uint32_t m_ackCnt;
78 };
79 
81  uint32_t ssThresh,
82  uint32_t segmentSize,
83  uint32_t cntRtt,
84  Time maxRtt,
85  uint32_t segmentsAcked,
86  SequenceNumber32 nextTxSeq,
87  SequenceNumber32 lastAckedSeq,
88  const std::string & name)
89  : TestCase (name),
90  m_cWnd (cWnd),
91  m_ssThresh (ssThresh),
92  m_segmentSize (segmentSize),
93  m_baseRtt (MilliSeconds (100)),
94  m_maxRtt (maxRtt),
95  m_segmentsAcked (segmentsAcked),
96  m_nextTxSeq (nextTxSeq),
97  m_lastAckedSeq (lastAckedSeq),
98  m_alpha (0.0),
99  m_beta (0.0),
100  m_cntRtt (cntRtt),
101  m_sumRtt (0),
102  m_rttAbove (false),
103  m_rttLow (0),
104  m_ackCnt (0)
105 {
106 }
107 
108 void
110 {
111  Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
112  state->m_cWnd = m_cWnd;
113  state->m_ssThresh = m_ssThresh;
114  state->m_segmentSize = m_segmentSize;
115  state->m_nextTxSequence = m_nextTxSeq;
116  state->m_lastAckedSeq = m_lastAckedSeq;
117 
118  Ptr<TcpIllinois> cong = CreateObject <TcpIllinois> ();
119 
120  // Set baseRtt to 100 ms
121  cong->PktsAcked (state, m_segmentsAcked, m_baseRtt);
122 
123  m_sumRtt += m_baseRtt;
124 
125  // Set maxRtt and update sumRtt based on cntRtt value
126  for (uint32_t count = 1; count < m_cntRtt; ++count)
127  {
128  cong->PktsAcked (state, m_segmentsAcked, m_maxRtt);
129  m_sumRtt += m_maxRtt;
130  }
131 
132  /*
133  * Test cWnd modification during additive increase
134  */
135  cong->IncreaseWindow (state, m_segmentsAcked);
136  IncreaseWindow (cong);
137  NS_TEST_ASSERT_MSG_EQ (state->m_cWnd.Get (), m_cWnd,
138  "CWnd has not updated correctly");
139 
140  /*
141  * Test ssThresh modification during multiplicative decrease
142  */
143  uint32_t ssThresh = cong->GetSsThresh (state, m_cWnd);
144  GetSsThresh ();
146  "SsThresh has not updated correctly");
147 
148 
149 }
150 
151 void
153 {
154  uint32_t segCwnd = m_cWnd / m_segmentSize;
155 
157  {
158  RecalcParam (cong);
159  }
160  if (m_cWnd < m_ssThresh)
161  { // NewReno slow start
162  if (m_segmentsAcked >= 1)
163  {
165  m_segmentsAcked -= 1;
166  }
167  NS_LOG_INFO ("In SlowStart, updated to cwnd " << m_cWnd <<
168  " ssthresh " << m_ssThresh);
169  }
170  else
171  {
172  uint32_t oldCwnd = segCwnd;
173 
174  if (m_segmentsAcked > 0)
175  {
177  }
178 
179  while (m_ackCnt >= segCwnd)
180  {
181  m_ackCnt -= segCwnd;
182  segCwnd += 1;
183  }
184 
185  if (segCwnd != oldCwnd)
186  {
187  m_cWnd = segCwnd * m_segmentSize;
188  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << m_cWnd <<
189  " ssthresh " << m_ssThresh);
190  }
191  }
192 
193 }
194 
195 void
197 {
198  DoubleValue alphaBase;
199  cong->GetAttribute ("AlphaBase", alphaBase);
200  UintegerValue winThresh;
201  cong->GetAttribute ("WinThresh", winThresh);
202 
203  if (m_cWnd < winThresh.Get ())
204  {
205  NS_LOG_INFO ("cWnd < winThresh, set alpha & beta to base values");
206  m_alpha = alphaBase.Get ();
207  }
208  else if (m_cntRtt > 0)
209  {
210  double dm = (double) CalculateMaxDelay ().GetMilliSeconds ();
211  double da = (double) CalculateAvgDelay ().GetMilliSeconds ();
212 
213  NS_LOG_INFO ("Updated to dm = " << dm << " da = " << da);
214 
215  CalculateAlpha (cong, da, dm);
216  CalculateBeta (cong, da, dm);
217  }
218 }
219 
220 Time
222 {
223  return (m_maxRtt - m_baseRtt);
224 }
225 
226 Time
228 {
229  return (m_sumRtt / m_cntRtt - m_baseRtt);
230 }
231 
232 void
234 {
235  DoubleValue alphaMax;
236  cong->GetAttribute ("AlphaMax", alphaMax);
237  UintegerValue theta;
238  cong->GetAttribute ("Theta", theta);
239  DoubleValue alphaMin;
240  cong->GetAttribute ("AlphaMin", alphaMin);
241 
242  double d1 = dm / 100;
243 
244  if (da <= d1)
245  {
246  if (!m_rttAbove)
247  {
248  m_alpha = alphaMax.Get ();
249  }
250  if (++m_rttLow >= theta.Get ())
251  {
252  m_rttLow = 0;
253  m_rttAbove = false;
254  m_alpha = alphaMax.Get ();
255  }
256  }
257  else
258  {
259  m_rttAbove = true;
260  dm -= d1;
261  da -= d1;
262  m_alpha = (dm * alphaMax.Get ()) / (dm + (da * (alphaMax.Get () - alphaMin.Get ())) / alphaMin.Get ());
263  }
264  NS_LOG_INFO ("Updated to alpha = " << m_alpha);
265 }
266 
267 void
269 {
270  DoubleValue betaMin;
271  cong->GetAttribute ("BetaMin", betaMin);
272  DoubleValue betaMax;
273  cong->GetAttribute ("BetaMax", betaMax);
274 
275  double d2, d3;
276  d2 = dm / 10;
277  d3 = (8 * dm) / 10;
278 
279  if (da <= d2)
280  {
281  m_beta = betaMin.Get ();
282  }
283  else if (da > d2 && da < d3)
284  {
285  m_beta = (betaMin.Get () * d3 - betaMax.Get () * d2 + (betaMax.Get () - betaMin.Get ()) * da) / (d3 - d2);
286  }
287 
288  else if (da >= d3 || d3 <= d2)
289  {
290  m_beta = betaMax.Get ();
291  }
292  NS_LOG_INFO ("Updated to beta = " << m_beta);
293 }
294 
295 void
297 {
298  uint32_t segCwnd = m_cWnd / m_segmentSize;
299  uint32_t ssThresh = std::max (2.0, (1.0 - m_beta) * segCwnd);
300 
301  NS_LOG_DEBUG ("Calculated ssThresh (in segments) = " << ssThresh);
302 
303  m_ssThresh = ssThresh * m_segmentSize;
304 }
305 
306 // -------------------------------------------------------------------
307 static class TcpIllinoisTestSuite : public TestSuite
308 {
309 public:
310  TcpIllinoisTestSuite () : TestSuite ("tcp-illinois-test", UNIT)
311  {
312  AddTestCase (new TcpIllinoisTest (38 * 1446, 40 * 1446, 1446, 2, MilliSeconds (105), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
313  "Illinois test on cWnd and ssThresh when in slow start"),
315  AddTestCase (new TcpIllinoisTest (60 * 346, 40 * 346, 346, 2, MilliSeconds (100), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
316  "Illinois test on cWnd and ssThresh when avg queueing delay is at minimum"),
318  AddTestCase (new TcpIllinoisTest (38 * 1446, 40 * 1446, 1446, 5, MilliSeconds (110), 2, SequenceNumber32 (2893), SequenceNumber32 (5785),
319  "Illinois test on cWnd and ssThresh when avg queueing delay is at maximum"),
321  AddTestCase (new TcpIllinoisTest (40 * 1446, 38 * 1446, 1446, 2, MilliSeconds (105), 55, SequenceNumber32 (2893), SequenceNumber32 (5785),
322  "Illinois test on cWnd and ssThresh when avg queueing delay is in between its min & max"),
324  }
326 
327 } // namespace ns3
void CalculateBeta(Ptr< TcpIllinois > cong, double da, double dm)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
virtual void DoRun()
Implementation to actually run this TestCase.
uint64_t Get(void) const
Definition: uinteger.cc:35
#define max(a, b)
Definition: 80211b.c:45
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
void RecalcParam(Ptr< TcpIllinois > cong)
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:161
void CalculateAlpha(Ptr< TcpIllinois > cong, double da, double dm)
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)
double Get(void) const
Definition: double.cc:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpIllinoisTestSuite g_tcpIllinoisTest
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
void IncreaseWindow(Ptr< TcpIllinois > cong)
SequenceNumber32 m_nextTxSeq
SequenceNumber32 m_lastAckedSeq
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
Testing TcpIllinois C-AIMD algorithm.