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 *
8 */
9
10#include "tcp-ledbat.h"
11
12#include "tcp-socket-state.h"
13
14#include "ns3/log.h"
15#include "ns3/simulator.h" // Now ()
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("TcpLedbat");
22
23TypeId
25{
26 static TypeId tid =
27 TypeId("ns3::TcpLedbat")
29 .AddConstructor<TcpLedbat>()
30 .SetGroupName("Internet")
31 .AddAttribute("TargetDelay",
32 "Targeted Queue Delay",
36 .AddAttribute("BaseHistoryLen",
37 "Number of Base delay samples",
38 UintegerValue(10),
41 .AddAttribute("NoiseFilterLen",
42 "Number of Current delay samples",
46 .AddAttribute("Gain",
47 "Offset Gain",
48 DoubleValue(1.0),
51 .AddAttribute("SSParam",
52 "Possibility of Slow Start",
56 .AddAttribute("MinCwnd",
57 "Minimum cWnd for Ledbat",
61 return tid;
62}
63
64void
66{
67 NS_LOG_FUNCTION(this << doSS);
68 m_doSs = doSS;
69 if (m_doSs)
70 {
72 }
73 else
74 {
75 m_flag &= ~LEDBAT_CAN_SS;
76 }
77}
78
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;
119}
120
125
128{
129 return CopyObject<TcpLedbat>(this);
130}
131
132std::string
134{
135 return "TcpLedbat";
136}
137
140{
142 if (b.buffer.empty())
143 {
144 return ~0U;
145 }
146 else
147 {
148 return b.buffer[b.min];
149 }
150}
151
153TcpLedbat::CurrentDelay(FilterFunction filter)
154{
155 NS_LOG_FUNCTION(this);
156 return filter(m_noiseFilter);
157}
158
165
166void
168{
169 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
170 if (tcb->m_cWnd.Get() <= tcb->m_segmentSize)
171 {
173 }
174 if (m_doSs == DO_SLOWSTART && tcb->m_cWnd <= tcb->m_ssThresh && (m_flag & LEDBAT_CAN_SS))
175 {
176 SlowStart(tcb, segmentsAcked);
177 }
178 else
179 {
180 m_flag &= ~LEDBAT_CAN_SS;
181 CongestionAvoidance(tcb, segmentsAcked);
182 }
183}
184
185void
187{
188 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
189 if ((m_flag & LEDBAT_VALID_OWD) == 0)
190 {
192 tcb,
193 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) +
219 segmentsAcked * tcb->m_segmentSize;
220 cwnd = std::min(cwnd, max_cwnd);
221 cwnd = std::max(cwnd, m_minCwnd * tcb->m_segmentSize);
222 tcb->m_cWnd = cwnd;
223
224 if (tcb->m_cWnd <= tcb->m_ssThresh)
225 {
226 tcb->m_ssThresh = tcb->m_cWnd - 1;
227 }
228}
229
230void
232{
233 NS_LOG_FUNCTION(this << owd << maxlen << cb.buffer.size());
234 if (cb.buffer.empty())
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
262void
264{
265 NS_LOG_FUNCTION(this << owd);
266 if (m_baseHistory.buffer.empty())
267 {
269 return;
270 }
271 uint64_t timestamp = static_cast<uint64_t>(Simulator::Now().GetSeconds());
272
273 if (timestamp - m_lastRollover > 60)
274 {
275 m_lastRollover = timestamp;
277 }
278 else
279 {
280 auto last = static_cast<uint32_t>(m_baseHistory.buffer.size() - 1);
281 if (owd < m_baseHistory.buffer[last])
282 {
283 m_baseHistory.buffer[last] = owd;
285 {
286 m_baseHistory.min = last;
287 }
288 }
289 }
290}
291
292void
294{
295 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
296 if (tcb->m_rcvTimestampValue == 0 || tcb->m_rcvTimestampEchoReply == 0)
297 {
298 m_flag &= ~LEDBAT_VALID_OWD;
299 }
300 else
301 {
303 }
304 if (rtt.IsPositive())
305 {
307 tcb->m_rcvTimestampValue - tcb->m_rcvTimestampEchoReply,
309 UpdateBaseDelay(tcb->m_rcvTimestampValue - tcb->m_rcvTimestampEchoReply);
310 }
311}
312
313} // 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
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
An implementation of LEDBAT.
Definition tcp-ledbat.h:29
static TypeId GetTypeId()
Get the type ID.
Definition tcp-ledbat.cc:24
SlowStartType m_doSs
Permissible Slow Start State.
Definition tcp-ledbat.h:177
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:185
void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Adjust cwnd following LEDBAT algorithm.
uint32_t m_flag
LEDBAT Flag.
Definition tcp-ledbat.h:184
uint32_t BaseDelay()
Return the value of base delay.
void SetDoSs(SlowStartType doSS)
Change the Slow Start Capability.
Definition tcp-ledbat.cc:65
double m_gain
GAIN value from RFC.
Definition tcp-ledbat.h:176
@ LEDBAT_CAN_SS
If LEDBAT allows Slow Start.
Definition tcp-ledbat.h:47
@ LEDBAT_VALID_OWD
If valid timestamps are present.
Definition tcp-ledbat.h:46
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
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:183
SlowStartType
The slowstart types.
Definition tcp-ledbat.h:35
@ DO_NOT_SLOWSTART
Do not Slow Start.
Definition tcp-ledbat.h:36
@ DO_SLOWSTART
Do NewReno Slow Start.
Definition tcp-ledbat.h:37
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:79
~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:175
int32_t m_sndCwndCnt
The congestion window addition parameter.
Definition tcp-ledbat.h:181
uint32_t m_baseHistoLen
Length of base delay history buffer.
Definition tcp-ledbat.h:178
uint32_t m_noiseFilterLen
Length of current delay buffer.
Definition tcp-ledbat.h:179
uint64_t m_lastRollover
Timestamp of last added delay.
Definition tcp-ledbat.h:180
OwdCircBuf m_baseHistory
Buffer to store the base delay.
Definition tcp-ledbat.h:182
uint32_t CurrentDelay(FilterFunction filter)
Return the value of current delay.
The NewReno implementation.
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:94
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:322
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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 MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
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:179
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:221
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
Buffer structure to store delays.
Definition tcp-ledbat.h:121
uint32_t min
The index of minimum value.
Definition tcp-ledbat.h:123
std::vector< uint32_t > buffer
Vector to store the delay.
Definition tcp-ledbat.h:122