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");
20NS_OBJECT_ENSURE_REGISTERED(TcpLinuxReno);
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::TcpLinuxReno")
27 .SetGroupName("Internet")
28 .AddConstructor<TcpLinuxReno>();
29 return tid;
30}
31
37
43
47
50{
51 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
52
53 if (segmentsAcked >= 1)
54 {
55 uint32_t sndCwnd = tcb->m_cWnd;
56 tcb->m_cWnd =
57 std::min((sndCwnd + (segmentsAcked * tcb->m_segmentSize)), (uint32_t)tcb->m_ssThresh);
58 NS_LOG_INFO("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh "
59 << tcb->m_ssThresh);
60 return segmentsAcked - ((tcb->m_cWnd - sndCwnd) / tcb->m_segmentSize);
61 }
62
63 return 0;
64}
65
66void
68{
69 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
70
71 if (m_suppressIncreaseIfCwndLimited && !tcb->m_isCwndLimited)
72 {
73 NS_LOG_DEBUG("No increase because current cwnd " << tcb->m_cWnd
74 << " is not limiting the flow");
75 return;
76 }
77
78 uint32_t w = tcb->m_cWnd / tcb->m_segmentSize;
79
80 // Floor w to 1 if w == 0
81 if (w == 0)
82 {
83 w = 1;
84 }
85
86 NS_LOG_DEBUG("w in segments " << w << " m_cWndCnt " << m_cWndCnt << " segments acked "
87 << segmentsAcked);
88 if (m_cWndCnt >= w)
89 {
90 m_cWndCnt = 0;
91 tcb->m_cWnd += tcb->m_segmentSize;
92 NS_LOG_DEBUG("Adding 1 segment to m_cWnd");
93 }
94
95 m_cWndCnt += segmentsAcked;
96 NS_LOG_DEBUG("Adding 1 segment to m_cWndCnt");
97 if (m_cWndCnt >= w)
98 {
99 uint32_t delta = m_cWndCnt / w;
100
101 m_cWndCnt -= delta * w;
102 tcb->m_cWnd += delta * tcb->m_segmentSize;
103 NS_LOG_DEBUG("Subtracting delta * w from m_cWndCnt " << delta * w);
104 }
105 NS_LOG_DEBUG("At end of CongestionAvoidance(), m_cWnd: " << tcb->m_cWnd
106 << " m_cWndCnt: " << m_cWndCnt);
107}
108
109void
111{
112 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
113
114 // Linux tcp_in_slow_start() condition
115 if (tcb->m_cWnd < tcb->m_ssThresh)
116 {
117 NS_LOG_DEBUG("In slow start, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
118 segmentsAcked = SlowStart(tcb, segmentsAcked);
119 }
120 else
121 {
122 NS_LOG_DEBUG("In cong. avoidance, m_cWnd " << tcb->m_cWnd << " m_ssThresh "
123 << tcb->m_ssThresh);
124 CongestionAvoidance(tcb, segmentsAcked);
125 }
126}
127
128std::string
130{
131 return "TcpLinuxReno";
132}
133
136{
137 NS_LOG_FUNCTION(this << state << bytesInFlight);
138
139 // In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
140 return std::max<uint32_t>(2 * state->m_segmentSize, state->m_cWnd / 2);
141}
142
145{
146 return CopyObject<TcpLinuxReno>(this);
147}
148
149void
155
156} // namespace ns3
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
Congestion control abstract class.
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.
~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.
void SetSuppressIncreaseIfCwndLimited(bool value)
TcpSocketBase follows the Linux way of setting a flag 'isCwndLimited' when BytesInFlight() >= cwnd.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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.