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 #include "ns3/simulator.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("TcpHtcp");
34 
36 
38 {
39  static TypeId tid = TypeId ("ns3::TcpHtcp")
41  .AddConstructor<TcpHtcp> ()
42  .SetGroupName ("Internet")
43  .AddAttribute ("DefaultBackoff",
44  "The default AIMD backoff factor",
45  DoubleValue (0.5),
47  MakeDoubleChecker<double> (0,1))
48  .AddAttribute ("ThroughputRatio",
49  "Threshold value for updating beta",
50  DoubleValue (0.2),
52  MakeDoubleChecker<double> ())
53  .AddAttribute ("DeltaL",
54  "Delta_L parameter in increase function",
55  TimeValue (Seconds (1)),
57  MakeTimeChecker ())
58  ;
59  return tid;
60 }
61 
62 std::string TcpHtcp::GetName () const
63 {
64  return "TcpHtcp";
65 }
66 
68  : TcpNewReno (),
69  m_alpha (0),
70  m_beta (0),
71  m_delta (0),
72  m_lastCon (0),
73  m_minRtt (Time::Max ()),
74  m_maxRtt (Time::Min ()),
75  m_throughput (0),
76  m_lastThroughput (0),
77  m_dataSent (0)
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
83  : TcpNewReno (sock),
84  m_alpha (sock.m_alpha),
85  m_beta (sock.m_beta),
86  m_defaultBackoff (sock.m_defaultBackoff),
87  m_throughputRatio (sock.m_throughputRatio),
88  m_delta (sock.m_delta),
89  m_deltaL (sock.m_deltaL),
90  m_lastCon (sock.m_lastCon),
91  m_minRtt (sock.m_minRtt),
92  m_maxRtt (sock.m_maxRtt),
93  m_throughput (sock.m_throughput),
94  m_lastThroughput (sock.m_lastThroughput),
95  m_dataSent (sock.m_dataSent)
96 {
97  NS_LOG_FUNCTION (this);
98 }
99 
101 {
102  NS_LOG_FUNCTION (this);
103 }
104 
106 {
107  NS_LOG_FUNCTION (this);
108  return CopyObject<TcpHtcp> (this);
109 }
110 
112  uint32_t segmentsAcked)
113 {
114  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
115  if (segmentsAcked > 0)
116  {
117  double adder = static_cast<double> (((tcb->m_segmentSize
118  * tcb->m_segmentSize) + (tcb->m_cWnd * m_alpha)) / tcb->m_cWnd);
119  adder = std::max (1.0, adder);
120  tcb->m_cWnd += static_cast<uint32_t> (adder);
121  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd
122  << " ssthresh " << tcb->m_ssThresh);
123  }
124 }
125 
127 {
128  NS_LOG_FUNCTION (this);
129 
131  if (m_delta <= m_deltaL)
132  {
133  m_alpha = 1;
134  }
135  else
136  {
137  Time diff = m_delta - m_deltaL;
138  double diffSec = diff.GetSeconds ();
139  // alpha=1+10(Delta-Delta_L)+[0.5(Delta-Delta_L)]^2 (seconds)
140  // from Leith and Shorten H-TCP paper
141  m_alpha = (1 + 10 * diffSec + 0.25 * (diffSec * diffSec));
142  }
143  m_alpha = 2 * (1 - m_beta) * m_alpha;
144  if (m_alpha < 1)
145  {
146  m_alpha = 1;
147  }
148  NS_LOG_DEBUG ("Updated m_alpha: " << m_alpha);
149 }
150 
152 {
153  NS_LOG_FUNCTION (this);
154 
155  // Default value for m_beta
157 
159  {
160  uint32_t diff = m_throughput - m_lastThroughput;
161  if (diff / m_lastThroughput <= m_throughputRatio)
162  {
164  }
165  }
166  NS_LOG_DEBUG ("Updated m_beta: " << m_beta);
167 }
168 
170  uint32_t bytesInFlight)
171 {
172  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
173 
175 
176  UpdateBeta ();
177  UpdateAlpha ();
178 
179  uint32_t segWin = 2 * tcb->m_segmentSize;
180  uint32_t bFlight = static_cast<uint32_t> (bytesInFlight * m_beta);
181  uint32_t ssThresh = std::max (segWin, bFlight);
182  m_minRtt = Time::Max ();
183  m_maxRtt = Time::Min ();
185  m_throughput = 0;
186  m_dataSent = 0;
187  NS_LOG_DEBUG (this << " ssThresh: " << ssThresh << " m_beta: " << m_beta);
188  return ssThresh;
189 }
190 
191 void TcpHtcp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
192  const Time &rtt)
193 {
194 
195  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
196  NS_LOG_DEBUG ("TcpSocketState: " << tcb->m_congState);
198  {
199  m_dataSent += segmentsAcked * tcb->m_segmentSize;
200  }
201 
202  m_throughput = static_cast<uint32_t> (m_dataSent
204 
205  UpdateAlpha ();
206  if (rtt < m_minRtt)
207  {
208  m_minRtt = rtt;
209  NS_LOG_DEBUG ("Updated m_minRtt=" << m_minRtt);
210  }
211  if (rtt > m_maxRtt)
212  {
213  m_maxRtt = rtt;
214  NS_LOG_DEBUG ("Updated m_maxRtt=" << m_maxRtt);
215  }
216 }
217 
218 } // namespace ns3
Time m_delta
Time in second that has elapsed since the.
Definition: tcp-htcp.h:94
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Definition: tcp-htcp.cc:111
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
double m_alpha
AIMD additive increase parameter.
Definition: tcp-htcp.h:90
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:126
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-htcp.cc:191
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time m_maxRtt
Maximum RTT in each congestion period.
Definition: tcp-htcp.h:99
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
The NewReno implementation.
An implementation of the H-TCP variant of TCP.
Definition: tcp-htcp.h:48
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:151
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1076
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-htcp.cc:37
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:395
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
virtual ~TcpHtcp(void)
Definition: tcp-htcp.cc:100
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:98
uint32_t m_lastThroughput
Throughput in last congestion period.
Definition: tcp-htcp.h:101
uint32_t m_throughput
Current throughput since last congestion.
Definition: tcp-htcp.h:100
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:1077
Time m_deltaL
Threshold for switching between standard and new increase function.
Definition: tcp-htcp.h:96
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:92
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:93
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:169
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-htcp.cc:62
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-htcp.cc:105
TcpHtcp(void)
Create an unbound tcp socket.
Definition: tcp-htcp.cc:67
Time m_lastCon
Time of the last congestion for the flow.
Definition: tcp-htcp.h:97
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
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:102
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
double m_beta
AIMD multiplicative decrease factor.
Definition: tcp-htcp.h:91