A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-linux-reno.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Apoorva Bhargava <apoorvabhargava13@gmail.com>
7 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
8 *
9 */
10
11#include "tcp-linux-reno.h"
12
13#include "ns3/log.h"
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("TcpLinuxReno");
21
24{
25 static TypeId tid = TypeId("ns3::TcpLinuxReno")
27 .SetGroupName("Internet")
28 .AddConstructor<TcpLinuxReno>()
29 .AddAttribute("BetaLoss",
30 "Beta for multiplicative decrease",
31 DoubleValue(0.5),
34 .AddAttribute("BetaEcn",
35 "Beta for multiplicative decrease for ABE",
36 DoubleValue(0.7), // According to RFC 8511 (ABE)
39
40 return tid;
41}
42
48
54
58
61{
62 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
63
64 if (segmentsAcked >= 1)
65 {
66 uint32_t sndCwnd = tcb->m_cWnd;
67 tcb->m_cWnd =
68 std::min((sndCwnd + (segmentsAcked * tcb->m_segmentSize)), (uint32_t)tcb->m_ssThresh);
69 NS_LOG_INFO("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh "
70 << tcb->m_ssThresh);
71 return segmentsAcked - ((tcb->m_cWnd - sndCwnd) / tcb->m_segmentSize);
72 }
73
74 return 0;
75}
76
77void
79{
80 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
81
82 if (m_suppressIncreaseIfCwndLimited && !tcb->m_isCwndLimited)
83 {
84 NS_LOG_DEBUG("No increase because current cwnd " << tcb->m_cWnd
85 << " is not limiting the flow");
86 return;
87 }
88
89 uint32_t w = tcb->m_cWnd / tcb->m_segmentSize;
90
91 // Floor w to 1 if w == 0
92 if (w == 0)
93 {
94 w = 1;
95 }
96
97 NS_LOG_DEBUG("w in segments " << w << " m_cWndCnt " << m_cWndCnt << " segments acked "
98 << segmentsAcked);
99 if (m_cWndCnt >= w)
100 {
101 m_cWndCnt = 0;
102 tcb->m_cWnd += tcb->m_segmentSize;
103 NS_LOG_DEBUG("Adding 1 segment to m_cWnd");
104 }
105
106 m_cWndCnt += segmentsAcked;
107 NS_LOG_DEBUG("Adding 1 segment to m_cWndCnt");
108 if (m_cWndCnt >= w)
109 {
110 uint32_t delta = m_cWndCnt / w;
111
112 m_cWndCnt -= delta * w;
113 tcb->m_cWnd += delta * tcb->m_segmentSize;
114 NS_LOG_DEBUG("Subtracting delta * w from m_cWndCnt " << delta * w);
115 }
116 NS_LOG_DEBUG("At end of CongestionAvoidance(), m_cWnd: " << tcb->m_cWnd
117 << " m_cWndCnt: " << m_cWndCnt);
118}
119
120void
122{
123 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
124
125 // Linux tcp_in_slow_start() condition
126 if (tcb->m_cWnd < tcb->m_ssThresh)
127 {
128 NS_LOG_DEBUG("In slow start, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
129 segmentsAcked = SlowStart(tcb, segmentsAcked);
130 }
131 else
132 {
133 NS_LOG_DEBUG("In cong. avoidance, m_cWnd " << tcb->m_cWnd << " m_ssThresh "
134 << tcb->m_ssThresh);
135 CongestionAvoidance(tcb, segmentsAcked);
136 }
137}
138
139std::string
141{
142 return "TcpLinuxReno";
143}
144
147{
148 NS_LOG_FUNCTION(this << state << bytesInFlight);
149
150 if (state->m_abeEnabled && state->m_ecnState == TcpSocketState::ECN_ECE_RCVD)
151 {
152 return std::max<uint32_t>(2 * state->m_segmentSize,
153 state->m_cWnd * m_betaEcn); // According to RFC 8511 (ABE)
154 }
155
156 return std::max<uint32_t>(2 * state->m_segmentSize, state->m_cWnd * m_betaLoss);
157}
158
161{
162 return CopyObject<TcpLinuxReno>(this);
163}
164
165void
171
172} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Reno congestion control algorithm.
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
bool m_suppressIncreaseIfCwndLimited
Suppress window increase if TCP is not cwnd limited.
std::string GetName() const override
Get the name of the congestion control algorithm.
static TypeId GetTypeId()
Get the type ID.
double m_betaEcn
Beta for Linux-Reno multiplicative decrease with ABE.
~TcpLinuxReno() override
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Slow start phase handler.
void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Congestion avoidance algorithm implementation.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance phase handler.
uint32_t m_cWndCnt
Linear increase counter.
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
double m_betaLoss
Beta for Linux-Reno multiplicative decrease.
void SetSuppressIncreaseIfCwndLimited(bool value)
TcpSocketBase follows the Linux way of setting a flag 'isCwndLimited' when BytesInFlight() >= cwnd.
@ ECN_ECE_RCVD
Last ACK received had ECE bit set in TCP header.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.