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 "ns3/tcp-socket-base.h"
32 #include "ns3/log.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("TcpScalable");
37 NS_OBJECT_ENSURE_REGISTERED (TcpScalable);
38 
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::TcpScalable")
44  .AddConstructor<TcpScalable> ()
45  .SetGroupName ("Internet")
46  .AddAttribute ("AIFactor", "Additive Increase Factor",
47  UintegerValue (50),
49  MakeUintegerChecker<uint32_t> ())
50  .AddAttribute ("MDFactor", "Multiplicative Decrease Factor",
51  DoubleValue (0.125),
53  MakeDoubleChecker<double> ())
54  ;
55  return tid;
56 }
57 
59  : TcpNewReno (),
60  m_ackCnt (0),
61  m_aiFactor (50),
62  m_mdFactor (0.125)
63 {
64  NS_LOG_FUNCTION (this);
65 }
66 
68  : TcpNewReno (sock),
69  m_ackCnt (sock.m_ackCnt),
70  m_aiFactor (sock.m_aiFactor),
71  m_mdFactor (sock.m_mdFactor)
72 {
73  NS_LOG_FUNCTION (this);
74 }
75 
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
83 {
84  return CopyObject<TcpScalable> (this);
85 }
86 
87 void
89  uint32_t segmentsAcked)
90 {
91  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
92 
93  uint32_t segCwnd = tcb->GetCwndInSegments ();
94  uint32_t oldCwnd = segCwnd;
95  uint32_t w = std::min (segCwnd, m_aiFactor);
96 
97  if (m_ackCnt >= w)
98  {
99  m_ackCnt = 0;
100  segCwnd++;
101  }
102 
103  m_ackCnt += segmentsAcked;
104  if (m_ackCnt >= w)
105  {
106  uint32_t delta = m_ackCnt / w;
107  m_ackCnt = 0;
108  segCwnd += delta;
109  }
110 
111  if (segCwnd != oldCwnd)
112  {
113  tcb->m_cWnd = segCwnd * tcb->m_segmentSize;
114  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
115  " ssthresh " << tcb->m_ssThresh);
116  }
117 }
118 
119 std::string
121 {
122  return "TcpScalable";
123 }
124 
125 uint32_t
127  uint32_t bytesInFlight)
128 {
129  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
130 
131  uint32_t segCwnd = bytesInFlight / tcb->m_segmentSize;
132 
133  double b = 1.0 - m_mdFactor;
134  uint32_t ssThresh = std::max (2.0, segCwnd * b);
135 
136  NS_LOG_DEBUG ("Calculated b(w) = " << b <<
137  " resulting (in segment) ssThresh=" << ssThresh);
138 
139  return ssThresh * tcb->m_segmentSize;
140 }
141 
142 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#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
#define min(a, b)
Definition: 80211b.c:44
virtual ~TcpScalable(void)
Definition: tcp-scalable.cc:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t m_segmentSize
Segment size.
double m_mdFactor
Multiplicative decrease factor.
Definition: tcp-scalable.h:111
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-scalable.cc:40
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
uint32_t m_aiFactor
Additive increase factor.
Definition: tcp-scalable.h:110
The NewReno implementation.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance of TcpScalable (Equation 1)
Definition: tcp-scalable.cc:88
#define max(a, b)
Definition: 80211b.c:45
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-scalable.cc:82
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
An implementation of TCP Scalable.
Definition: tcp-scalable.h:62
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedValue< uint32_t > m_cWnd
Congestion window.
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
TcpScalable(void)
Create an unbound tcp socket.
Definition: tcp-scalable.cc:58
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
uint32_t m_ackCnt
Number of received ACK.
Definition: tcp-scalable.h:109
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold following Scalable principle (Equation 2)
virtual std::string GetName() const
Get the name of the congestion control algorithm.