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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Apoorva Bhargava <apoorvabhargava13@gmail.com>
18 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
19 *
20 */
21
22#include "tcp-linux-reno.h"
23
24#include "ns3/log.h"
25#include "ns3/simulator.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("TcpLinuxReno");
31NS_OBJECT_ENSURE_REGISTERED(TcpLinuxReno);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::TcpLinuxReno")
38 .SetGroupName("Internet")
39 .AddConstructor<TcpLinuxReno>();
40 return tid;
41}
42
45{
46 NS_LOG_FUNCTION(this);
47}
48
50 : TcpCongestionOps(sock)
51{
52 NS_LOG_FUNCTION(this);
53}
54
56{
57}
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 // In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
151 return std::max<uint32_t>(2 * state->m_segmentSize, state->m_cWnd / 2);
152}
153
156{
157 return CopyObject<TcpLinuxReno>(this);
158}
159
160void
162{
163 NS_LOG_FUNCTION(this << value);
165}
166
167} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.