A Discrete-Event Network Simulator
API
tcp-congestion-ops.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
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 */
19#include "tcp-congestion-ops.h"
20#include "ns3/log.h"
21
22namespace ns3 {
23
24NS_LOG_COMPONENT_DEFINE ("TcpCongestionOps");
25
26NS_OBJECT_ENSURE_REGISTERED (TcpCongestionOps);
27
28TypeId
30{
31 static TypeId tid = TypeId ("ns3::TcpCongestionOps")
32 .SetParent<Object> ()
33 .SetGroupName ("Internet")
34 ;
35 return tid;
36}
37
39{
40}
41
43{
44}
45
47{
48}
49
50void
52{
53 NS_LOG_FUNCTION (this << tcb << segmentsAcked);
54}
55
56void
58 const Time& rtt)
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
73{
74 NS_LOG_FUNCTION (this << tcb << event);
75}
76
77bool
79{
80 return false;
81}
82
83void
85 [[maybe_unused]] const TcpRateOps::TcpRateConnection &rc,
86 [[maybe_unused]] const TcpRateOps::TcpRateSample &rs)
87{
88 NS_LOG_FUNCTION (this << tcb);
89}
90
91// RENO
92
94
97{
98 static TypeId tid = TypeId ("ns3::TcpNewReno")
100 .SetGroupName ("Internet")
101 .AddConstructor<TcpNewReno> ()
102 ;
103 return tid;
104}
105
107{
108 NS_LOG_FUNCTION (this);
109}
110
112 : TcpCongestionOps (sock)
113{
114 NS_LOG_FUNCTION (this);
115}
116
118{
119}
120
165{
166 NS_LOG_FUNCTION (this << tcb << segmentsAcked);
167
168 if (segmentsAcked >= 1)
169 {
170 tcb->m_cWnd += tcb->m_segmentSize;
171 NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
172 return segmentsAcked - 1;
173 }
174
175 return 0;
176}
177
187void
189{
190 NS_LOG_FUNCTION (this << tcb << segmentsAcked);
191
192 if (segmentsAcked > 0)
193 {
194 double adder = static_cast<double> (tcb->m_segmentSize * tcb->m_segmentSize) / tcb->m_cWnd.Get ();
195 adder = std::max (1.0, adder);
196 tcb->m_cWnd += static_cast<uint32_t> (adder);
197 NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
198 " ssthresh " << tcb->m_ssThresh);
199 }
200}
201
211void
213{
214 NS_LOG_FUNCTION (this << tcb << segmentsAcked);
215
216 if (tcb->m_cWnd < tcb->m_ssThresh)
217 {
218 segmentsAcked = SlowStart (tcb, segmentsAcked);
219 }
220
221 if (tcb->m_cWnd >= tcb->m_ssThresh)
222 {
223 CongestionAvoidance (tcb, segmentsAcked);
224 }
225
226 /* At this point, we could have segmentsAcked != 0. This because RFC says
227 * that in slow start, we should increase cWnd by min (N, SMSS); if in
228 * slow start we receive a cumulative ACK, it counts only for 1 SMSS of
229 * increase, wasting the others.
230 *
231 * // Incorrect assert, I am sorry
232 * NS_ASSERT (segmentsAcked == 0);
233 */
234}
235
236std::string
238{
239 return "TcpNewReno";
240}
241
244 uint32_t bytesInFlight)
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
258
#define max(a, b)
Definition: 80211b.c:43
A base class which provides memory management and object aggregation.
Definition: object.h:88
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.
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.
static TypeId GetTypeId(void)
Get the type ID.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Trigger events/calculations specific to a congestion state.
The NewReno implementation.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
std::string GetName() const
Get the name of the congestion control algorithm.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_segmentSize
Segment size.
TcpCAEvent_t
Congestion avoidance events.
TcpCongState_t
Definition of the Congestion state machine.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Information about the connection rate.
Definition: tcp-rate-ops.h:163
Rate Sample structure.
Definition: tcp-rate-ops.h:134