A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-ledbat.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Ankit Deepak <adadeepak8@gmail.com>
7 * Modified by: S B L Prateek <sblprateek@gmail.com>
8 *
9 */
10
11#include "tcp-ledbat.h"
12
13#include "tcp-socket-state.h"
14
15#include "ns3/log.h"
16#include "ns3/simulator.h" // Now ()
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("TcpLedbat");
23
26{
27 static TypeId tid =
28 TypeId("ns3::TcpLedbat")
30 .AddConstructor<TcpLedbat>()
31 .SetGroupName("Internet")
32 .AddAttribute("TargetDelay",
33 "Targeted Queue Delay",
37 .AddAttribute("BaseHistoryLen",
38 "Number of Base delay samples",
39 UintegerValue(10),
42 .AddAttribute("NoiseFilterLen",
43 "Number of Current delay samples",
47 .AddAttribute("Gain",
48 "Offset Gain",
49 DoubleValue(1.0),
52 .AddAttribute("SSParam",
53 "Possibility of Slow Start",
57 .AddAttribute("MinCwnd",
58 "Minimum cWnd for Ledbat",
62 .AddAttribute("AllowedIncrease",
63 "Allowed Increase",
64 DoubleValue(1.0),
67 return tid;
68}
69
70void
72{
73 NS_LOG_FUNCTION(this << doSS);
74 m_doSs = doSS;
75 if (m_doSs)
76 {
78 }
79 else
80 {
82 }
83}
84
95
96void
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;
117 m_flag = sock.m_flag;
118 m_minCwnd = sock.m_minCwnd;
120}
121
126
129{
130 return CopyObject<TcpLedbat>(this);
131}
132
133std::string
135{
136 return "TcpLedbat";
137}
138
141{
143 if (b.buffer.empty())
144 {
145 return ~0U;
146 }
147 else
148 {
149 return b.buffer[b.min];
150 }
151}
152
155{
156 NS_LOG_FUNCTION(this);
157 return filter(m_noiseFilter);
158}
159
166
167void
169{
170 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
171 if (tcb->m_cWnd.Get() <= tcb->m_segmentSize)
172 {
174 }
175 if (m_doSs == DO_SLOWSTART && tcb->m_cWnd <= tcb->m_ssThresh && (m_flag & LEDBAT_CAN_SS))
176 {
177 SlowStart(tcb, segmentsAcked);
178 }
179 else
180 {
182 CongestionAvoidance(tcb, segmentsAcked);
183 }
184}
185
186void
188{
189 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
190 if ((m_flag & LEDBAT_VALID_OWD) == 0)
191 {
193 tcb,
194 segmentsAcked); // letting it fall to TCP behaviour if no timestamps
195 return;
196 }
197 uint32_t queueDelay;
198 double offset;
199 uint32_t cwnd = tcb->m_cWnd.Get();
200 uint32_t maxCwnd;
202 uint32_t baseDelay = BaseDelay();
203
204 if (currentDelay > baseDelay)
205 {
206 queueDelay = currentDelay - baseDelay;
207 offset = m_target.GetMilliSeconds() - queueDelay;
208 }
209 else
210 {
211 queueDelay = baseDelay - currentDelay;
212 offset = m_target.GetMilliSeconds() + queueDelay;
213 }
214 offset *= m_gain;
215 m_sndCwndCnt = offset * segmentsAcked * tcb->m_segmentSize;
216 double inc = m_sndCwndCnt / (m_target.GetMilliSeconds() * tcb->m_cWnd.Get());
217 cwnd += (inc * tcb->m_segmentSize);
218
219 // Since m_bytesInFlight reflects the state after processing the current ACK,
220 // adding segmentsAcked * m_segmentSize reconstructs the flight size before this
221 // ACK arrived, as required by the RFC definition of flight size.
222 uint32_t flightSizeBeforeAck =
223 tcb->m_bytesInFlight.Get() + (segmentsAcked * tcb->m_segmentSize);
224 maxCwnd = flightSizeBeforeAck + static_cast<uint32_t>(m_allowedIncrease * tcb->m_segmentSize);
225 cwnd = std::min(cwnd, maxCwnd);
226 cwnd = std::max(cwnd, m_minCwnd * tcb->m_segmentSize);
227 tcb->m_cWnd = cwnd;
228
229 if (tcb->m_cWnd <= tcb->m_ssThresh)
230 {
231 tcb->m_ssThresh = tcb->m_cWnd - 1;
232 }
233}
234
235void
237{
238 NS_LOG_FUNCTION(this << owd << maxlen << cb.buffer.size());
239 if (cb.buffer.empty())
240 {
241 NS_LOG_LOGIC("First Value for queue");
242 cb.buffer.push_back(owd);
243 cb.min = 0;
244 return;
245 }
246 cb.buffer.push_back(owd);
247 if (cb.buffer[cb.min] > owd)
248 {
249 cb.min = cb.buffer.size() - 1;
250 }
251 if (cb.buffer.size() >= maxlen)
252 {
253 NS_LOG_LOGIC("Queue full" << maxlen);
254 cb.buffer.erase(cb.buffer.begin());
255 auto bufferStart = cb.buffer.begin();
256 cb.min = std::distance(bufferStart, std::min_element(bufferStart, cb.buffer.end()));
257 NS_LOG_LOGIC("Current min element" << cb.buffer[cb.min]);
258 }
259}
260
261void
263{
264 NS_LOG_FUNCTION(this << owd);
265 if (m_baseHistory.buffer.empty())
266 {
268 return;
269 }
270 Time timestamp = Simulator::Now();
271
272 if ((timestamp - m_lastRollover) > Seconds(60))
273 {
274 m_lastRollover = timestamp;
276 }
277 else
278 {
279 size_t last = m_baseHistory.buffer.size() - 1;
280 if (owd < m_baseHistory.buffer[last])
281 {
282 m_baseHistory.buffer[last] = owd;
283 if (owd < m_baseHistory.buffer[m_baseHistory.min])
284 {
285 m_baseHistory.min = last;
286 }
287 }
288 }
289}
290
291void
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() && tcb->m_rcvTimestampValue >= tcb->m_rcvTimestampEchoReply)
304 {
305 uint32_t owd = tcb->m_rcvTimestampValue - tcb->m_rcvTimestampEchoReply;
307 UpdateBaseDelay(owd);
308 }
309}
310
311} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
An implementation of LEDBAT.
Definition tcp-ledbat.h:30
static TypeId GetTypeId()
Get the type ID.
Definition tcp-ledbat.cc:25
SlowStartType m_doSs
Permissible Slow Start State.
Definition tcp-ledbat.h:178
std::string GetName() const override
Get the name of the TCP flavour.
void UpdateBaseDelay(uint32_t owd)
Update the base delay buffer.
uint32_t m_minCwnd
Minimum cWnd value mentioned in RFC 6817.
Definition tcp-ledbat.h:186
void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Adjust cwnd following LEDBAT algorithm.
uint32_t m_flag
LEDBAT Flag.
Definition tcp-ledbat.h:185
double m_allowedIncrease
ALLOWED INCREASE value mentioned in RFC 6817.
Definition tcp-ledbat.h:187
uint32_t BaseDelay()
Return the value of base delay.
void SetDoSs(SlowStartType doSS)
Change the Slow Start Capability.
Definition tcp-ledbat.cc:71
double m_gain
GAIN value from RFC.
Definition tcp-ledbat.h:177
@ LEDBAT_CAN_SS
If LEDBAT allows Slow Start.
Definition tcp-ledbat.h:48
@ LEDBAT_VALID_OWD
If valid timestamps are present.
Definition tcp-ledbat.h:47
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
double m_sndCwndCnt
The congestion window addition parameter.
Definition tcp-ledbat.h:182
void AddDelay(OwdCircBuf &cb, uint32_t owd, uint32_t maxlen)
Add new delay to the buffers.
OwdCircBuf m_noiseFilter
Buffer to store the current delay.
Definition tcp-ledbat.h:184
SlowStartType
The slowstart types.
Definition tcp-ledbat.h:36
@ DO_NOT_SLOWSTART
Do not Slow Start.
Definition tcp-ledbat.h:37
@ DO_SLOWSTART
Do NewReno Slow Start.
Definition tcp-ledbat.h:38
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Get information from the acked packet.
TcpLedbat()
Create an unbound tcp socket.
Definition tcp-ledbat.cc:85
~TcpLedbat() override
Destructor.
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Reduce Congestion.
void InitCircBuf(OwdCircBuf &buffer)
Initialise a new buffer.
Definition tcp-ledbat.cc:97
static uint32_t MinCircBuf(OwdCircBuf &b)
Return the minimum delay of the buffer.
Time m_target
Target Queue Delay.
Definition tcp-ledbat.h:176
Time m_lastRollover
Timestamp of last added delay.
Definition tcp-ledbat.h:181
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition tcp-ledbat.h:179
uint32_t m_noiseFilterLen
Length of current delay buffer.
Definition tcp-ledbat.h:180
uint32_t(* FilterFunction)(OwdCircBuf &)
Filter function used by LEDBAT for current delay.
Definition tcp-ledbat.h:135
OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition tcp-ledbat.h:183
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:323
AttributeValue implementation for Time.
Definition nstime.h:1375
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Hold an unsigned integer type.
Definition uinteger.h:34
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
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:32
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:223
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:1376
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:35
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:274
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:181
Ptr< T > CopyObject(Ptr< const T > object)
Definition object.h:597
Buffer structure to store delays.
Definition tcp-ledbat.h:122
size_t min
The index of minimum value.
Definition tcp-ledbat.h:124
std::vector< uint32_t > buffer
Vector to store the delay.
Definition tcp-ledbat.h:123