A Discrete-Event Network Simulator
API
tcp-yeah.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 "tcp-yeah.h"
28 #include "ns3/tcp-socket-base.h"
29 #include "ns3/log.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("TcpYeah");
35 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::TcpYeah")
42  .AddConstructor<TcpYeah> ()
43  .SetGroupName ("Internet")
44  .AddAttribute ("Alpha", "Maximum backlog allowed at the bottleneck queue",
45  UintegerValue (80),
47  MakeUintegerChecker<uint32_t> ())
48  .AddAttribute ("Gamma", "Fraction of queue to be removed per RTT",
49  UintegerValue (1),
51  MakeUintegerChecker<uint32_t> ())
52  .AddAttribute ("Delta", "Log minimum fraction of cwnd to be removed on loss",
53  UintegerValue (3),
55  MakeUintegerChecker<uint32_t> ())
56  .AddAttribute ("Epsilon", "Log maximum fraction to be removed on early decongestion",
57  UintegerValue (1),
59  MakeUintegerChecker<uint32_t> ())
60  .AddAttribute ("Phy", "Maximum delta from base",
61  UintegerValue (8),
63  MakeUintegerChecker<uint32_t> ())
64  .AddAttribute ("Rho", "Minimum # of consecutive RTT to consider competition on loss",
65  UintegerValue (16),
67  MakeUintegerChecker<uint32_t> ())
68  .AddAttribute ("Zeta", "Minimum # of state switches to reset m_renoCount",
69  UintegerValue (50),
71  MakeUintegerChecker<uint32_t> ())
72  .AddAttribute ("StcpAiFactor", "STCP additive increase factor",
73  UintegerValue (100),
75  MakeUintegerChecker<uint32_t> ())
76  ;
77  return tid;
78 }
79 
81  : TcpNewReno (),
82  m_alpha (80),
83  m_gamma (1),
84  m_delta (3),
85  m_epsilon (1),
86  m_phy (8),
87  m_rho (16),
88  m_zeta (50),
89  m_stcpAiFactor (100),
90  m_stcp (0),
91  m_baseRtt (Time::Max ()),
92  m_minRtt (Time::Max ()),
93  m_cntRtt (0),
94  m_doingYeahNow (true),
95  m_begSndNxt (0),
96  m_lastQ (0),
97  m_doingRenoNow (0),
98  m_renoCount (2),
99  m_fastCount (0)
100 {
101  NS_LOG_FUNCTION (this);
102  m_stcp = CreateObject <TcpScalable> ();
103  m_stcp->SetAttribute ("AIFactor", (UintegerValue) m_stcpAiFactor);
104 }
105 
107  : TcpNewReno (sock),
108  m_alpha (sock.m_alpha),
109  m_gamma (sock.m_gamma),
110  m_delta (sock.m_delta),
111  m_epsilon (sock.m_epsilon),
112  m_phy (sock.m_phy),
113  m_rho (sock.m_rho),
114  m_zeta (sock.m_zeta),
115  m_stcpAiFactor (sock.m_stcpAiFactor),
116  m_baseRtt (sock.m_baseRtt),
117  m_minRtt (sock.m_minRtt),
118  m_cntRtt (sock.m_cntRtt),
119  m_doingYeahNow (sock.m_doingYeahNow),
120  m_begSndNxt (sock.m_begSndNxt),
121  m_lastQ (sock.m_lastQ),
122  m_doingRenoNow (sock.m_doingRenoNow),
123  m_renoCount (sock.m_renoCount),
124  m_fastCount (sock.m_fastCount)
125 {
126  NS_LOG_FUNCTION (this);
127  m_stcp = CopyObject (sock.m_stcp);
128 }
129 
131 {
132  NS_LOG_FUNCTION (this);
133 }
134 
137 {
138  return CopyObject<TcpYeah> (this);
139 }
140 
141 void
142 TcpYeah::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
143  const Time& rtt)
144 {
145  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
146 
147  if (rtt.IsZero ())
148  {
149  return;
150  }
151 
152  m_minRtt = std::min (m_minRtt, rtt);
153  NS_LOG_DEBUG ("Updated m_minRtt = " << m_minRtt.GetMilliSeconds () << " ms");
154 
155  m_baseRtt = std::min (m_baseRtt, rtt);
156  NS_LOG_DEBUG ("Updated m_baseRtt = " << m_baseRtt.GetMilliSeconds () << " ms");
157 
158  // Update RTT counter
159  m_cntRtt++;
160  NS_LOG_DEBUG ("Updated m_cntRtt = " << m_cntRtt);
161 }
162 
163 void
164 TcpYeah::EnableYeah (const SequenceNumber32 &nextTxSequence)
165 {
166  NS_LOG_FUNCTION (this << nextTxSequence);
167 
168  m_doingYeahNow = true;
169  m_begSndNxt = nextTxSequence;
170  m_cntRtt = 0;
171  m_minRtt = Time::Max ();
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION (this);
178 
179  m_doingYeahNow = false;
180 }
181 
182 void
184  const TcpSocketState::TcpCongState_t newState)
185 {
186  NS_LOG_FUNCTION (this << tcb << newState);
187 
188  if (newState == TcpSocketState::CA_OPEN)
189  {
190  EnableYeah (tcb->m_nextTxSequence);
191  }
192  else
193  {
194  DisableYeah ();
195  }
196 }
197 
198 void
199 TcpYeah::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
200 {
201  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
202 
203  if (tcb->m_cWnd < tcb->m_ssThresh)
204  {
205  NS_LOG_LOGIC ("In slow start, invoke NewReno slow start.");
206  segmentsAcked = TcpNewReno::SlowStart (tcb, segmentsAcked);
207  }
208  else if (!m_doingRenoNow)
209  { // Fast mode
210  NS_LOG_LOGIC ("In Fast mode, increment cwnd according to STCP rule.");
211  m_stcp->IncreaseWindow (tcb, segmentsAcked);
212  NS_LOG_INFO ("In Fast mode, updated to cwnd " << tcb->m_cWnd <<
213  " ssthresh " << tcb->m_ssThresh);
214  }
215  else
216  { // Behave like NewReno
217  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
218  }
219 
220  if (tcb->m_lastAckedSeq >= m_begSndNxt)
221  { // A YeAH cycle has finished, we do YeAH cwnd adjustment every RTT.
222 
223  NS_LOG_LOGIC ("A YeAH cycle has finished, check if enough RTT samples.");
224  /*
225  * We perform YeAH calculations only if we got enough RTT samples to
226  * insure that at least 1 of those samples wasn't from a delayed ACK.
227  */
228  if (m_cntRtt > 2)
229  {
230  NS_LOG_LOGIC ("Enough RTT samples to perform YeAH calculations");
231  /*
232  * We have enough RTT samples to perform YeAH algorithm.
233  * Now we need to determine if we should operate in Fast or Slow mode,
234  * and if we should execute the precautionary decongestion algorithm.
235  */
236 
237  uint32_t segCwnd = tcb->GetCwndInSegments ();
238 
239  // Calculate the extra number of packets in queue
240  // Naming convention: minRtt is the minimum RTT of this round,
241  // baseRtt is the minimum RTT of the entire transmission.
243  Time rttQueue = m_minRtt - m_baseRtt;
244 
245  // queue = rttQueue * bw = rttQueue * (cwnd/RTTmin)
246  double bw = segCwnd / m_minRtt.GetSeconds ();
247  uint32_t queue = bw * rttQueue.GetSeconds ();
248  NS_LOG_DEBUG ("Queue backlog = " << queue <<
249  " given by cwnd = " << segCwnd <<
250  ", minRtt = " << m_minRtt.GetMilliSeconds () <<
251  " ms, baseRtt = " << m_baseRtt.GetMilliSeconds () <<
252  " ms");
253 
254  double L = rttQueue.GetSeconds () / m_baseRtt.GetSeconds ();
255  NS_LOG_DEBUG ("Network congestion level = " << L);
256 
257  if (queue > m_alpha || L > (1 / m_phy) )
258  { // Slow mode
259  if (queue > m_alpha && segCwnd > m_renoCount)
260  { // Precautionary decongestion
261  NS_LOG_LOGIC ("Execute the precautionary decongestion.");
262  uint32_t reduction = std::min (queue / m_gamma, segCwnd >> m_epsilon);
263  segCwnd -= reduction;
264  segCwnd = std::max (segCwnd, m_renoCount);
265  tcb->m_cWnd = segCwnd * tcb->m_segmentSize;
266  tcb->m_ssThresh = tcb->m_cWnd;
267 
268  NS_LOG_INFO ("In Slow mode, after precautionary decongestion, "
269  "updated to cwnd " << tcb->m_cWnd <<
270  " ssthresh " << tcb->m_ssThresh);
271  }
272 
273  if (m_renoCount <= 2)
274  {
275  m_renoCount = std::max (segCwnd >> 1, (uint32_t) 2);
276  }
277  else
278  {
279  m_renoCount++;
280  }
281 
283  NS_LOG_DEBUG ("In Slow mode, updated to m_renoCount = " <<
284  m_renoCount << " m_doingRenoNow = " << m_doingRenoNow);
285  }
286  else
287  { // Fast mode
288  m_fastCount++;
289  if (m_fastCount > m_zeta)
290  { // Reset renoCount
291  m_renoCount = 2;
292  m_fastCount = 0;
293  }
294  m_doingRenoNow = 0;
295  NS_LOG_DEBUG ("In Fast mode, updated to m_renoCount = " <<
296  m_renoCount << " m_doingRenoNow = " << m_doingRenoNow);
297  }
298  m_lastQ = queue;
299  }
300 
301  // Save the current right edge for next Yeah cycle
302  m_begSndNxt = tcb->m_nextTxSequence;
303 
304  // Reset cntRtt & minRtt
305  m_cntRtt = 0;
306  m_minRtt = Time::Max ();
307  }
308 }
309 
310 std::string
312 {
313  return "TcpYeah";
314 }
315 
316 uint32_t
318  uint32_t bytesInFlight)
319 {
320  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
321  uint32_t reduction;
322  uint32_t segBytesInFlight = bytesInFlight / tcb->m_segmentSize;
323 
324  if (m_doingRenoNow < m_rho)
325  { // Not competing with Reno flows
326  NS_LOG_LOGIC ("Not competing with Reno flows upon loss");
327  reduction = m_lastQ;
328  reduction = std::max (reduction, segBytesInFlight >> m_delta);
329  reduction = std::min (reduction, std::max (segBytesInFlight >> 1, (uint32_t) 2));
330  }
331  else
332  { // Competing with Reno flows
333  NS_LOG_LOGIC ("Competing with Reno flows upon loss");
334  reduction = std::max (segBytesInFlight >> 1, (uint32_t) 2);
335  }
336 
337  NS_LOG_INFO ("Reduction amount upon loss = " << reduction);
338 
339  m_fastCount = 0;
340  m_renoCount = std::max (m_renoCount >> 1, (uint32_t) 2);
341 
342  return (bytesInFlight - (reduction * tcb->m_segmentSize));
343 }
344 
345 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint32_t m_stcpAiFactor
STCP additive increase parameter.
Definition: tcp-yeah.h:174
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Normal state, no dubious events.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
TcpYeah(void)
Create an unbound tcp socket.
Definition: tcp-yeah.cc:80
#define min(a, b)
Definition: 80211b.c:44
uint32_t m_fastCount
Number of RTTs in "Fast" mode.
Definition: tcp-yeah.h:184
bool IsZero(void) const
Definition: nstime.h:274
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Enable/disable YeAH algorithm depending on the congestion state.
Definition: tcp-yeah.cc:183
uint32_t m_epsilon
Log maximum fraction to be removed on early decongestion.
Definition: tcp-yeah.h:169
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void DisableYeah()
Stop taking YeAH samples.
Definition: tcp-yeah.cc:175
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
uint32_t m_delta
Log minimum fraction of cwnd to be removed on loss.
Definition: tcp-yeah.h:168
The NewReno implementation.
uint32_t m_gamma
Fraction of queue to be removed per RTT when precautionary decongestion executed. ...
Definition: tcp-yeah.h:167
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Compute RTTs needed to execute YeAH algorithm.
Definition: tcp-yeah.cc:142
static Time Max()
Maximum representable Time.
Definition: nstime.h:259
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
Time m_minRtt
Minimum of all RTTs measured within last RTT.
Definition: tcp-yeah.h:177
#define max(a, b)
Definition: 80211b.c:45
An implementation of TCP YeAH.
Definition: tcp-yeah.h:72
Hold an unsigned integer type.
Definition: uinteger.h:44
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
uint32_t m_cntRtt
Number of RTT measurements during last RTT.
Definition: tcp-yeah.h:178
uint32_t m_phy
Maximum delta from base.
Definition: tcp-yeah.h:170
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-yeah.cc:311
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition: object.h:497
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
uint32_t m_renoCount
Estimated cwnd of competing Reno flow.
Definition: tcp-yeah.h:183
TcpCongState_t
Definition of the Congestion state machine.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void EnableYeah(const SequenceNumber32 &nextTxSequence)
Enable YeAH algorithm to start taking YeAH samples.
Definition: tcp-yeah.cc:164
uint32_t m_lastQ
Last number of packets in the bottleneck queue.
Definition: tcp-yeah.h:181
Time m_baseRtt
Minimum of all YeAH RTT measurements seen during connection.
Definition: tcp-yeah.h:176
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-yeah.cc:136
uint32_t m_rho
Minimum number of consecutive RTT to consider competition with Reno flows on loss.
Definition: tcp-yeah.h:171
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following YeAH dual-mode algorithm.
Definition: tcp-yeah.cc:199
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
bool m_doingYeahNow
If true, do YeAH for this RTT.
Definition: tcp-yeah.h:179
uint32_t m_zeta
Minimum number of state switches to reset m_renoCount.
Definition: tcp-yeah.h:172
Ptr< TcpScalable > m_stcp
TcpScalable object.
Definition: tcp-yeah.h:175
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-yeah.cc:38
SequenceNumber32 m_begSndNxt
Right edge during last RTT.
Definition: tcp-yeah.h:180
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:904
uint32_t m_alpha
Maximum backlog allowed at the bottleneck queue; Q_max in the paper.
Definition: tcp-yeah.h:166
uint32_t m_doingRenoNow
Number of RTTs in "Slow" mode.
Definition: tcp-yeah.h:182
virtual ~TcpYeah(void)
Definition: tcp-yeah.cc:130
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold upon the receipt of 3 dupACKs.
Definition: tcp-yeah.cc:317