A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
tcp-linux-reno.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2019 NITK Surathkal
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Apoorva Bhargava <apoorvabhargava13@gmail.com>
19
* Mohit P. Tahiliani <tahiliani@nitk.edu.in>
20
*
21
*/
22
23
#include "
tcp-linux-reno.h
"
24
#include "ns3/log.h"
25
#include "ns3/simulator.h"
26
27
namespace
ns3
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"TcpLinuxReno"
);
30
NS_OBJECT_ENSURE_REGISTERED
(TcpLinuxReno);
31
32
TypeId
33
TcpLinuxReno::GetTypeId
(
void
)
34
{
35
static
TypeId
tid =
TypeId
(
"ns3::TcpLinuxReno"
)
36
.
SetParent
<
TcpCongestionOps
> ()
37
.SetGroupName (
"Internet"
)
38
.AddConstructor<
TcpLinuxReno
> ()
39
;
40
return
tid;
41
}
42
43
TcpLinuxReno::TcpLinuxReno
(
void
) :
TcpCongestionOps
()
44
{
45
NS_LOG_FUNCTION
(
this
);
46
}
47
48
TcpLinuxReno::TcpLinuxReno
(
const
TcpLinuxReno
& sock)
49
:
TcpCongestionOps
(sock)
50
{
51
NS_LOG_FUNCTION
(
this
);
52
}
53
54
TcpLinuxReno::~TcpLinuxReno
(
void
)
55
{
56
}
57
58
uint32_t
59
TcpLinuxReno::SlowStart
(
Ptr<TcpSocketState>
tcb, uint32_t segmentsAcked)
60
{
61
NS_LOG_FUNCTION
(
this
<< tcb << segmentsAcked);
62
63
if
(segmentsAcked >= 1)
64
{
65
uint32_t sndCwnd = tcb->
m_cWnd
;
66
tcb->
m_cWnd
=
std::min
((sndCwnd + (segmentsAcked * tcb->
m_segmentSize
)), (uint32_t)tcb->
m_ssThresh
);
67
NS_LOG_INFO
(
"In SlowStart, updated to cwnd "
<< tcb->
m_cWnd
<<
" ssthresh "
<< tcb->
m_ssThresh
);
68
return
segmentsAcked - ((tcb->
m_cWnd
- sndCwnd) / tcb->
m_segmentSize
);
69
}
70
71
return
0;
72
}
73
74
void
75
TcpLinuxReno::CongestionAvoidance
(
Ptr<TcpSocketState>
tcb, uint32_t segmentsAcked)
76
{
77
NS_LOG_FUNCTION
(
this
<< tcb << segmentsAcked);
78
79
uint32_t w = tcb->
m_cWnd
/ tcb->
m_segmentSize
;
80
81
// Floor w to 1 if w == 0
82
if
(w == 0)
83
{
84
w = 1;
85
}
86
87
NS_LOG_DEBUG
(
"w in segments "
<< w <<
" m_cWndCnt "
<<
m_cWndCnt
<<
" segments acked "
<< 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
<<
" m_cWndCnt: "
<<
m_cWndCnt
);
106
}
107
108
void
109
TcpLinuxReno::IncreaseWindow
(
Ptr<TcpSocketState>
tcb, uint32_t segmentsAcked)
110
{
111
NS_LOG_FUNCTION
(
this
<< tcb << segmentsAcked);
112
113
// Linux tcp_in_slow_start() condition
114
if
(tcb->
m_cWnd
< tcb->
m_ssThresh
)
115
{
116
NS_LOG_DEBUG
(
"In slow start, m_cWnd "
<< tcb->
m_cWnd
<<
" m_ssThresh "
<< tcb->
m_ssThresh
);
117
segmentsAcked =
SlowStart
(tcb, segmentsAcked);
118
}
119
else
120
{
121
NS_LOG_DEBUG
(
"In cong. avoidance, m_cWnd "
<< tcb->
m_cWnd
<<
" m_ssThresh "
<< tcb->
m_ssThresh
);
122
CongestionAvoidance
(tcb, segmentsAcked);
123
}
124
}
125
126
std::string
127
TcpLinuxReno::GetName
()
const
128
{
129
return
"TcpLinuxReno"
;
130
}
131
132
uint32_t
133
TcpLinuxReno::GetSsThresh
(
Ptr<const TcpSocketState>
state,
134
uint32_t bytesInFlight)
135
{
136
NS_LOG_FUNCTION
(
this
<< state << bytesInFlight);
137
138
// In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
139
return
std::max<uint32_t> (2 * state->m_segmentSize, state->m_cWnd / 2);
140
}
141
142
Ptr<TcpCongestionOps>
143
TcpLinuxReno::Fork
()
144
{
145
return
CopyObject<TcpLinuxReno> (
this
);
146
}
147
148
}
// namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::TcpLinuxReno
Definition:
tcp-linux-reno.h:32
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
min
#define min(a, b)
Definition:
80211b.c:42
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpSocketState::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition:
tcp-socket-state.h:177
ns3::TcpLinuxReno::TcpLinuxReno
TcpLinuxReno()
Definition:
tcp-linux-reno.cc:43
tcp-linux-reno.h
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:923
ns3::TcpLinuxReno::Fork
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition:
tcp-linux-reno.cc:143
ns3::Ptr< TcpSocketState >
ns3::TcpLinuxReno::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
tcp-linux-reno.cc:33
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:281
ns3::TcpLinuxReno::~TcpLinuxReno
~TcpLinuxReno()
Definition:
tcp-linux-reno.cc:54
ns3::TcpLinuxReno::CongestionAvoidance
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance phase handler.
Definition:
tcp-linux-reno.cc:75
ns3::TcpCongestionOps
Congestion control abstract class.
Definition:
tcp-congestion-ops.h:52
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition:
log.h:273
ns3::TcpLinuxReno::GetSsThresh
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition:
tcp-linux-reno.cc:133
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:244
ns3::TcpSocketState::m_cWnd
TracedValue< uint32_t > m_cWnd
Congestion window.
Definition:
tcp-socket-state.h:165
ns3::TcpLinuxReno::m_cWndCnt
uint32_t m_cWndCnt
Linear increase counter.
Definition:
tcp-linux-reno.h:73
ns3::TcpLinuxReno::SlowStart
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Slow start phase handler.
Definition:
tcp-linux-reno.cc:59
ns3::TcpLinuxReno::IncreaseWindow
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
Definition:
tcp-linux-reno.cc:109
ns3::TcpLinuxReno::GetName
std::string GetName() const
Get the name of the congestion control algorithm.
Definition:
tcp-linux-reno.cc:127
ns3::TcpSocketState::m_ssThresh
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Definition:
tcp-socket-state.h:167
src
internet
model
tcp-linux-reno.cc
Generated on Fri Oct 1 2021 17:02:52 for ns-3 by
1.8.20