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 "tcp-socket-base.h"
21 #include "ns3/log.h"
22 
23 namespace ns3 {
24 
25 NS_LOG_COMPONENT_DEFINE ("TcpCongestionOps");
26 
27 NS_OBJECT_ENSURE_REGISTERED (TcpCongestionOps);
28 
29 TypeId
31 {
32  static TypeId tid = TypeId ("ns3::TcpCongestionOps")
33  .SetParent<Object> ()
34  .SetGroupName ("Internet")
35  ;
36  return tid;
37 }
38 
40 {
41 }
42 
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,
59  const Time& rtt)
60 {
61  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
62 }
63 
64 void
66  const TcpSocketState::TcpCongState_t newState)
67 {
68  NS_LOG_FUNCTION (this << tcb << newState);
69 }
70 
71 void
73  const TcpSocketState::TcpCAEvent_t event)
74 {
75  NS_LOG_FUNCTION (this << tcb << event);
76 }
77 
78 bool
80 {
81  return false;
82 }
83 
84 void
87  const TcpRateOps::TcpRateSample &rs)
88 {
89  NS_LOG_FUNCTION (this << tcb);
90  NS_UNUSED (rc);
91  NS_UNUSED (rs);
92 }
93 
94 // RENO
95 
97 
98 TypeId
100 {
101  static TypeId tid = TypeId ("ns3::TcpNewReno")
103  .SetGroupName ("Internet")
104  .AddConstructor<TcpNewReno> ()
105  ;
106  return tid;
107 }
108 
110 {
111  NS_LOG_FUNCTION (this);
112 }
113 
115  : TcpCongestionOps (sock)
116 {
117  NS_LOG_FUNCTION (this);
118 }
119 
121 {
122 }
123 
166 uint32_t
167 TcpNewReno::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
168 {
169  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
170 
171  if (segmentsAcked >= 1)
172  {
173  tcb->m_cWnd += tcb->m_segmentSize;
174  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
175  return segmentsAcked - 1;
176  }
177 
178  return 0;
179 }
180 
190 void
192 {
193  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
194 
195  if (segmentsAcked > 0)
196  {
197  double adder = static_cast<double> (tcb->m_segmentSize * tcb->m_segmentSize) / tcb->m_cWnd.Get ();
198  adder = std::max (1.0, adder);
199  tcb->m_cWnd += static_cast<uint32_t> (adder);
200  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
201  " ssthresh " << tcb->m_ssThresh);
202  }
203 }
204 
214 void
215 TcpNewReno::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
216 {
217  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
218 
219  if (tcb->m_cWnd < tcb->m_ssThresh)
220  {
221  segmentsAcked = SlowStart (tcb, segmentsAcked);
222  }
223 
224  if (tcb->m_cWnd >= tcb->m_ssThresh)
225  {
226  CongestionAvoidance (tcb, segmentsAcked);
227  }
228 
229  /* At this point, we could have segmentsAcked != 0. This because RFC says
230  * that in slow start, we should increase cWnd by min (N, SMSS); if in
231  * slow start we receive a cumulative ACK, it counts only for 1 SMSS of
232  * increase, wasting the others.
233  *
234  * // Incorrect assert, I am sorry
235  * NS_ASSERT (segmentsAcked == 0);
236  */
237 }
238 
239 std::string
241 {
242  return "TcpNewReno";
243 }
244 
245 uint32_t
247  uint32_t bytesInFlight)
248 {
249  NS_LOG_FUNCTION (this << state << bytesInFlight);
250 
251  return std::max (2 * state->m_segmentSize, bytesInFlight / 2);
252 }
253 
256 {
257  return CopyObject<TcpNewReno> (this);
258 }
259 
260 } // namespace ns3
261 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uint32_t m_segmentSize
Segment size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
The NewReno implementation.
virtual void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Trigger events/calculations on occurrence of congestion window event.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
static TypeId GetTypeId(void)
Get the type ID.
Rate Sample structure.
Definition: tcp-rate-ops.h:131
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
#define max(a, b)
Definition: 80211b.c:43
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
TcpCongState_t
Definition of the Congestion state machine.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Congestion control abstract class.
TracedValue< uint32_t > m_cWnd
Congestion window.
Information about the connection rate.
Definition: tcp-rate-ops.h:160
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
std::string GetName() const
Get the name of the congestion control algorithm.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Trigger events/calculations specific to a congestion state.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual bool HasCongControl() const
Returns true when Congestion Control Algorithm implements CongControl.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
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.