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/tcp-socket-base.h"
24 #include "ns3/log.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpLedbat");
29 NS_OBJECT_ENSURE_REGISTERED (TcpLedbat);
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::TcpLedbat")
36  .AddConstructor<TcpLedbat> ()
37  .SetGroupName ("Internet")
38  .AddAttribute ("TargetDelay",
39  "Targeted Queue Delay",
40  TimeValue (MilliSeconds (100)),
42  MakeTimeChecker ())
43  .AddAttribute ("BaseHistoryLen",
44  "Number of Base delay samples",
45  UintegerValue (10),
47  MakeUintegerChecker<uint32_t> ())
48  .AddAttribute ("NoiseFilterLen",
49  "Number of Current delay samples",
50  UintegerValue (4),
52  MakeUintegerChecker<uint32_t> ())
53  .AddAttribute ("Gain",
54  "Offset Gain",
55  DoubleValue (1.0),
57  MakeDoubleChecker<double> ())
58  .AddAttribute ("SSParam",
59  "Possibility of Slow Start",
63  DO_NOT_SLOWSTART, "no"))
64  ;
65  return tid;
66 }
67 
69 {
70  NS_LOG_FUNCTION (this << doSS);
71  m_doSs = doSS;
72  if (m_doSs)
73  {
75  }
76  else
77  {
79  }
80 }
81 
83  : TcpNewReno ()
84 {
85  NS_LOG_FUNCTION (this);
86  m_target = MilliSeconds (100);
87  m_gain = 1;
89  m_baseHistoLen = 10;
90  m_noiseFilterLen = 4;
93  m_lastRollover = 0;
94  m_sndCwndCnt = 0;
96 }
97 
98 void TcpLedbat::InitCircBuf (struct OwdCircBuf &buffer)
99 {
100  NS_LOG_FUNCTION (this);
101  buffer.buffer.clear ();
102  buffer.min = 0;
103 }
104 
106  : TcpNewReno (sock)
107 {
108  NS_LOG_FUNCTION (this);
109  m_target = sock.m_target;
110  m_gain = sock.m_gain;
111  m_doSs = sock.m_doSs;
117  m_sndCwndCnt = sock.m_sndCwndCnt;
118  m_flag = sock.m_flag;
119 }
120 
122 {
123  NS_LOG_FUNCTION (this);
124 }
125 
128 {
129  return CopyObject<TcpLedbat> (this);
130 }
131 
132 std::string
134 {
135  return "TcpLedbat";
136 }
137 
138 uint32_t TcpLedbat::MinCircBuf (struct OwdCircBuf &b)
139 {
141  if (b.buffer.size () == 0)
142  {
143  return ~0;
144  }
145  else
146  {
147  return b.buffer[b.min];
148  }
149 }
150 
151 uint32_t TcpLedbat::CurrentDelay (FilterFunction filter)
152 {
153  NS_LOG_FUNCTION (this);
154  return filter (m_noiseFilter);
155 }
156 
158 {
159  NS_LOG_FUNCTION (this);
160  return MinCircBuf (m_baseHistory);
161 }
162 
164  uint32_t bytesInFlight)
165 {
166  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
167  uint32_t res;
168  res = TcpNewReno::GetSsThresh (tcb, bytesInFlight);
169  return res;
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 = current_delay - base_delay;
208  offset = m_target.GetMilliSeconds () - queue_delay;
209  }
210  else
211  {
212  queue_delay = base_delay - current_delay;
213  offset = m_target.GetMilliSeconds () + queue_delay;
214  }
215  offset *= m_gain;
216  m_sndCwndCnt = 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 = (tcb->m_highTxMark.Get () - tcb->m_lastAckedSeq) + segmentsAcked * tcb->m_segmentSize;
221  cwnd = std::min (cwnd, max_cwnd);
222  cwnd = std::max (cwnd, 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 = 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 = (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 = 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 }
uint32_t BaseDelay()
Return the value of base delay.
Definition: tcp-ledbat.cc:157
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
uint32_t min
The index of minimum value.
Definition: tcp-ledbat.h:142
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:198
std::vector< uint32_t > buffer
Vector to store the delay.
Definition: tcp-ledbat.h:141
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsPositive(void) const
Definition: nstime.h:284
#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:291
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:199
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:37
#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:172
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
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:138
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
struct OwdCircBuf m_noiseFilter
Buffer to store the current delay.
Definition: tcp-ledbat.h:202
Buffer structure to store delays.
Definition: tcp-ledbat.h:139
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:121
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-ledbat.cc:32
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
void InitCircBuf(struct OwdCircBuf &buffer)
Initialise a new buffer.
Definition: tcp-ledbat.cc:98
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-ledbat.cc:127
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:45
AttributeValue implementation for Time.
Definition: nstime.h:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
SlowStartType m_doSs
Permissible Slow Start State.
Definition: tcp-ledbat.h:196
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition: tcp-ledbat.h:197
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
Definition: tcp-ledbat.cc:151
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
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:195
struct OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition: tcp-ledbat.h:201
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold.
Definition: tcp-ledbat.cc:163
If valid timestamps are present.
Definition: tcp-ledbat.h:55
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:1056
If LEDBAT allows Slow Start.
Definition: tcp-ledbat.h:56
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Time m_target
Target Queue Delay.
Definition: tcp-ledbat.h:194
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
TracedValue< uint32_t > m_cWnd
Congestion window.
Do NewReno Slow Start.
Definition: tcp-ledbat.h:46
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:262
uint32_t m_flag
LEDBAT Flag.
Definition: tcp-ledbat.h:203
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:68
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:43
virtual std::string GetName() const
Get the name of the TCP flavour.
Definition: tcp-ledbat.cc:133
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:345
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:200
TcpLedbat(void)
Create an unbound tcp socket.
Definition: tcp-ledbat.cc:82