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 
52 // RENO
53 
55 
56 TypeId
58 {
59  static TypeId tid = TypeId ("ns3::TcpNewReno")
61  .SetGroupName ("Internet")
62  .AddConstructor<TcpNewReno> ()
63  ;
64  return tid;
65 }
66 
68 {
69  NS_LOG_FUNCTION (this);
70 }
71 
73  : TcpCongestionOps (sock)
74 {
75  NS_LOG_FUNCTION (this);
76 }
77 
79 {
80 }
81 
124 uint32_t
125 TcpNewReno::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
126 {
127  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
128 
129  if (segmentsAcked >= 1)
130  {
131  tcb->m_cWnd += tcb->m_segmentSize;
132  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
133  return segmentsAcked - 1;
134  }
135 
136  return 0;
137 }
138 
148 void
150 {
151  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
152 
153  if (segmentsAcked > 0)
154  {
155  double adder = static_cast<double> (tcb->m_segmentSize * tcb->m_segmentSize) / tcb->m_cWnd.Get ();
156  adder = std::max (1.0, adder);
157  tcb->m_cWnd += static_cast<uint32_t> (adder);
158  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
159  " ssthresh " << tcb->m_ssThresh);
160  }
161 }
162 
172 void
173 TcpNewReno::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
174 {
175  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
176 
177  if (tcb->m_cWnd < tcb->m_ssThresh)
178  {
179  segmentsAcked = SlowStart (tcb, segmentsAcked);
180  }
181 
182  if (tcb->m_cWnd >= tcb->m_ssThresh)
183  {
184  CongestionAvoidance (tcb, segmentsAcked);
185  }
186 
187  /* At this point, we could have segmentsAcked != 0. This because RFC says
188  * that in slow start, we should increase cWnd by min (N, SMSS); if in
189  * slow start we receive a cumulative ACK, it counts only for 1 SMSS of
190  * increase, wasting the others.
191  *
192  * // Incorrect assert, I am sorry
193  * NS_ASSERT (segmentsAcked == 0);
194  */
195 }
196 
197 std::string
199 {
200  return "TcpNewReno";
201 }
202 
203 uint32_t
205  uint32_t bytesInFlight)
206 {
207  NS_LOG_FUNCTION (this << state << bytesInFlight);
208 
209  return std::max (2 * state->m_segmentSize, bytesInFlight / 2);
210 }
211 
214 {
215  return CopyObject<TcpNewReno> (this);
216 }
217 
218 } // namespace ns3
219 
#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 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:202
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:278
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
The NewReno implementation.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
std::string GetName() const
Get the name of the congestion control algorithm.
static TypeId GetTypeId(void)
Get the type ID.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Congestion control abstract class.
TracedValue< uint32_t > m_cWnd
Congestion window.
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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915