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 uint32_t w = tcb->m_cWnd / tcb->m_segmentSize;
83
84 // Floor w to 1 if w == 0
85 if (w == 0)
86 {
87 w = 1;
88 }
89
90 NS_LOG_DEBUG("w in segments " << w << " m_cWndCnt " << m_cWndCnt << " segments acked "
91 << segmentsAcked);
92 if (m_cWndCnt >= w)
93 {
94 m_cWndCnt = 0;
95 tcb->m_cWnd += tcb->m_segmentSize;
96 NS_LOG_DEBUG("Adding 1 segment to m_cWnd");
97 }
98
99 m_cWndCnt += segmentsAcked;
100 NS_LOG_DEBUG("Adding 1 segment to m_cWndCnt");
101 if (m_cWndCnt >= w)
102 {
103 uint32_t delta = m_cWndCnt / w;
104
105 m_cWndCnt -= delta * w;
106 tcb->m_cWnd += delta * tcb->m_segmentSize;
107 NS_LOG_DEBUG("Subtracting delta * w from m_cWndCnt " << delta * w);
108 }
109 NS_LOG_DEBUG("At end of CongestionAvoidance(), m_cWnd: " << tcb->m_cWnd
110 << " m_cWndCnt: " << m_cWndCnt);
111}
112
113void
115{
116 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
117
118 // Linux tcp_in_slow_start() condition
119 if (tcb->m_cWnd < tcb->m_ssThresh)
120 {
121 NS_LOG_DEBUG("In slow start, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
122 segmentsAcked = SlowStart(tcb, segmentsAcked);
123 }
124 else
125 {
126 NS_LOG_DEBUG("In cong. avoidance, m_cWnd " << tcb->m_cWnd << " m_ssThresh "
127 << tcb->m_ssThresh);
128 CongestionAvoidance(tcb, segmentsAcked);
129 }
130}
131
132std::string
134{
135 return "TcpLinuxReno";
136}
137
140{
141 NS_LOG_FUNCTION(this << state << bytesInFlight);
142
143 // In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
144 return std::max<uint32_t>(2 * state->m_segmentSize, state->m_cWnd / 2);
145}
146
149{
150 return CopyObject<TcpLinuxReno>(this);
151}
152
153} // 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.
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.
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.