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 "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpLedbat");
28 NS_OBJECT_ENSURE_REGISTERED (TcpLedbat);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::TcpLedbat")
35  .AddConstructor<TcpLedbat> ()
36  .SetGroupName ("Internet")
37  .AddAttribute ("TargetDelay",
38  "Targeted Queue Delay",
39  TimeValue (MilliSeconds (100)),
41  MakeTimeChecker ())
42  .AddAttribute ("BaseHistoryLen",
43  "Number of Base delay samples",
44  UintegerValue (10),
46  MakeUintegerChecker<uint32_t> ())
47  .AddAttribute ("NoiseFilterLen",
48  "Number of Current delay samples",
49  UintegerValue (4),
51  MakeUintegerChecker<uint32_t> ())
52  .AddAttribute ("Gain",
53  "Offset Gain",
54  DoubleValue (1.0),
56  MakeDoubleChecker<double> ())
57  .AddAttribute ("SSParam",
58  "Possibility of Slow Start",
62  DO_NOT_SLOWSTART, "no"))
63  ;
64  return tid;
65 }
66 
68 {
69  NS_LOG_FUNCTION (this << doSS);
70  m_doSs = doSS;
71  if (m_doSs)
72  {
74  }
75  else
76  {
78  }
79 }
80 
82  : TcpNewReno ()
83 {
84  NS_LOG_FUNCTION (this);
85  m_target = MilliSeconds (100);
86  m_gain = 1;
88  m_baseHistoLen = 10;
89  m_noiseFilterLen = 4;
92  m_lastRollover = 0;
93  m_sndCwndCnt = 0;
95 }
96 
97 void TcpLedbat::InitCircBuf (struct OwdCircBuf &buffer)
98 {
99  NS_LOG_FUNCTION (this);
100  buffer.buffer.clear ();
101  buffer.min = 0;
102 }
103 
105  : TcpNewReno (sock)
106 {
107  NS_LOG_FUNCTION (this);
108  m_target = sock.m_target;
109  m_gain = sock.m_gain;
110  m_doSs = sock.m_doSs;
116  m_sndCwndCnt = sock.m_sndCwndCnt;
117  m_flag = sock.m_flag;
118 }
119 
121 {
122  NS_LOG_FUNCTION (this);
123 }
124 
127 {
128  return CopyObject<TcpLedbat> (this);
129 }
130 
131 std::string
133 {
134  return "TcpLedbat";
135 }
136 
137 uint32_t TcpLedbat::MinCircBuf (struct OwdCircBuf &b)
138 {
140  if (b.buffer.size () == 0)
141  {
142  return ~0U;
143  }
144  else
145  {
146  return b.buffer[b.min];
147  }
148 }
149 
150 uint32_t TcpLedbat::CurrentDelay (FilterFunction filter)
151 {
152  NS_LOG_FUNCTION (this);
153  return filter (m_noiseFilter);
154 }
155 
157 {
158  NS_LOG_FUNCTION (this);
159  return MinCircBuf (m_baseHistory);
160 }
161 
162 void TcpLedbat::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
163 {
164  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
165  if (tcb->m_cWnd.Get () <= tcb->m_segmentSize)
166  {
168  }
169  if (m_doSs == DO_SLOWSTART && tcb->m_cWnd <= tcb->m_ssThresh && (m_flag & LEDBAT_CAN_SS))
170  {
171  SlowStart (tcb, segmentsAcked);
172  }
173  else
174  {
175  m_flag &= ~LEDBAT_CAN_SS;
176  CongestionAvoidance (tcb, segmentsAcked);
177  }
178 }
179 
180 void TcpLedbat::CongestionAvoidance (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
181 {
182  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
183  if ((m_flag & LEDBAT_VALID_OWD) == 0)
184  {
185  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked); //letting it fall to TCP behaviour if no timestamps
186  return;
187  }
188  int64_t queue_delay;
189  double offset;
190  uint32_t cwnd = (tcb->m_cWnd.Get ());
191  uint32_t max_cwnd;
192  uint64_t current_delay = CurrentDelay (&TcpLedbat::MinCircBuf);
193  uint64_t base_delay = BaseDelay ();
194 
195  if (current_delay > base_delay)
196  {
197  queue_delay = static_cast<int64_t> (current_delay - base_delay);
198  offset = m_target.GetMilliSeconds () - queue_delay;
199  }
200  else
201  {
202  queue_delay = static_cast<int64_t> (base_delay - current_delay);
203  offset = m_target.GetMilliSeconds () + queue_delay;
204  }
205  offset *= m_gain;
206  m_sndCwndCnt = static_cast<int32_t> (offset * segmentsAcked * tcb->m_segmentSize);
207  double inc = (m_sndCwndCnt * 1.0) / (m_target.GetMilliSeconds () * tcb->m_cWnd.Get ());
208  cwnd += (inc * tcb->m_segmentSize);
209 
210  max_cwnd = static_cast<uint32_t>(tcb->m_highTxMark.Get () - tcb->m_lastAckedSeq) + segmentsAcked * tcb->m_segmentSize;
211  cwnd = std::min (cwnd, max_cwnd);
212  cwnd = std::max (cwnd, tcb->m_segmentSize);
213  tcb->m_cWnd = cwnd;
214 
215  if (tcb->m_cWnd <= tcb->m_ssThresh)
216  {
217  tcb->m_ssThresh = tcb->m_cWnd - 1;
218  }
219 }
220 
221 void TcpLedbat::AddDelay (struct OwdCircBuf &cb, uint32_t owd, uint32_t maxlen)
222 {
223  NS_LOG_FUNCTION (this << owd << maxlen << cb.buffer.size ());
224  if (cb.buffer.size () == 0)
225  {
226  NS_LOG_LOGIC ("First Value for queue");
227  cb.buffer.push_back (owd);
228  cb.min = 0;
229  return;
230  }
231  cb.buffer.push_back (owd);
232  if (cb.buffer[cb.min] > owd)
233  {
234  cb.min = static_cast<uint32_t> (cb.buffer.size () - 1);
235  }
236  if (cb.buffer.size () >= maxlen)
237  {
238  NS_LOG_LOGIC ("Queue full" << maxlen);
239  cb.buffer.erase (cb.buffer.begin ());
240  cb.min = 0;
241  NS_LOG_LOGIC ("Current min element" << cb.buffer[cb.min]);
242  for (uint32_t i = 1; i < maxlen - 1; i++)
243  {
244  if (cb.buffer[i] < cb.buffer[cb.min])
245  {
246  cb.min = i;
247  }
248  }
249  }
250 }
251 
252 void TcpLedbat::UpdateBaseDelay (uint32_t owd)
253 {
254  NS_LOG_FUNCTION (this << owd );
255  if (m_baseHistory.buffer.size () == 0)
256  {
258  return;
259  }
260  uint64_t timestamp = static_cast<uint64_t> (Simulator::Now ().GetSeconds ());
261 
262  if (timestamp - m_lastRollover > 60)
263  {
264  m_lastRollover = timestamp;
266  }
267  else
268  {
269  uint32_t last = static_cast<uint32_t> (m_baseHistory.buffer.size () - 1);
270  if (owd < m_baseHistory.buffer[last])
271  {
272  m_baseHistory.buffer[last] = owd;
274  {
275  m_baseHistory.min = last;
276  }
277  }
278  }
279 }
280 
281 void TcpLedbat::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
282  const Time& rtt)
283 {
284  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
285  if (tcb->m_rcvTimestampValue == 0 || tcb->m_rcvTimestampEchoReply == 0)
286  {
288  }
289  else
290  {
292  }
293  if (rtt.IsPositive ())
294  {
297  }
298 }
299 
300 } // namespace ns3
uint32_t BaseDelay()
Return the value of base delay.
Definition: tcp-ledbat.cc:156
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
If LEDBAT allows Slow Start.
Definition: tcp-ledbat.h:55
uint32_t min
The index of minimum value.
Definition: tcp-ledbat.h:132
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint32_t m_noiseFilterLen
Length of current delay buffer.
Definition: tcp-ledbat.h:188
std::vector< uint32_t > buffer
Vector to store the delay.
Definition: tcp-ledbat.h:131
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsPositive(void) const
Definition: nstime.h:298
#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:44
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Get information from the acked packet.
Definition: tcp-ledbat.cc:281
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:209
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
uint64_t m_lastRollover
Timestamp of last added delay.
Definition: tcp-ledbat.h:189
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:221
An implementation of LEDBAT.
Definition: tcp-ledbat.h:36
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following LEDBAT algorithm.
Definition: tcp-ledbat.cc:162
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1015
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:137
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition: tcp-ledbat.h:191
Buffer structure to store delays.
Definition: tcp-ledbat.h:129
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
virtual ~TcpLedbat(void)
Destructor.
Definition: tcp-ledbat.cc:120
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-ledbat.cc:31
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
void InitCircBuf(struct OwdCircBuf &buffer)
Initialise a new buffer.
Definition: tcp-ledbat.cc:97
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-ledbat.cc:126
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:45
AttributeValue implementation for Time.
Definition: nstime.h:1069
Hold an unsigned integer type.
Definition: uinteger.h:44
SlowStartType m_doSs
Permissible Slow Start State.
Definition: tcp-ledbat.h:186
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition: tcp-ledbat.h:187
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
Definition: tcp-ledbat.cc:150
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_gain
GAIN value from RFC.
Definition: tcp-ledbat.h:185
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:1070
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Time m_target
Target Queue Delay.
Definition: tcp-ledbat.h:184
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
TracedValue< uint32_t > m_cWnd
Congestion window.
Do NewReno Slow Start.
Definition: tcp-ledbat.h:45
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
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
void UpdateBaseDelay(uint32_t owd)
Update the base delay buffer.
Definition: tcp-ledbat.cc:252
uint32_t m_flag
LEDBAT Flag.
Definition: tcp-ledbat.h:193
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Reduce Congestion.
Definition: tcp-ledbat.cc:180
void SetDoSs(SlowStartType doSS)
Change the Slow Start Capability.
Definition: tcp-ledbat.cc:67
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
SlowStartType
The slowstart types.
Definition: tcp-ledbat.h:42
OwdCircBuf m_noiseFilter
Buffer to store the current delay.
Definition: tcp-ledbat.h:192
virtual std::string GetName() const
Get the name of the TCP flavour.
Definition: tcp-ledbat.cc:132
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:359
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
int32_t m_sndCwndCnt
The congestion window addition parameter.
Definition: tcp-ledbat.h:190
TcpLedbat(void)
Create an unbound tcp socket.
Definition: tcp-ledbat.cc:81
If valid timestamps are present.
Definition: tcp-ledbat.h:54