A Discrete-Event Network Simulator
API
tcp-htcp.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 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  * by: Amir Modarresi <amodarresi@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  */
26 
27 #include "tcp-htcp.h"
28 #include "ns3/log.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("TcpHtcp");
33 
35 
37 {
38  static TypeId tid = TypeId ("ns3::TcpHtcp")
40  .AddConstructor<TcpHtcp> ()
41  .SetGroupName ("Internet")
42  .AddAttribute ("DefaultBackoff",
43  "The default AIMD backoff factor",
44  DoubleValue (0.5),
46  MakeDoubleChecker<double> (0,1))
47  .AddAttribute ("ThroughputRatio",
48  "Threshold value for updating beta",
49  DoubleValue (0.2),
51  MakeDoubleChecker<double> ())
52  .AddAttribute ("DeltaL",
53  "Delta_L parameter in increase function",
54  TimeValue (Seconds (1)),
56  MakeTimeChecker ())
57  ;
58  return tid;
59 }
60 
61 std::string TcpHtcp::GetName () const
62 {
63  return "TcpHtcp";
64 }
65 
67  : TcpNewReno (),
68  m_alpha (0),
69  m_beta (0),
70  m_delta (0),
71  m_lastCon (0),
72  m_minRtt (Time::Max ()),
73  m_maxRtt (Time::Min ()),
74  m_throughput (0),
75  m_lastThroughput (0),
76  m_dataSent (0)
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
82  : TcpNewReno (sock),
83  m_alpha (sock.m_alpha),
84  m_beta (sock.m_beta),
85  m_defaultBackoff (sock.m_defaultBackoff),
86  m_throughputRatio (sock.m_throughputRatio),
87  m_delta (sock.m_delta),
88  m_deltaL (sock.m_deltaL),
89  m_lastCon (sock.m_lastCon),
90  m_minRtt (sock.m_minRtt),
91  m_maxRtt (sock.m_maxRtt),
92  m_throughput (sock.m_throughput),
93  m_lastThroughput (sock.m_lastThroughput),
94  m_dataSent (sock.m_dataSent)
95 {
96  NS_LOG_FUNCTION (this);
97 }
98 
100 {
101  NS_LOG_FUNCTION (this);
102 }
103 
105 {
106  NS_LOG_FUNCTION (this);
107  return CopyObject<TcpHtcp> (this);
108 }
109 
111  uint32_t segmentsAcked)
112 {
113  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
114  if (segmentsAcked > 0)
115  {
116  double adder = static_cast<double> (((tcb->m_segmentSize
117  * tcb->m_segmentSize) + (tcb->m_cWnd * m_alpha)) / tcb->m_cWnd);
118  adder = std::max (1.0, adder);
119  tcb->m_cWnd += static_cast<uint32_t> (adder);
120  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd
121  << " ssthresh " << tcb->m_ssThresh);
122  }
123 }
124 
126 {
127  NS_LOG_FUNCTION (this);
128 
130  if (m_delta <= m_deltaL)
131  {
132  m_alpha = 1;
133  }
134  else
135  {
136  Time diff = m_delta - m_deltaL;
137  double diffSec = diff.GetSeconds ();
138  // alpha=1+10(Delta-Delta_L)+[0.5(Delta-Delta_L)]^2 (seconds)
139  // from Leith and Shorten H-TCP paper
140  m_alpha = (1 + 10 * diffSec + 0.25 * (diffSec * diffSec));
141  }
142  m_alpha = 2 * (1 - m_beta) * m_alpha;
143  if (m_alpha < 1)
144  {
145  m_alpha = 1;
146  }
147  NS_LOG_DEBUG ("Updated m_alpha: " << m_alpha);
148 }
149 
151 {
152  NS_LOG_FUNCTION (this);
153 
154  // Default value for m_beta
156 
158  {
159  uint32_t diff = m_throughput - m_lastThroughput;
160  if (diff / m_lastThroughput <= m_throughputRatio)
161  {
163  }
164  }
165  NS_LOG_DEBUG ("Updated m_beta: " << m_beta);
166 }
167 
169  uint32_t bytesInFlight)
170 {
171  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
172 
174 
175  UpdateBeta ();
176  UpdateAlpha ();
177 
178  uint32_t segWin = 2 * tcb->m_segmentSize;
179  uint32_t bFlight = static_cast<uint32_t> (bytesInFlight * m_beta);
180  uint32_t ssThresh = std::max (segWin, bFlight);
181  m_minRtt = Time::Max ();
182  m_maxRtt = Time::Min ();
184  m_throughput = 0;
185  m_dataSent = 0;
186  NS_LOG_DEBUG (this << " ssThresh: " << ssThresh << " m_beta: " << m_beta);
187  return ssThresh;
188 }
189 
190 void TcpHtcp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
191  const Time &rtt)
192 {
193 
194  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
195  NS_LOG_DEBUG ("TcpSocketState: " << tcb->m_congState);
197  {
198  m_dataSent += segmentsAcked * tcb->m_segmentSize;
199  }
200 
201  m_throughput = static_cast<uint32_t> (m_dataSent
203 
204  UpdateAlpha ();
205  if (rtt < m_minRtt)
206  {
207  m_minRtt = rtt;
208  NS_LOG_DEBUG ("Updated m_minRtt=" << m_minRtt);
209  }
210  if (rtt > m_maxRtt)
211  {
212  m_maxRtt = rtt;
213  NS_LOG_DEBUG ("Updated m_maxRtt=" << m_maxRtt);
214  }
215 }
216 
217 } // namespace ns3
Time m_delta
Time in second that has elapsed since the.
Definition: tcp-htcp.h:93
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Definition: tcp-htcp.cc:110
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
double m_alpha
AIMD additive increase parameter.
Definition: tcp-htcp.h:89
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 "...
Normal state, no dubious events.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static Time Min()
Minimum representable Time.
Definition: nstime.h:268
void UpdateAlpha(void)
Updates the additive increase parameter for H-TCP.
Definition: tcp-htcp.cc:125
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-htcp.cc:190
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-htcp.cc:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time m_maxRtt
Maximum RTT in each congestion period.
Definition: tcp-htcp.h:98
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:277
The NewReno implementation.
An implementation of the H-TCP variant of TCP.
Definition: tcp-htcp.h:47
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
static Time Max()
Maximum representable Time.
Definition: nstime.h:273
void UpdateBeta(void)
Updates the multiplicative decrease factor beta for H-TCP.
Definition: tcp-htcp.cc:150
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
#define max(a, b)
Definition: 80211b.c:45
AttributeValue implementation for Time.
Definition: nstime.h:1069
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-htcp.cc:36
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
virtual ~TcpHtcp(void)
Definition: tcp-htcp.cc:99
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedValue< TcpCongState_t > m_congState
State in the Congestion state machine.
Time m_minRtt
Minimum RTT in each congestion period.
Definition: tcp-htcp.h:97
uint32_t m_lastThroughput
Throughput in last congestion period.
Definition: tcp-htcp.h:100
uint32_t m_throughput
Current throughput since last congestion.
Definition: tcp-htcp.h:99
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1070
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:395
Time m_deltaL
Threshold for switching between standard and new increase function.
Definition: tcp-htcp.h:95
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
TracedValue< uint32_t > m_cWnd
Congestion window.
double m_defaultBackoff
default value when throughput ratio less than default
Definition: tcp-htcp.h:91
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
double m_throughputRatio
ratio of two consequence throughput
Definition: tcp-htcp.h:92
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:168
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-htcp.cc:104
TcpHtcp(void)
Create an unbound tcp socket.
Definition: tcp-htcp.cc:66
Time m_lastCon
Time of the last congestion for the flow.
Definition: tcp-htcp.h:96
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_dataSent
Current amount of data sent since last congestion.
Definition: tcp-htcp.h:101
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
double m_beta
AIMD multiplicative decrease factor.
Definition: tcp-htcp.h:90