A Discrete-Event Network Simulator
API
tcp-ledbat.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 NITK Surathkal
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: Ankit Deepak <adadeepak8@gmail.com>
19  *
20  */
21 
22 #include "tcp-ledbat.h"
23 #include "tcp-socket-state.h"
24 
25 #include "ns3/log.h"
26 #include "ns3/simulator.h" // Now ()
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("TcpLedbat");
31 NS_OBJECT_ENSURE_REGISTERED (TcpLedbat);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::TcpLedbat")
38  .AddConstructor<TcpLedbat> ()
39  .SetGroupName ("Internet")
40  .AddAttribute ("TargetDelay",
41  "Targeted Queue Delay",
42  TimeValue (MilliSeconds (100)),
44  MakeTimeChecker ())
45  .AddAttribute ("BaseHistoryLen",
46  "Number of Base delay samples",
47  UintegerValue (10),
49  MakeUintegerChecker<uint32_t> ())
50  .AddAttribute ("NoiseFilterLen",
51  "Number of Current delay samples",
52  UintegerValue (4),
54  MakeUintegerChecker<uint32_t> ())
55  .AddAttribute ("Gain",
56  "Offset Gain",
57  DoubleValue (1.0),
59  MakeDoubleChecker<double> ())
60  .AddAttribute ("SSParam",
61  "Possibility of Slow Start",
65  DO_NOT_SLOWSTART, "no"))
66  .AddAttribute ("MinCwnd",
67  "Minimum cWnd for Ledbat",
68  UintegerValue (2),
70  MakeUintegerChecker<uint32_t> ())
71  ;
72  return tid;
73 }
74 
76 {
77  NS_LOG_FUNCTION (this << doSS);
78  m_doSs = doSS;
79  if (m_doSs)
80  {
82  }
83  else
84  {
86  }
87 }
88 
90  : TcpNewReno ()
91 {
92  NS_LOG_FUNCTION (this);
93  m_target = MilliSeconds (100);
94  m_gain = 1;
96  m_baseHistoLen = 10;
97  m_noiseFilterLen = 4;
100  m_lastRollover = 0;
101  m_sndCwndCnt = 0;
103  m_minCwnd = 2;
104 };
105 
106 void TcpLedbat::InitCircBuf (struct OwdCircBuf &buffer)
107 {
108  NS_LOG_FUNCTION (this);
109  buffer.buffer.clear ();
110  buffer.min = 0;
111 }
112 
114  : TcpNewReno (sock)
115 {
116  NS_LOG_FUNCTION (this);
117  m_target = sock.m_target;
118  m_gain = sock.m_gain;
119  m_doSs = sock.m_doSs;
125  m_sndCwndCnt = sock.m_sndCwndCnt;
126  m_flag = sock.m_flag;
127  m_minCwnd = sock.m_minCwnd;
128 }
129 
131 {
132  NS_LOG_FUNCTION (this);
133 }
134 
137 {
138  return CopyObject<TcpLedbat> (this);
139 }
140 
141 std::string
143 {
144  return "TcpLedbat";
145 }
146 
147 uint32_t TcpLedbat::MinCircBuf (struct OwdCircBuf &b)
148 {
150  if (b.buffer.size () == 0)
151  {
152  return ~0U;
153  }
154  else
155  {
156  return b.buffer[b.min];
157  }
158 }
159 
160 uint32_t TcpLedbat::CurrentDelay (FilterFunction filter)
161 {
162  NS_LOG_FUNCTION (this);
163  return filter (m_noiseFilter);
164 }
165 
167 {
168  NS_LOG_FUNCTION (this);
169  return MinCircBuf (m_baseHistory);
170 }
171 
172 void TcpLedbat::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
173 {
174  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
175  if (tcb->m_cWnd.Get () <= tcb->m_segmentSize)
176  {
178  }
179  if (m_doSs == DO_SLOWSTART && tcb->m_cWnd <= tcb->m_ssThresh && (m_flag & LEDBAT_CAN_SS))
180  {
181  SlowStart (tcb, segmentsAcked);
182  }
183  else
184  {
185  m_flag &= ~LEDBAT_CAN_SS;
186  CongestionAvoidance (tcb, segmentsAcked);
187  }
188 }
189 
190 void TcpLedbat::CongestionAvoidance (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
191 {
192  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
193  if ((m_flag & LEDBAT_VALID_OWD) == 0)
194  {
195  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked); //letting it fall to TCP behaviour if no timestamps
196  return;
197  }
198  int64_t queue_delay;
199  double offset;
200  uint32_t cwnd = (tcb->m_cWnd.Get ());
201  uint32_t max_cwnd;
202  uint64_t current_delay = CurrentDelay (&TcpLedbat::MinCircBuf);
203  uint64_t base_delay = BaseDelay ();
204 
205  if (current_delay > base_delay)
206  {
207  queue_delay = static_cast<int64_t> (current_delay - base_delay);
208  offset = m_target.GetMilliSeconds () - queue_delay;
209  }
210  else
211  {
212  queue_delay = static_cast<int64_t> (base_delay - current_delay);
213  offset = m_target.GetMilliSeconds () + queue_delay;
214  }
215  offset *= m_gain;
216  m_sndCwndCnt = static_cast<int32_t> (offset * segmentsAcked * tcb->m_segmentSize);
217  double inc = (m_sndCwndCnt * 1.0) / (m_target.GetMilliSeconds () * tcb->m_cWnd.Get ());
218  cwnd += (inc * tcb->m_segmentSize);
219 
220  max_cwnd = static_cast<uint32_t>(tcb->m_highTxMark.Get () - tcb->m_lastAckedSeq) + segmentsAcked * tcb->m_segmentSize;
221  cwnd = std::min (cwnd, max_cwnd);
222  cwnd = std::max (cwnd, m_minCwnd * tcb->m_segmentSize);
223  tcb->m_cWnd = cwnd;
224 
225  if (tcb->m_cWnd <= tcb->m_ssThresh)
226  {
227  tcb->m_ssThresh = tcb->m_cWnd - 1;
228  }
229 }
230 
231 void TcpLedbat::AddDelay (struct OwdCircBuf &cb, uint32_t owd, uint32_t maxlen)
232 {
233  NS_LOG_FUNCTION (this << owd << maxlen << cb.buffer.size ());
234  if (cb.buffer.size () == 0)
235  {
236  NS_LOG_LOGIC ("First Value for queue");
237  cb.buffer.push_back (owd);
238  cb.min = 0;
239  return;
240  }
241  cb.buffer.push_back (owd);
242  if (cb.buffer[cb.min] > owd)
243  {
244  cb.min = static_cast<uint32_t> (cb.buffer.size () - 1);
245  }
246  if (cb.buffer.size () >= maxlen)
247  {
248  NS_LOG_LOGIC ("Queue full" << maxlen);
249  cb.buffer.erase (cb.buffer.begin ());
250  cb.min = 0;
251  NS_LOG_LOGIC ("Current min element" << cb.buffer[cb.min]);
252  for (uint32_t i = 1; i < maxlen - 1; i++)
253  {
254  if (cb.buffer[i] < cb.buffer[cb.min])
255  {
256  cb.min = i;
257  }
258  }
259  }
260 }
261 
262 void TcpLedbat::UpdateBaseDelay (uint32_t owd)
263 {
264  NS_LOG_FUNCTION (this << owd );
265  if (m_baseHistory.buffer.size () == 0)
266  {
268  return;
269  }
270  uint64_t timestamp = static_cast<uint64_t> (Simulator::Now ().GetSeconds ());
271 
272  if (timestamp - m_lastRollover > 60)
273  {
274  m_lastRollover = timestamp;
276  }
277  else
278  {
279  uint32_t last = static_cast<uint32_t> (m_baseHistory.buffer.size () - 1);
280  if (owd < m_baseHistory.buffer[last])
281  {
282  m_baseHistory.buffer[last] = owd;
284  {
285  m_baseHistory.min = last;
286  }
287  }
288  }
289 }
290 
291 void TcpLedbat::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
292  const Time& rtt)
293 {
294  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
295  if (tcb->m_rcvTimestampValue == 0 || tcb->m_rcvTimestampEchoReply == 0)
296  {
298  }
299  else
300  {
302  }
303  if (rtt.IsPositive ())
304  {
307  }
308 }
309 
310 } // namespace ns3
uint32_t BaseDelay()
Return the value of base delay.
Definition: tcp-ledbat.cc:166
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
uint32_t min
The index of minimum value.
Definition: tcp-ledbat.h:135
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
uint32_t m_noiseFilterLen
Length of current delay buffer.
Definition: tcp-ledbat.h:191
std::vector< uint32_t > buffer
Vector to store the delay.
Definition: tcp-ledbat.h:134
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 "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define min(a, b)
Definition: 80211b.c:42
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Get information from the acked packet.
Definition: tcp-ledbat.cc:291
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
uint64_t m_lastRollover
Timestamp of last added delay.
Definition: tcp-ledbat.h:192
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm
void AddDelay(struct OwdCircBuf &cb, uint32_t owd, uint32_t maxlen)
Add new delay to the buffers.
Definition: tcp-ledbat.cc:231
An implementation of LEDBAT.
Definition: tcp-ledbat.h:39
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following LEDBAT algorithm.
Definition: tcp-ledbat.cc:172
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
uint32_t m_segmentSize
Segment size.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
The NewReno implementation.
static uint32_t MinCircBuf(struct OwdCircBuf &b)
Return the minimum delay of the buffer.
Definition: tcp-ledbat.cc:147
OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition: tcp-ledbat.h:194
Buffer structure to store delays.
Definition: tcp-ledbat.h:132
virtual ~TcpLedbat(void)
Destructor.
Definition: tcp-ledbat.cc:130
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-ledbat.cc:34
void InitCircBuf(struct OwdCircBuf &buffer)
Initialise a new buffer.
Definition: tcp-ledbat.cc:106
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-ledbat.cc:136
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1342
Hold an unsigned integer type.
Definition: uinteger.h:44
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:203
SlowStartType m_doSs
Permissible Slow Start State.
Definition: tcp-ledbat.h:189
Do NewReno Slow Start.
Definition: tcp-ledbat.h:48
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition: tcp-ledbat.h:190
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
SlowStartType
The slowstart types.
Definition: tcp-ledbat.h:45
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
Definition: tcp-ledbat.cc:160
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint32_t m_minCwnd
Minimum cWnd value mentioned in RFC 6817.
Definition: tcp-ledbat.h:197
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_gain
GAIN value from RFC.
Definition: tcp-ledbat.h:188
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1343
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Time m_target
Target Queue Delay.
Definition: tcp-ledbat.h:187
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
void UpdateBaseDelay(uint32_t owd)
Update the base delay buffer.
Definition: tcp-ledbat.cc:262
uint32_t m_flag
LEDBAT Flag.
Definition: tcp-ledbat.h:196
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
bool IsPositive(void) const
Exactly equivalent to t >= 0.
Definition: nstime.h:316
T Get(void) const
Get the underlying value.
Definition: traced-value.h:229
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Reduce Congestion.
Definition: tcp-ledbat.cc:190
void SetDoSs(SlowStartType doSS)
Change the Slow Start Capability.
Definition: tcp-ledbat.cc:75
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:161
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:472
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
OwdCircBuf m_noiseFilter
Buffer to store the current delay.
Definition: tcp-ledbat.h:195
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
virtual std::string GetName() const
Get the name of the TCP flavour.
Definition: tcp-ledbat.cc:142
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:923
int32_t m_sndCwndCnt
The congestion window addition parameter.
Definition: tcp-ledbat.h:193
TcpLedbat(void)
Create an unbound tcp socket.
Definition: tcp-ledbat.cc:89
If LEDBAT allows Slow Start.
Definition: tcp-ledbat.h:58
If valid timestamps are present.
Definition: tcp-ledbat.h:57