A Discrete-Event Network Simulator
API
tcp-illinois.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: Keerthi Ganta <keerthiganta@ku.edu>
19  * Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
20  *
21  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
22  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
23  * Information and Telecommunication Technology Center (ITTC)
24  * and Department of Electrical Engineering and Computer Science
25  * The University of Kansas Lawrence, KS USA.
26  */
27 
28 
29 #include "tcp-illinois.h"
30 #include "ns3/tcp-socket-base.h"
31 #include "ns3/log.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpIllinois");
36 NS_OBJECT_ENSURE_REGISTERED (TcpIllinois);
37 
38 TypeId
40 {
41  static TypeId tid = TypeId ("ns3::TcpIllinois")
43  .AddConstructor<TcpIllinois> ()
44  .SetGroupName ("Internet")
45  .AddAttribute ("AlphaMin", "Minimum alpha threshold",
46  DoubleValue (0.3),
48  MakeDoubleChecker<double> ())
49  .AddAttribute ("AlphaMax", "Maximum alpha threshold",
50  DoubleValue (10.0),
52  MakeDoubleChecker<double> ())
53  .AddAttribute ("AlphaBase", "Alpha base threshold",
54  DoubleValue (1.0),
56  MakeDoubleChecker<double> ())
57  .AddAttribute ("BetaMin", "Minimum beta threshold",
58  DoubleValue (0.125),
60  MakeDoubleChecker<double> ())
61  .AddAttribute ("BetaMax", "Maximum beta threshold",
62  DoubleValue (0.5),
64  MakeDoubleChecker<double> ())
65  .AddAttribute ("BetaBase", "Beta base threshold",
66  DoubleValue (0.5),
68  MakeDoubleChecker<double> ())
69  .AddAttribute ("WinThresh", "Window threshold",
70  UintegerValue (15),
72  MakeUintegerChecker<uint32_t> ())
73  .AddAttribute ("Theta", "Theta threshold",
74  UintegerValue (5),
76  MakeUintegerChecker<uint32_t> ())
77  ;
78  return tid;
79 }
80 
82  : TcpNewReno (),
83  m_sumRtt (Time (0)),
84  m_cntRtt (0),
85  m_baseRtt (Time::Max ()),
86  m_maxRtt (Time::Min ()),
87  m_endSeq (0),
88  m_rttAbove (false),
89  m_rttLow (0),
90  m_alphaMin (0.3),
91  m_alphaMax (10.0),
92  m_alphaBase (1.0),
93  m_alpha (m_alphaMax),
94  m_betaMin (0.125),
95  m_betaMax (0.5),
96  m_betaBase (0.5),
97  m_beta (m_betaBase),
98  m_winThresh (15),
99  m_theta (5),
100  m_ackCnt (0)
101 {
102  NS_LOG_FUNCTION (this);
103 }
104 
106  : TcpNewReno (sock),
107  m_sumRtt (sock.m_sumRtt),
108  m_cntRtt (sock.m_cntRtt),
109  m_baseRtt (sock.m_baseRtt),
110  m_maxRtt (sock.m_maxRtt),
111  m_endSeq (sock.m_endSeq),
112  m_rttAbove (sock.m_rttAbove),
113  m_rttLow (sock.m_rttLow),
114  m_alphaMin (sock.m_alphaMin),
115  m_alphaMax (sock.m_alphaMax),
116  m_alphaBase (sock.m_alphaBase),
117  m_alpha (sock.m_alpha),
118  m_betaMin (sock.m_betaMin),
119  m_betaMax (sock.m_betaMax),
120  m_betaBase (sock.m_betaBase),
121  m_beta (sock.m_beta),
122  m_winThresh (sock.m_winThresh),
123  m_theta (sock.m_theta),
124  m_ackCnt (sock.m_ackCnt)
125 {
126  NS_LOG_FUNCTION (this);
127 }
128 
130 {
131  NS_LOG_FUNCTION (this);
132 }
133 
134 void
136 {
137  NS_LOG_FUNCTION (this << cWnd);
138 
139  if (cWnd < m_winThresh)
140  {
141  NS_LOG_INFO ("cWnd < winThresh, set alpha & beta to base values");
142 
144  m_beta = m_betaBase;
145  }
146  else if (m_cntRtt > 0)
147  {
148  double dm = static_cast<double> (CalculateMaxDelay ().GetMilliSeconds ());
149  double da = static_cast<double> (CalculateAvgDelay ().GetMilliSeconds ());
150 
151  NS_LOG_INFO ("Updated to dm = " << dm << " da = " << da);
152 
153  CalculateAlpha (da, dm);
154  CalculateBeta (da, dm);
155  }
156 }
157 
158 void
160  const TcpSocketState::TcpCongState_t newState)
161 {
162  NS_LOG_FUNCTION (this << tcb << newState);
163 
164  if (newState == TcpSocketState::CA_LOSS)
165  {
167  m_beta = m_betaBase;
168  m_rttLow = 0;
169  m_rttAbove = false;
170  Reset (tcb->m_nextTxSequence);
171  }
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION (this << segmentsAcked);
178 
179  if (tcb->m_lastAckedSeq >= m_endSeq)
180  {
181  RecalcParam (tcb->m_cWnd);
182  Reset (tcb->m_nextTxSequence);
183  }
184 
185  if (tcb->m_cWnd < tcb->m_ssThresh)
186  {
187  TcpNewReno::SlowStart (tcb, segmentsAcked);
188  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd <<
189  " ssthresh " << tcb->m_ssThresh);
190  }
191  else
192  {
193  uint32_t segCwnd = tcb->GetCwndInSegments ();
194  uint32_t oldCwnd = segCwnd;
195 
196  if (segmentsAcked > 0)
197  {
198  m_ackCnt += segmentsAcked * m_alpha;
199  }
200 
201  while (m_ackCnt >= segCwnd)
202  {
203  m_ackCnt -= segCwnd;
204  segCwnd += 1;
205  }
206 
207  if (segCwnd != oldCwnd)
208  {
209  tcb->m_cWnd = segCwnd * tcb->m_segmentSize;
210  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
211  " ssthresh " << tcb->m_ssThresh);
212  }
213  }
214 }
215 
216 void
217 TcpIllinois::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t packetsAcked,
218  const Time &rtt)
219 {
220  NS_LOG_FUNCTION (this << tcb << packetsAcked << rtt);
221 
222  if (rtt.IsZero ())
223  {
224  return;
225  }
226 
227  // Keep track of minimum RTT
228  m_baseRtt = std::min (m_baseRtt, rtt);
229 
230  // Keep track of maximum RTT
231  m_maxRtt = std::max (rtt, m_maxRtt);
232 
233  ++m_cntRtt;
234  m_sumRtt += rtt;
235 
236  NS_LOG_INFO ("Updated baseRtt = " << m_baseRtt << " maxRtt = " << m_maxRtt <<
237  " cntRtt = " << m_cntRtt << " sumRtt = " << m_sumRtt);
238 }
239 
240 uint32_t
242 {
243  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
244 
245  uint32_t segBytesInFlight = bytesInFlight / tcb->m_segmentSize;
246  uint32_t ssThresh = std::max (2.0, (1.0 - m_beta) * segBytesInFlight);
247 
248  NS_LOG_DEBUG ("Calculated ssThresh (in segments) = " << ssThresh);
249 
250  return ssThresh * tcb->m_segmentSize;
251 }
252 
253 void
254 TcpIllinois::CalculateAlpha (double da, double dm)
255 {
256  NS_LOG_FUNCTION (this << da << dm);
257 
258  double d1 = dm / 100;
259 
260  if (da <= d1)
261  {
262  NS_LOG_INFO ("da <= d1");
263 
264  if (!m_rttAbove)
265  { // In case we can't get out of this low delay zone, we use alphaMax
267  }
268  if (++m_rttLow >= m_theta)
269  {
270  /*
271  * da needs to stay below d1 for theta times RTT amount of time
272  * before we can increase alpha to alphaMax
273  */
274  NS_LOG_INFO ("da stays below d1 for theta times RTT amount of time, "
275  "increase alpha to alphaMax");
276 
277  m_rttLow = 0;
278  m_rttAbove = false;
280  }
281  }
282  else
283  {
284  NS_LOG_INFO ("da > d1");
285 
286  m_rttAbove = true;
287  /*
288  * alpha = k1 / (k2 + da), where
289  * k1 = ((dm - d1) * alphaMin * alphaMax) / (alphaMax - alphaMin)
290  * k2 = (((dm - d1) * alphaMin) / (alphaMax - alphaMin)) - d1
291  */
292  dm -= d1;
293  da -= d1;
294  m_alpha = (dm * m_alphaMax) / (dm + (da * (m_alphaMax - m_alphaMin)) / m_alphaMin);
295  }
296 
297  NS_LOG_INFO ("Updated to alpha = " << m_alpha);
298 }
299 
300 void
301 TcpIllinois::CalculateBeta (double da, double dm)
302 {
303  NS_LOG_FUNCTION (this << da << dm);
304 
305  double d2, d3;
306 
307  d2 = dm / 10;
308  d3 = (8 * dm) / 10;
309 
310  if (da <= d2)
311  {
312  NS_LOG_INFO ("da <= d2");
313 
314  m_beta = m_betaMin;
315  }
316 
317  else if (da > d2 && da < d3)
318  {
319  NS_LOG_INFO ("da > d2 && da < d3");
320 
321  /*
322  * beta = k3 + k4 * da, where
323  * k3 = (betaMin * d3 - betaMax * d2) / (d3 - d2)
324  * k4 = (betaMax - betaMin) / (d3 - d2)
325  */
326  m_beta = (m_betaMin * d3 - m_betaMax * d2 + (m_betaMax - m_betaMin) * da) / (d3 - d2);
327 
328  }
329 
330  else if (da >= d3 || d3 <= d2)
331  {
332  NS_LOG_INFO ("da >= d3 || d3 <= d2");
333 
334  m_beta = m_betaMax;
335  }
336 
337  NS_LOG_INFO ("Updated to beta = " << m_beta);
338 }
339 
340 Time
342 {
343  NS_LOG_FUNCTION (this);
344 
345  return (m_sumRtt / m_cntRtt - m_baseRtt);
346 }
347 
348 Time
350 {
351  NS_LOG_FUNCTION (this);
352 
353  return (m_maxRtt - m_baseRtt);
354 }
355 
356 void
357 TcpIllinois::Reset (const SequenceNumber32 &nextTxSequence)
358 {
359  NS_LOG_FUNCTION (this << nextTxSequence);
360 
361  m_endSeq = nextTxSequence;
362  m_cntRtt = 0;
363  m_sumRtt = Time (0);
364 }
365 
368 {
369  NS_LOG_FUNCTION (this);
370 
371  return CopyObject<TcpIllinois> (this);
372 }
373 
374 std::string
376 {
377  NS_LOG_FUNCTION (this);
378 
379  return "TcpIllinois";
380 }
381 
382 } // namespace ns3
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Time m_baseRtt
Minimum of all RTT measurements.
Definition: tcp-illinois.h:230
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
double m_beta
Multiplicative decrease factor.
Definition: tcp-illinois.h:242
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void Reset(const SequenceNumber32 &nextTxSequence)
Reset Illinois parameters.
double m_betaMax
Maximum beta threshold.
Definition: tcp-illinois.h:240
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold after congestion event.
#define min(a, b)
Definition: 80211b.c:44
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Illinois congestion avoidance algorithm.
Time CalculateMaxDelay() const
Calculate maximum queueing delay.
uint32_t m_ackCnt
Number of received ACK.
Definition: tcp-illinois.h:245
bool IsZero(void) const
Definition: nstime.h:274
bool m_rttAbove
True when da > d1.
Definition: tcp-illinois.h:233
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void CalculateAlpha(double da, double dm)
Calculate additive increase factor alpha.
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:277
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:719
double m_alpha
Additive increase factor.
Definition: tcp-illinois.h:238
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
The NewReno implementation.
Time m_sumRtt
Sum of all RTT measurements during last RTT.
Definition: tcp-illinois.h:228
uint32_t m_theta
Number of RTTs required before setting alpha to its max.
Definition: tcp-illinois.h:244
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
#define max(a, b)
Definition: 80211b.c:45
Time CalculateAvgDelay() const
Calculate average queueing delay.
double m_alphaBase
Base value of alpha for standard AIMD.
Definition: tcp-illinois.h:237
double m_alphaMin
Minimum alpha threshold.
Definition: tcp-illinois.h:235
Hold an unsigned integer type.
Definition: uinteger.h:44
double m_alphaMax
Maximum alpha threshold.
Definition: tcp-illinois.h:236
void CalculateBeta(double da, double dm)
Calculate multiplicative decrease factor beta.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
Time m_maxRtt
Maximum of all RTT measurements.
Definition: tcp-illinois.h:231
TcpIllinois(void)
Create an unbound tcp socket.
Definition: tcp-illinois.cc:81
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
TcpCongState_t
Definition of the Congestion state machine.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~TcpIllinois(void)
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Reset Illinois parameters to default values upon a loss.
TracedValue< uint32_t > m_cWnd
Congestion window.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
uint32_t m_cntRtt
Number of RTT measurements during last RTT.
Definition: tcp-illinois.h:229
SequenceNumber32 m_endSeq
Right edge of current RTT.
Definition: tcp-illinois.h:232
double m_betaMin
Minimum beta threshold.
Definition: tcp-illinois.h:239
double m_betaBase
Base value of beta for standard AIMD.
Definition: tcp-illinois.h:241
CWND was reduced due to RTO timeout or SACK reneging.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
void RecalcParam(uint32_t cWnd)
Recalculate alpha and beta every RTT.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-illinois.cc:39
uint32_t m_winThresh
Window threshold for adaptive sizing.
Definition: tcp-illinois.h:243
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Measure RTT for each ACK Keep track of min and max RTT.
An implementation of TCP Illinois algorithm.
Definition: tcp-illinois.h:106
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
uint8_t m_rttLow
Number of RTTs da has stayed below d1.
Definition: tcp-illinois.h:234
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.