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
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE ("TcpIllinoisTestSuite");
36
44{
45public:
59 uint32_t ssThresh,
61 uint32_t cntRtt,
62 Time maxRtt,
63 uint32_t segmentsAcked,
64 SequenceNumber32 nextTxSeq,
65 SequenceNumber32 lastAckedSeq,
66 const std::string &name);
67
68private:
69 virtual void DoRun ();
79 void RecalcParam (Ptr<TcpIllinois> cong);
96 void CalculateAlpha (Ptr<TcpIllinois> cong, double da, double dm);
103 void CalculateBeta (Ptr<TcpIllinois> cong, double da, double dm);
107 void GetSsThresh ();
108
117 double m_alpha;
118 double m_beta;
122 uint8_t m_rttLow;
124};
125
127 uint32_t ssThresh,
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
154void
156{
157 Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
158 state->m_cWnd = m_cWnd;
159 state->m_ssThresh = m_ssThresh;
163
164 Ptr<TcpIllinois> cong = CreateObject <TcpIllinois> ();
165
166 // Set baseRtt to 100 ms
167 cong->PktsAcked (state, m_segmentsAcked, m_baseRtt);
168
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);
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
197void
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
241void
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
266Time
268{
269 return (m_maxRtt - m_baseRtt);
270}
271
272Time
274{
275 return (m_sumRtt / m_cntRtt - m_baseRtt);
276}
277
278void
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
313void
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
341void
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{
362public:
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
#define max(a, b)
Definition: 80211b.c:43
TcpIllinois C-AIMD algorithm tests.
Time CalculateAvgDelay()
Calculate the average delay.
Time CalculateMaxDelay()
Calculate the maximum delay.
void CalculateAlpha(Ptr< TcpIllinois > cong, double da, double dm)
Calculate the TCP Illinois alpha param.
SequenceNumber32 m_lastAckedSeq
Last ACKed sequence number.
void RecalcParam(Ptr< TcpIllinois > cong)
Recalculate the internal TCP Illinois params.
Time m_baseRtt
Base RTT.
uint32_t m_ackCnt
ACK counter.
virtual void DoRun()
Implementation to actually run this TestCase.
void IncreaseWindow(Ptr< TcpIllinois > cong)
Increases the TCP window.
Time m_maxRtt
Max RTT.
SequenceNumber32 m_nextTxSeq
Next Tx sequence number.
uint8_t m_rttLow
RTT low counter.
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.
uint32_t m_cntRtt
RTT counter.
uint32_t m_cWnd
Congestion window.
bool m_rttAbove
RTT above threshold.
void CalculateBeta(Ptr< TcpIllinois > cong, double da, double dm)
Calculate the TCP Illinois beta param.
Time m_sumRtt
Sum of all the RTTs.
void GetSsThresh()
brief Get and check the SSH threshold.
double m_alpha
TCP Illinois alpha parameter.
uint32_t m_ssThresh
Slow Start Threshold.
double m_beta
TCP Illinois beta parameter.
uint32_t m_segmentSize
Segment size.
uint32_t m_segmentsAcked
Number of segments ACKed.
TCP Illinois TestSuite.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
double Get(void) const
Definition: double.cc:35
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
uint32_t m_segmentSize
Segment size.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
Hold an unsigned integer type.
Definition: uinteger.h:44
uint64_t Get(void) const
Definition: uinteger.cc:35
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#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:141
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpIllinoisTestSuite g_tcpIllinoisTest
Static variable for test initialization.