A Discrete-Event Network Simulator
API
tcp-scalable.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
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  * Authors: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
19  * Keerthi Ganta <keerthig@ittc.ku.edu>
20  * Md. Moshfequr Rahman <moshfequr@ittc.ku.edu>
21  * Amir Modarresi <amodarresi@ittc.ku.edu>
22  *
23  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
24  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
25  * Information and Telecommunication Technology Center (ITTC)
26  * and Department of Electrical Engineering and Computer Science
27  * The University of Kansas Lawrence, KS USA.
28  */
29 
30 #include "tcp-scalable.h"
31 #include "tcp-socket-state.h"
32 
33 #include "ns3/log.h"
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("TcpScalable");
38 NS_OBJECT_ENSURE_REGISTERED (TcpScalable);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::TcpScalable")
45  .AddConstructor<TcpScalable> ()
46  .SetGroupName ("Internet")
47  .AddAttribute ("AIFactor", "Additive Increase Factor",
48  UintegerValue (50),
50  MakeUintegerChecker<uint32_t> ())
51  .AddAttribute ("MDFactor", "Multiplicative Decrease Factor",
52  DoubleValue (0.125),
54  MakeDoubleChecker<double> ())
55  ;
56  return tid;
57 }
58 
60  : TcpNewReno (),
61  m_ackCnt (0),
62  m_aiFactor (50),
63  m_mdFactor (0.125)
64 {
65  NS_LOG_FUNCTION (this);
66 }
67 
69  : TcpNewReno (sock),
70  m_ackCnt (sock.m_ackCnt),
71  m_aiFactor (sock.m_aiFactor),
72  m_mdFactor (sock.m_mdFactor)
73 {
74  NS_LOG_FUNCTION (this);
75 }
76 
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
84 {
85  return CopyObject<TcpScalable> (this);
86 }
87 
88 void
90  uint32_t segmentsAcked)
91 {
92  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
93 
94  uint32_t segCwnd = tcb->GetCwndInSegments ();
95  NS_ASSERT (segCwnd >= 1);
96 
97  uint32_t oldCwnd = segCwnd;
98  uint32_t w = std::min (segCwnd, m_aiFactor);
99 
100  if (m_ackCnt >= w)
101  {
102  m_ackCnt = 0;
103  segCwnd++;
104  }
105 
106  m_ackCnt += segmentsAcked;
107  if (m_ackCnt >= w)
108  {
109  uint32_t delta = m_ackCnt / w;
110  m_ackCnt = 0;
111  segCwnd += delta;
112  }
113 
114  if (segCwnd != oldCwnd)
115  {
116  tcb->m_cWnd = segCwnd * tcb->m_segmentSize;
117  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
118  " ssthresh " << tcb->m_ssThresh);
119  }
120 }
121 
122 std::string
124 {
125  return "TcpScalable";
126 }
127 
128 uint32_t
130  uint32_t bytesInFlight)
131 {
132  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
133 
134  uint32_t segCwnd = bytesInFlight / tcb->m_segmentSize;
135 
136  double b = 1.0 - m_mdFactor;
137  uint32_t ssThresh = static_cast<uint32_t> (std::max (2.0, segCwnd * b));
138 
139  NS_LOG_DEBUG ("Calculated b(w) = " << b <<
140  " resulting (in segment) ssThresh=" << ssThresh);
141 
142  return ssThresh * tcb->m_segmentSize;
143 }
144 
145 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
The NewReno implementation.
An implementation of TCP Scalable.
Definition: tcp-scalable.h:65
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-scalable.cc:41
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-scalable.cc:83
TcpScalable(void)
Create an unbound tcp socket.
Definition: tcp-scalable.cc:59
uint32_t m_ackCnt
Number of received ACK.
Definition: tcp-scalable.h:111
uint32_t m_aiFactor
Additive increase factor.
Definition: tcp-scalable.h:112
double m_mdFactor
Multiplicative decrease factor.
Definition: tcp-scalable.h:113
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance of TcpScalable (Equation 1)
Definition: tcp-scalable.cc:89
virtual std::string GetName() const
Get the name of the congestion control algorithm.
virtual ~TcpScalable(void)
Definition: tcp-scalable.cc:77
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold following Scalable principle (Equation 2)
uint32_t m_segmentSize
Segment size.
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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.