A Discrete-Event Network Simulator
API
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 
22 namespace ns3
23 {
24 
25 NS_LOG_COMPONENT_DEFINE("TcpCongestionOps");
26 
27 NS_OBJECT_ENSURE_REGISTERED(TcpCongestionOps);
28 
29 TypeId
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 
51 void
53 {
54  NS_LOG_FUNCTION(this << tcb << segmentsAcked);
55 }
56 
57 void
58 TcpCongestionOps::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt)
59 {
60  NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
61 }
62 
63 void
65  const TcpSocketState::TcpCongState_t newState)
66 {
67  NS_LOG_FUNCTION(this << tcb << newState);
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION(this << tcb << event);
74 }
75 
76 bool
78 {
79  return false;
80 }
81 
82 void
84  const TcpRateOps::TcpRateConnection& /* rc */,
85  const TcpRateOps::TcpRateSample& /* rs */)
86 {
87  NS_LOG_FUNCTION(this << tcb);
88 }
89 
90 // RENO
91 
93 
94 TypeId
96 {
97  static TypeId tid = TypeId("ns3::TcpNewReno")
99  .SetGroupName("Internet")
100  .AddConstructor<TcpNewReno>();
101  return tid;
102 }
103 
105  : TcpCongestionOps()
106 {
107  NS_LOG_FUNCTION(this);
108 }
109 
111  : TcpCongestionOps(sock)
112 {
113  NS_LOG_FUNCTION(this);
114 }
115 
117 {
118 }
119 
162 uint32_t
163 TcpNewReno::SlowStart(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
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 
187 void
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 
212 void
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 
237 std::string
239 {
240  return "TcpNewReno";
241 }
242 
243 uint32_t
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
#define max(a, b)
Definition: 80211b.c:42
A base class which provides memory management and object aggregation.
Definition: object.h:89
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.
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:105
T Get() const
Get the underlying value.
Definition: traced-value.h:249
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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