A Discrete-Event Network Simulator
API
tcp-bic.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com>
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  */
19 #include "tcp-bic.h"
20 #include "ns3/log.h"
21 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("TcpBic");
26 
27 TypeId
29 {
30  static TypeId tid = TypeId ("ns3::TcpBic")
32  .AddConstructor<TcpBic> ()
33  .SetGroupName ("Internet")
34  .AddAttribute ("FastConvergence", "Turn on/off fast convergence.",
35  BooleanValue (true),
38  .AddAttribute ("Beta", "Beta for multiplicative decrease",
39  DoubleValue (0.8),
41  MakeDoubleChecker <double> (0.0))
42  .AddAttribute ("MaxIncr", "Limit on increment allowed during binary search",
43  UintegerValue (16),
45  MakeUintegerChecker <uint32_t> (1))
46  .AddAttribute ("LowWnd", "Threshold window size (in segments) for engaging BIC response",
47  UintegerValue (14),
49  MakeUintegerChecker <uint32_t> ())
50  .AddAttribute ("SmoothPart", "Number of RTT needed to approach cWnd_max from "
51  "cWnd_max-BinarySearchCoefficient. It can be viewed as the gradient "
52  "of the slow start AIM phase: less this value is, "
53  "more steep the increment will be.",
54  UintegerValue (5),
56  MakeUintegerChecker <uint32_t> (1))
57  .AddAttribute ("BinarySearchCoefficient", "Inverse of the coefficient for the "
58  "binary search. Default 4, as in Linux",
59  UintegerValue (4),
61  MakeUintegerChecker <uint8_t> (2))
62  ;
63  return tid;
64 }
65 
66 
68  : TcpCongestionOps (),
69  m_cWndCnt (0),
70  m_lastMaxCwnd (0),
71  m_lastCwnd (0),
72  m_epochStart (Time::Min ())
73 {
74  NS_LOG_FUNCTION (this);
75 }
76 
77 TcpBic::TcpBic (const TcpBic &sock)
78  : TcpCongestionOps (sock),
79  m_fastConvergence (sock.m_fastConvergence),
80  m_beta (sock.m_beta),
81  m_maxIncr (sock.m_maxIncr),
82  m_lowWnd (sock.m_lowWnd),
83  m_smoothPart (sock.m_smoothPart),
84  m_cWndCnt (sock.m_cWndCnt),
85  m_lastMaxCwnd (sock.m_lastMaxCwnd),
86  m_lastCwnd (sock.m_lastCwnd),
87  m_epochStart (sock.m_epochStart),
88  m_b (sock.m_b)
89 {
90  NS_LOG_FUNCTION (this);
91 }
92 
93 
94 void
95 TcpBic::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
96 {
97  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
98 
99  if (tcb->m_cWnd < tcb->m_ssThresh)
100  {
101  tcb->m_cWnd += tcb->m_segmentSize;
102  segmentsAcked -= 1;
103 
104  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd <<
105  " ssthresh " << tcb->m_ssThresh);
106  }
107 
108  if (tcb->m_cWnd >= tcb->m_ssThresh && segmentsAcked > 0)
109  {
110  m_cWndCnt += segmentsAcked;
111  uint32_t cnt = Update (tcb);
112 
113  /* According to the BIC paper and RFC 6356 even once the new cwnd is
114  * calculated you must compare this to the number of ACKs received since
115  * the last cwnd update. If not enough ACKs have been received then cwnd
116  * cannot be updated.
117  */
118  if (m_cWndCnt > cnt)
119  {
120  tcb->m_cWnd += tcb->m_segmentSize;
121  m_cWndCnt = 0;
122  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd);
123  }
124  else
125  {
126  NS_LOG_INFO ("Not enough segments have been ACKed to increment cwnd."
127  "Until now " << m_cWndCnt);
128  }
129  }
130 }
131 
132 uint32_t
134 {
135  NS_LOG_FUNCTION (this << tcb);
136 
137  uint32_t segCwnd = tcb->GetCwndInSegments ();
138  uint32_t cnt;
139 
140  m_lastCwnd = segCwnd;
141 
142  if (m_epochStart == Time::Min ())
143  {
144  m_epochStart = Simulator::Now (); /* record the beginning of an epoch */
145  }
146 
147  if (segCwnd < m_lowWnd)
148  {
149  NS_LOG_INFO ("Under lowWnd, compatibility mode. Behaving as NewReno");
150  cnt = segCwnd;
151  return cnt;
152  }
153 
154  if (segCwnd < m_lastMaxCwnd)
155  {
156  double dist = (m_lastMaxCwnd - segCwnd) / m_b;
157 
158  NS_LOG_INFO ("cWnd = " << segCwnd << " under lastMax, " <<
159  m_lastMaxCwnd << " and dist=" << dist);
160  if (dist > m_maxIncr)
161  {
162  /* Linear increase */
163  cnt = segCwnd / m_maxIncr;
164  NS_LOG_INFO ("Linear increase (maxIncr=" << m_maxIncr << "), cnt=" << cnt);
165  }
166  else if (dist <= 1)
167  {
168  /* smoothed binary search increase: when our window is really
169  * close to the last maximum, we parameterize in m_smoothPart the number
170  * of RTT needed to reach that window.
171  */
172  cnt = (segCwnd * m_smoothPart) / m_b;
173 
174  NS_LOG_INFO ("Binary search increase (smoothPart=" << m_smoothPart <<
175  "), cnt=" << cnt);
176  }
177  else
178  {
179  /* binary search increase */
180  cnt = static_cast<uint32_t> (segCwnd / dist);
181 
182  NS_LOG_INFO ("Binary search increase, cnt=" << cnt);
183  }
184  }
185  else
186  {
187  NS_LOG_INFO ("cWnd = " << segCwnd << " above last max, " <<
188  m_lastMaxCwnd);
189  if (segCwnd < m_lastMaxCwnd + m_b)
190  {
191  /* slow start AMD linear increase */
192  cnt = (segCwnd * m_smoothPart) / m_b;
193  NS_LOG_INFO ("Slow start AMD, cnt=" << cnt);
194  }
195  else if (segCwnd < m_lastMaxCwnd + m_maxIncr * (m_b - 1))
196  {
197  /* slow start */
198  cnt = (segCwnd * (m_b - 1)) / (segCwnd - m_lastMaxCwnd);
199 
200  NS_LOG_INFO ("Slow start, cnt=" << cnt);
201  }
202  else
203  {
204  /* linear increase */
205  cnt = segCwnd / m_maxIncr;
206 
207  NS_LOG_INFO ("Linear, cnt=" << cnt);
208  }
209  }
210 
211  /* if in slow start or link utilization is very low. Code taken from Linux
212  * kernel, not sure of the source they take it. Usually, it is not reached,
213  * since if m_lastMaxCwnd is 0, we are (hopefully) in slow start.
214  */
215  if (m_lastMaxCwnd == 0)
216  {
217  if (cnt > 20) /* increase cwnd 5% per RTT */
218  {
219  cnt = 20;
220  }
221  }
222 
223  if (cnt == 0)
224  {
225  cnt = 1;
226  }
227 
228  return cnt;
229 }
230 
231 std::string
233 {
234  return "TcpBic";
235 }
236 
237 uint32_t
238 TcpBic::GetSsThresh (Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight)
239 {
240  NS_LOG_FUNCTION (this);
241 
242  uint32_t segCwnd = tcb->GetCwndInSegments ();
243  uint32_t ssThresh = 0;
244 
245  m_epochStart = Time::Min ();
246 
247  /* Wmax and fast convergence */
248  if (segCwnd < m_lastMaxCwnd && m_fastConvergence)
249  {
250  NS_LOG_INFO ("Fast Convergence. Last max cwnd: " << m_lastMaxCwnd <<
251  " updated to " << static_cast<uint32_t> (m_beta * segCwnd));
252  m_lastMaxCwnd = static_cast<uint32_t> (m_beta * segCwnd);
253  }
254  else
255  {
256  NS_LOG_INFO ("Last max cwnd: " << m_lastMaxCwnd << " updated to " <<
257  segCwnd);
258  m_lastMaxCwnd = segCwnd;
259  }
260 
261  if (segCwnd < m_lowWnd)
262  {
263  ssThresh = std::max (2 * tcb->m_segmentSize, bytesInFlight / 2);
264  NS_LOG_INFO ("Less than lowWindow, ssTh= " << ssThresh);
265  }
266  else
267  {
268  ssThresh = static_cast<uint32_t> (std::max (segCwnd * m_beta, 2.0) * tcb->m_segmentSize);
269  NS_LOG_INFO ("More than lowWindow, ssTh= " << ssThresh);
270  }
271 
272  return ssThresh;
273 }
274 
277 {
278  return CopyObject<TcpBic> (this);
279 }
280 
281 } // namespace ns3
BIC congestion control algorithm.
Definition: tcp-bic.h:80
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Time m_epochStart
Beginning of an epoch.
Definition: tcp-bic.h:139
bool m_fastConvergence
Enable or disable fast convergence algorithm.
Definition: tcp-bic.h:129
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:36
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static Time Min()
Minimum representable Time.
Definition: nstime.h:268
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
uint32_t m_lastMaxCwnd
Last maximum cWnd.
Definition: tcp-bic.h:137
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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
uint32_t m_lowWnd
Lower bound on congestion window.
Definition: tcp-bic.h:132
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-bic.cc:28
uint32_t m_maxIncr
Maximum window increment.
Definition: tcp-bic.h:131
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-bic.cc:238
virtual uint32_t Update(Ptr< TcpSocketState > tcb)
Bic window update after a new ack received.
Definition: tcp-bic.cc:133
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
#define max(a, b)
Definition: 80211b.c:45
uint32_t m_cWndCnt
cWnd integer-to-float counter
Definition: tcp-bic.h:136
Hold an unsigned integer type.
Definition: uinteger.h:44
uint32_t m_smoothPart
Number of RTT needed to reach Wmax from Wmax-B.
Definition: tcp-bic.h:133
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-bic.cc:276
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-bic.cc:232
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
TcpBic()
Constructor.
Definition: tcp-bic.cc:67
uint32_t m_lastCwnd
Last cWnd.
Definition: tcp-bic.h:138
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
double m_beta
Beta for cubic multiplicative increase.
Definition: tcp-bic.h:130
Congestion control abstract class.
uint8_t m_b
Binary search coefficient.
Definition: tcp-bic.h:140
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
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
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
Definition: tcp-bic.cc:95
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914