A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-congestion-ops.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
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 */
18#include "tcp-congestion-ops.h"
19
20#include "ns3/log.h"
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("TcpCongestionOps");
26
27NS_OBJECT_ENSURE_REGISTERED(TcpCongestionOps);
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::TcpCongestionOps").SetParent<Object>().SetGroupName("Internet");
34 return tid;
35}
36
38 : Object()
39{
40}
41
43 : Object(other)
44{
45}
46
48{
49}
50
51void
53{
54 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
55}
56
57void
59{
60 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
61}
62
63void
65 const TcpSocketState::TcpCongState_t newState)
66{
67 NS_LOG_FUNCTION(this << tcb << newState);
68}
69
70void
72{
73 NS_LOG_FUNCTION(this << tcb << event);
74}
75
76bool
78{
79 return false;
80}
81
82void
84 const TcpRateOps::TcpRateConnection& /* rc */,
85 const TcpRateOps::TcpRateSample& /* rs */)
86{
87 NS_LOG_FUNCTION(this << tcb);
88}
89
90// RENO
91
93
96{
97 static TypeId tid = TypeId("ns3::TcpNewReno")
99 .SetGroupName("Internet")
100 .AddConstructor<TcpNewReno>();
101 return tid;
102}
103
106{
107 NS_LOG_FUNCTION(this);
108}
109
111 : TcpCongestionOps(sock)
112{
113 NS_LOG_FUNCTION(this);
114}
115
117{
118}
119
120/**
121 * \brief Tcp NewReno slow start algorithm
122 *
123 * Defined in RFC 5681 as
124 *
125 * > During slow start, a TCP increments cwnd by at most SMSS bytes for
126 * > each ACK received that cumulatively acknowledges new data. Slow
127 * > start ends when cwnd exceeds ssthresh (or, optionally, when it
128 * > reaches it, as noted above) or when congestion is observed. While
129 * > traditionally TCP implementations have increased cwnd by precisely
130 * > SMSS bytes upon receipt of an ACK covering new data, we RECOMMEND
131 * > that TCP implementations increase cwnd, per:
132 * >
133 * > cwnd += min (N, SMSS) (2)
134 * >
135 * > where N is the number of previously unacknowledged bytes acknowledged
136 * > in the incoming ACK.
137 *
138 * The ns-3 implementation respect the RFC definition. Linux does something
139 * different:
140 * \verbatim
141u32 tcp_slow_start(struct tcp_sock *tp, u32 acked)
142 {
143 u32 cwnd = tp->snd_cwnd + acked;
144
145 if (cwnd > tp->snd_ssthresh)
146 cwnd = tp->snd_ssthresh + 1;
147 acked -= cwnd - tp->snd_cwnd;
148 tp->snd_cwnd = min(cwnd, tp->snd_cwnd_clamp);
149
150 return acked;
151 }
152 \endverbatim
153 *
154 * As stated, we want to avoid the case when a cumulative ACK increases cWnd more
155 * than a segment size, but we keep count of how many segments we have ignored,
156 * and return them.
157 *
158 * \param tcb internal congestion state
159 * \param segmentsAcked count of segments acked
160 * \return the number of segments not considered for increasing the cWnd
161 */
164{
165 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
166
167 if (segmentsAcked >= 1)
168 {
169 tcb->m_cWnd += tcb->m_segmentSize;
170 NS_LOG_INFO("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh "
171 << tcb->m_ssThresh);
172 return segmentsAcked - 1;
173 }
174
175 return 0;
176}
177
178/**
179 * \brief NewReno congestion avoidance
180 *
181 * During congestion avoidance, cwnd is incremented by roughly 1 full-sized
182 * segment per round-trip time (RTT).
183 *
184 * \param tcb internal congestion state
185 * \param segmentsAcked count of segments acked
186 */
187void
189{
190 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
191
192 if (segmentsAcked > 0)
193 {
194 double adder =
195 static_cast<double>(tcb->m_segmentSize * tcb->m_segmentSize) / tcb->m_cWnd.Get();
196 adder = std::max(1.0, adder);
197 tcb->m_cWnd += static_cast<uint32_t>(adder);
198 NS_LOG_INFO("In CongAvoid, updated to cwnd " << tcb->m_cWnd << " ssthresh "
199 << tcb->m_ssThresh);
200 }
201}
202
203/**
204 * \brief Try to increase the cWnd following the NewReno specification
205 *
206 * \see SlowStart
207 * \see CongestionAvoidance
208 *
209 * \param tcb internal congestion state
210 * \param segmentsAcked count of segments acked
211 */
212void
214{
215 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
216
217 if (tcb->m_cWnd < tcb->m_ssThresh)
218 {
219 segmentsAcked = SlowStart(tcb, segmentsAcked);
220 }
221
222 if (tcb->m_cWnd >= tcb->m_ssThresh)
223 {
224 CongestionAvoidance(tcb, segmentsAcked);
225 }
226
227 /* At this point, we could have segmentsAcked != 0. This because RFC says
228 * that in slow start, we should increase cWnd by min (N, SMSS); if in
229 * slow start we receive a cumulative ACK, it counts only for 1 SMSS of
230 * increase, wasting the others.
231 *
232 * // Incorrect assert, I am sorry
233 * NS_ASSERT (segmentsAcked == 0);
234 */
235}
236
237std::string
239{
240 return "TcpNewReno";
241}
242
245{
246 NS_LOG_FUNCTION(this << state << bytesInFlight);
247
248 return std::max(2 * state->m_segmentSize, bytesInFlight / 2);
249}
250
253{
254 return CopyObject<TcpNewReno>(this);
255}
256
257} // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Congestion control abstract class.
virtual void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Trigger events/calculations on occurrence of congestion window event.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
virtual void CongControl(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateConnection &rc, const TcpRateOps::TcpRateSample &rs)
Called when packets are delivered to update cwnd and pacing rate.
static TypeId GetTypeId()
Get the type ID.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
virtual bool HasCongControl() const
Returns true when Congestion Control Algorithm implements CongControl.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Trigger events/calculations specific to a congestion state.
The NewReno implementation.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
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.
void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Try to increase the cWnd following the NewReno specification.
static TypeId GetTypeId()
Get the type ID.
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
TcpCAEvent_t
Congestion avoidance events.
TcpCongState_t
Definition of the Congestion state machine.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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_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.
Information about the connection rate.
Definition: tcp-rate-ops.h:174
Rate Sample structure.
Definition: tcp-rate-ops.h:140