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 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("TcpCongestionOps");
25 
26 NS_OBJECT_ENSURE_REGISTERED (TcpCongestionOps);
27 
28 TypeId
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 
50 void
52 {
53  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
54 }
55 
56 void
57 TcpCongestionOps::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
58  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  const TcpSocketState::TcpCAEvent_t event)
73 {
74  NS_LOG_FUNCTION (this << tcb << event);
75 }
76 
77 bool
79 {
80  return false;
81 }
82 
83 void
86  const TcpRateOps::TcpRateSample &rs)
87 {
88  NS_LOG_FUNCTION (this << tcb);
89  NS_UNUSED (rc);
90  NS_UNUSED (rs);
91 }
92 
93 // RENO
94 
96 
97 TypeId
99 {
100  static TypeId tid = TypeId ("ns3::TcpNewReno")
102  .SetGroupName ("Internet")
103  .AddConstructor<TcpNewReno> ()
104  ;
105  return tid;
106 }
107 
109 {
110  NS_LOG_FUNCTION (this);
111 }
112 
114  : TcpCongestionOps (sock)
115 {
116  NS_LOG_FUNCTION (this);
117 }
118 
120 {
121 }
122 
165 uint32_t
166 TcpNewReno::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
167 {
168  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
169 
170  if (segmentsAcked >= 1)
171  {
172  tcb->m_cWnd += tcb->m_segmentSize;
173  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
174  return segmentsAcked - 1;
175  }
176 
177  return 0;
178 }
179 
189 void
191 {
192  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
193 
194  if (segmentsAcked > 0)
195  {
196  double adder = static_cast<double> (tcb->m_segmentSize * tcb->m_segmentSize) / tcb->m_cWnd.Get ();
197  adder = std::max (1.0, adder);
198  tcb->m_cWnd += static_cast<uint32_t> (adder);
199  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
200  " ssthresh " << tcb->m_ssThresh);
201  }
202 }
203 
213 void
214 TcpNewReno::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
215 {
216  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
217 
218  if (tcb->m_cWnd < tcb->m_ssThresh)
219  {
220  segmentsAcked = SlowStart (tcb, segmentsAcked);
221  }
222 
223  if (tcb->m_cWnd >= tcb->m_ssThresh)
224  {
225  CongestionAvoidance (tcb, segmentsAcked);
226  }
227 
228  /* At this point, we could have segmentsAcked != 0. This because RFC says
229  * that in slow start, we should increase cWnd by min (N, SMSS); if in
230  * slow start we receive a cumulative ACK, it counts only for 1 SMSS of
231  * increase, wasting the others.
232  *
233  * // Incorrect assert, I am sorry
234  * NS_ASSERT (segmentsAcked == 0);
235  */
236 }
237 
238 std::string
240 {
241  return "TcpNewReno";
242 }
243 
244 uint32_t
246  uint32_t bytesInFlight)
247 {
248  NS_LOG_FUNCTION (this << state << bytesInFlight);
249 
250  return std::max (2 * state->m_segmentSize, bytesInFlight / 2);
251 }
252 
253 void
255 {
256  NS_LOG_FUNCTION (this << tcb);
257 
258  tcb->m_cWnd = std::max (tcb->m_cWnd.Get () / 2, tcb->m_segmentSize);
259 }
260 
263 {
264  return CopyObject<TcpNewReno> (this);
265 }
266 
267 } // namespace ns3
268 
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:205
#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:281
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 void ReduceCwnd(Ptr< TcpSocketState > tcb)
Reduces congestion window on receipt of ECN Echo Flag.
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:132
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:161
T Get(void) const
Get the underlying value.
Definition: traced-value.h:227
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:922
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.