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