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 
29 #include "ns3/log.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/simulator.h"
32 #include "ns3/abort.h"
33 #include "ns3/node.h"
34 #include "math.h"
35 #include "ns3/tcp-socket-base.h"
36 #include "ns3/sequence-number.h"
37 #include "ns3/double.h"
38 #include "ns3/nstime.h"
39 
40 namespace ns3 {
41 
42 NS_LOG_COMPONENT_DEFINE ("TcpHtcp");
43 
45 
47 {
48  static TypeId tid = TypeId ("ns3::TcpHtcp")
50  .AddConstructor<TcpHtcp> ()
51  .SetGroupName ("Internet")
52  .AddAttribute ("DefaultBackoff",
53  "The default AIMD backoff factor",
54  DoubleValue (0.5),
56  MakeDoubleChecker<double> (0,1))
57  .AddAttribute ("ThroughputRatio",
58  "Threshold value for updating beta",
59  DoubleValue (0.2),
61  MakeDoubleChecker<double> ())
62  .AddAttribute ("DeltaL",
63  "Delta_L parameter in increase function",
64  TimeValue (Seconds (1)),
66  MakeTimeChecker ())
67  ;
68  return tid;
69 }
70 
71 std::string TcpHtcp::GetName () const
72 {
73  return "TcpHtcp";
74 }
75 
77  : TcpNewReno (),
78  m_alpha (0),
79  m_beta (0),
80  m_delta (0),
81  m_lastCon (0),
82  m_minRtt (Time::Max ()),
83  m_maxRtt (Time::Min ()),
84  m_throughput (0),
85  m_lastThroughput (0),
86  m_dataSent (0)
87 {
88  NS_LOG_FUNCTION (this);
89 }
90 
92  : TcpNewReno (sock),
93  m_alpha (sock.m_alpha),
94  m_beta (sock.m_beta),
95  m_defaultBackoff (sock.m_defaultBackoff),
96  m_throughputRatio (sock.m_throughputRatio),
97  m_delta (sock.m_delta),
98  m_deltaL (sock.m_deltaL),
99  m_lastCon (sock.m_lastCon),
100  m_minRtt (sock.m_minRtt),
101  m_maxRtt (sock.m_maxRtt),
102  m_throughput (sock.m_throughput),
103  m_lastThroughput (sock.m_lastThroughput),
104  m_dataSent (sock.m_dataSent)
105 {
106  NS_LOG_FUNCTION (this);
107 }
108 
110 {
111  NS_LOG_FUNCTION (this);
112 }
113 
115 {
116  NS_LOG_FUNCTION (this);
117  return CopyObject<TcpHtcp> (this);
118 }
119 
121  uint32_t segmentsAcked)
122 {
123  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
124  if (segmentsAcked > 0)
125  {
126  double adder = static_cast<double> (((tcb->m_segmentSize
127  * tcb->m_segmentSize) + (tcb->m_cWnd * m_alpha)) / tcb->m_cWnd);
128  adder = std::max (1.0, adder);
129  tcb->m_cWnd += static_cast<uint32_t> (adder);
130  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd
131  << " ssthresh " << tcb->m_ssThresh);
132  }
133 }
134 
136 {
137  NS_LOG_FUNCTION (this);
138 
140  if (m_delta <= m_deltaL)
141  {
142  m_alpha = 1;
143  }
144  else
145  {
146  Time diff = m_delta - m_deltaL;
147  double diffSec = diff.GetSeconds ();
148  // alpha=1+10(Delta-Delta_L)+[0.5(Delta-Delta_L)]^2 (seconds)
149  // from Leith and Shorten H-TCP paper
150  m_alpha = (1 + 10 * diffSec + 0.25 * (diffSec * diffSec));
151  }
152  m_alpha = 2 * (1 - m_beta) * m_alpha;
153  if (m_alpha < 1)
154  {
155  m_alpha = 1;
156  }
157  NS_LOG_DEBUG ("Updated m_alpha: " << m_alpha);
158 }
159 
161 {
162  NS_LOG_FUNCTION (this);
163  if (m_lastThroughput > 0)
164  {
166  {
168  }
169  else
170  {
172  }
173  }
174  else
175  {
177  }
178  NS_LOG_DEBUG ("Updated m_beta: " << m_beta);
179 }
180 
182  uint32_t bytesInFlight)
183 {
184  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
185 
187 
188  UpdateBeta ();
189  UpdateAlpha ();
190 
191  uint32_t segWin = 2 * tcb->m_segmentSize;
192  uint32_t bFlight = bytesInFlight * m_beta;
193  uint32_t ssThresh = std::max (segWin, bFlight);
194  m_minRtt = Time::Max ();
195  m_maxRtt = Time::Min ();
197  m_throughput = 0;
198  m_dataSent = 0;
199  NS_LOG_DEBUG (this << " ssThresh: " << ssThresh << " m_beta: " << m_beta);
200  return ssThresh;
201 }
202 
203 void TcpHtcp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
204  const Time &rtt)
205 {
206 
207  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
208  NS_LOG_DEBUG ("TcpSocketState: " << tcb->m_congState);
209  if (tcb->m_congState == TcpSocketState::CA_OPEN)
210  {
211  m_dataSent += segmentsAcked * tcb->m_segmentSize;
212  }
213 
216 
217  UpdateAlpha ();
218  if (rtt < m_minRtt)
219  {
220  m_minRtt = rtt;
221  NS_LOG_DEBUG ("Updated m_minRtt=" << m_minRtt);
222  }
223  if (rtt > m_maxRtt)
224  {
225  m_maxRtt = rtt;
226  NS_LOG_DEBUG ("Updated m_maxRtt=" << m_maxRtt);
227  }
228 }
229 
230 } // namespace ns3
Custom version of log2() to deal with Bug 1467.
Time m_delta
Time in second that has elapsed since the.
Definition: tcp-htcp.h:96
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Definition: tcp-htcp.cc:120
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
double m_alpha
AIMD additive increase parameter.
Definition: tcp-htcp.h:92
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:44
static Time Min()
Minimum representable Time.
Definition: nstime.h:254
void UpdateAlpha(void)
Updates the additive increase parameter for H-TCP.
Definition: tcp-htcp.cc:135
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-htcp.cc:203
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-htcp.cc:71
#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:101
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
The NewReno implementation.
An implementation of the H-TCP variant of TCP.
Definition: tcp-htcp.h:50
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:259
void UpdateBeta(void)
Updates the multiplicative decrease factor beta for H-TCP.
Definition: tcp-htcp.cc:160
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
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:957
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-htcp.cc:46
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
virtual ~TcpHtcp(void)
Definition: tcp-htcp.cc:109
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time m_minRtt
Minimum RTT in each congestion period.
Definition: tcp-htcp.h:100
uint32_t m_lastThroughput
Throughput in last congestion period.
Definition: tcp-htcp.h:103
uint32_t m_throughput
Current throughput since last congestion.
Definition: tcp-htcp.h:102
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:958
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:381
Time m_deltaL
Threshold for switching between standard and new increase function.
Definition: tcp-htcp.h:98
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
double m_defaultBackoff
default value when throughput ratio less than default
Definition: tcp-htcp.h:94
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:95
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:181
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-htcp.cc:114
TcpHtcp(void)
Create an unbound tcp socket.
Definition: tcp-htcp.cc:76
Time m_lastCon
Time of the last congestion for the flow.
Definition: tcp-htcp.h:99
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:104
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
double m_beta
AIMD multiplicative decrease factor.
Definition: tcp-htcp.h:93