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 #include "ns3/simulator.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  .AddAttribute ("MinCwnd",
65  "Minimum cWnd for Ledbat",
66  UintegerValue (2),
68  MakeUintegerChecker<uint32_t> ())
69  ;
70  return tid;
71 }
72 
74 {
75  NS_LOG_FUNCTION (this << doSS);
76  m_doSs = doSS;
77  if (m_doSs)
78  {
80  }
81  else
82  {
84  }
85 }
86 
88  : TcpNewReno ()
89 {
90  NS_LOG_FUNCTION (this);
91  m_target = MilliSeconds (100);
92  m_gain = 1;
94  m_baseHistoLen = 10;
95  m_noiseFilterLen = 4;
98  m_lastRollover = 0;
99  m_sndCwndCnt = 0;
101  m_minCwnd = 2;
102 };
103 
104 void TcpLedbat::InitCircBuf (struct OwdCircBuf &buffer)
105 {
106  NS_LOG_FUNCTION (this);
107  buffer.buffer.clear ();
108  buffer.min = 0;
109 }
110 
112  : TcpNewReno (sock)
113 {
114  NS_LOG_FUNCTION (this);
115  m_target = sock.m_target;
116  m_gain = sock.m_gain;
117  m_doSs = sock.m_doSs;
123  m_sndCwndCnt = sock.m_sndCwndCnt;
124  m_flag = sock.m_flag;
125  m_minCwnd = sock.m_minCwnd;
126 }
127 
129 {
130  NS_LOG_FUNCTION (this);
131 }
132 
135 {
136  return CopyObject<TcpLedbat> (this);
137 }
138 
139 std::string
141 {
142  return "TcpLedbat";
143 }
144 
145 uint32_t TcpLedbat::MinCircBuf (struct OwdCircBuf &b)
146 {
148  if (b.buffer.size () == 0)
149  {
150  return ~0U;
151  }
152  else
153  {
154  return b.buffer[b.min];
155  }
156 }
157 
158 uint32_t TcpLedbat::CurrentDelay (FilterFunction filter)
159 {
160  NS_LOG_FUNCTION (this);
161  return filter (m_noiseFilter);
162 }
163 
165 {
166  NS_LOG_FUNCTION (this);
167  return MinCircBuf (m_baseHistory);
168 }
169 
170 void TcpLedbat::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
171 {
172  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
173  if (tcb->m_cWnd.Get () <= tcb->m_segmentSize)
174  {
176  }
177  if (m_doSs == DO_SLOWSTART && tcb->m_cWnd <= tcb->m_ssThresh && (m_flag & LEDBAT_CAN_SS))
178  {
179  SlowStart (tcb, segmentsAcked);
180  }
181  else
182  {
183  m_flag &= ~LEDBAT_CAN_SS;
184  CongestionAvoidance (tcb, segmentsAcked);
185  }
186 }
187 
188 void TcpLedbat::CongestionAvoidance (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
189 {
190  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
191  if ((m_flag & LEDBAT_VALID_OWD) == 0)
192  {
193  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked); //letting it fall to TCP behaviour if no timestamps
194  return;
195  }
196  int64_t queue_delay;
197  double offset;
198  uint32_t cwnd = (tcb->m_cWnd.Get ());
199  uint32_t max_cwnd;
200  uint64_t current_delay = CurrentDelay (&TcpLedbat::MinCircBuf);
201  uint64_t base_delay = BaseDelay ();
202 
203  if (current_delay > base_delay)
204  {
205  queue_delay = static_cast<int64_t> (current_delay - base_delay);
206  offset = m_target.GetMilliSeconds () - queue_delay;
207  }
208  else
209  {
210  queue_delay = static_cast<int64_t> (base_delay - current_delay);
211  offset = m_target.GetMilliSeconds () + queue_delay;
212  }
213  offset *= m_gain;
214  m_sndCwndCnt = static_cast<int32_t> (offset * segmentsAcked * tcb->m_segmentSize);
215  double inc = (m_sndCwndCnt * 1.0) / (m_target.GetMilliSeconds () * tcb->m_cWnd.Get ());
216  cwnd += (inc * tcb->m_segmentSize);
217 
218  max_cwnd = static_cast<uint32_t>(tcb->m_highTxMark.Get () - tcb->m_lastAckedSeq) + segmentsAcked * tcb->m_segmentSize;
219  cwnd = std::min (cwnd, max_cwnd);
220  cwnd = std::max (cwnd, m_minCwnd * tcb->m_segmentSize);
221  tcb->m_cWnd = cwnd;
222 
223  if (tcb->m_cWnd <= tcb->m_ssThresh)
224  {
225  tcb->m_ssThresh = tcb->m_cWnd - 1;
226  }
227 }
228 
229 void TcpLedbat::AddDelay (struct OwdCircBuf &cb, uint32_t owd, uint32_t maxlen)
230 {
231  NS_LOG_FUNCTION (this << owd << maxlen << cb.buffer.size ());
232  if (cb.buffer.size () == 0)
233  {
234  NS_LOG_LOGIC ("First Value for queue");
235  cb.buffer.push_back (owd);
236  cb.min = 0;
237  return;
238  }
239  cb.buffer.push_back (owd);
240  if (cb.buffer[cb.min] > owd)
241  {
242  cb.min = static_cast<uint32_t> (cb.buffer.size () - 1);
243  }
244  if (cb.buffer.size () >= maxlen)
245  {
246  NS_LOG_LOGIC ("Queue full" << maxlen);
247  cb.buffer.erase (cb.buffer.begin ());
248  cb.min = 0;
249  NS_LOG_LOGIC ("Current min element" << cb.buffer[cb.min]);
250  for (uint32_t i = 1; i < maxlen - 1; i++)
251  {
252  if (cb.buffer[i] < cb.buffer[cb.min])
253  {
254  cb.min = i;
255  }
256  }
257  }
258 }
259 
260 void TcpLedbat::UpdateBaseDelay (uint32_t owd)
261 {
262  NS_LOG_FUNCTION (this << owd );
263  if (m_baseHistory.buffer.size () == 0)
264  {
266  return;
267  }
268  uint64_t timestamp = static_cast<uint64_t> (Simulator::Now ().GetSeconds ());
269 
270  if (timestamp - m_lastRollover > 60)
271  {
272  m_lastRollover = timestamp;
274  }
275  else
276  {
277  uint32_t last = static_cast<uint32_t> (m_baseHistory.buffer.size () - 1);
278  if (owd < m_baseHistory.buffer[last])
279  {
280  m_baseHistory.buffer[last] = owd;
282  {
283  m_baseHistory.min = last;
284  }
285  }
286  }
287 }
288 
289 void TcpLedbat::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
290  const Time& rtt)
291 {
292  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
293  if (tcb->m_rcvTimestampValue == 0 || tcb->m_rcvTimestampEchoReply == 0)
294  {
296  }
297  else
298  {
300  }
301  if (rtt.IsPositive ())
302  {
305  }
306 }
307 
308 } // namespace ns3
uint32_t BaseDelay()
Return the value of base delay.
Definition: tcp-ledbat.cc:164
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
uint32_t min
The index of minimum value.
Definition: tcp-ledbat.h:133
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:189
std::vector< uint32_t > buffer
Vector to store the delay.
Definition: tcp-ledbat.h:132
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:289
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.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
uint64_t m_lastRollover
Timestamp of last added delay.
Definition: tcp-ledbat.h:190
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:229
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:202
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following LEDBAT algorithm.
Definition: tcp-ledbat.cc:170
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
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:145
OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition: tcp-ledbat.h:192
Buffer structure to store delays.
Definition: tcp-ledbat.h:130
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:128
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-ledbat.cc:32
void InitCircBuf(struct OwdCircBuf &buffer)
Initialise a new buffer.
Definition: tcp-ledbat.cc:104
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-ledbat.cc:134
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1076
Hold an unsigned integer type.
Definition: uinteger.h:44
SlowStartType m_doSs
Permissible Slow Start State.
Definition: tcp-ledbat.h:187
Do NewReno Slow Start.
Definition: tcp-ledbat.h:46
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition: tcp-ledbat.h:188
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
SlowStartType
The slowstart types.
Definition: tcp-ledbat.h:43
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
Definition: tcp-ledbat.cc:158
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint32_t m_minCwnd
Minimum cWnd value mentioned in RFC 6817.
Definition: tcp-ledbat.h:195
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_gain
GAIN value from RFC.
Definition: tcp-ledbat.h:186
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:1077
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Time m_target
Target Queue Delay.
Definition: tcp-ledbat.h:185
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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
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:260
uint32_t m_flag
LEDBAT Flag.
Definition: tcp-ledbat.h:194
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
bool IsPositive(void) const
Definition: nstime.h:298
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Reduce Congestion.
Definition: tcp-ledbat.cc:188
void SetDoSs(SlowStartType doSS)
Change the Slow Start Capability.
Definition: tcp-ledbat.cc:73
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
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:193
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:140
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:915
int32_t m_sndCwndCnt
The congestion window addition parameter.
Definition: tcp-ledbat.h:191
TcpLedbat(void)
Create an unbound tcp socket.
Definition: tcp-ledbat.cc:87
If LEDBAT allows Slow Start.
Definition: tcp-ledbat.h:56
If valid timestamps are present.
Definition: tcp-ledbat.h:55