A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-htcp.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 ResiliNets, ITTC, University of Kansas
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * by: Amir Modarresi <amodarresi@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 */
25
26#include "tcp-htcp.h"
27
28#include "ns3/log.h"
29#include "ns3/simulator.h"
30
31namespace ns3
32{
33
35
37
38TypeId
40{
41 static TypeId tid = TypeId("ns3::TcpHtcp")
43 .AddConstructor<TcpHtcp>()
44 .SetGroupName("Internet")
45 .AddAttribute("DefaultBackoff",
46 "The default AIMD backoff factor",
47 DoubleValue(0.5),
49 MakeDoubleChecker<double>(0, 1))
50 .AddAttribute("ThroughputRatio",
51 "Threshold value for updating beta",
52 DoubleValue(0.2),
54 MakeDoubleChecker<double>())
55 .AddAttribute("DeltaL",
56 "Delta_L parameter in increase function",
60 return tid;
61}
62
63std::string
65{
66 return "TcpHtcp";
67}
68
70 : TcpNewReno(),
71 m_alpha(0),
72 m_beta(0),
73 m_delta(0),
74 m_lastCon(0),
75 m_minRtt(Time::Max()),
76 m_maxRtt(Time::Min()),
77 m_throughput(0),
78 m_lastThroughput(0),
79 m_dataSent(0)
80{
81 NS_LOG_FUNCTION(this);
82}
83
85 : TcpNewReno(sock),
86 m_alpha(sock.m_alpha),
87 m_beta(sock.m_beta),
88 m_defaultBackoff(sock.m_defaultBackoff),
89 m_throughputRatio(sock.m_throughputRatio),
90 m_delta(sock.m_delta),
91 m_deltaL(sock.m_deltaL),
92 m_lastCon(sock.m_lastCon),
93 m_minRtt(sock.m_minRtt),
94 m_maxRtt(sock.m_maxRtt),
95 m_throughput(sock.m_throughput),
96 m_lastThroughput(sock.m_lastThroughput),
97 m_dataSent(sock.m_dataSent)
98{
99 NS_LOG_FUNCTION(this);
100}
101
103{
104 NS_LOG_FUNCTION(this);
105}
106
109{
110 NS_LOG_FUNCTION(this);
111 return CopyObject<TcpHtcp>(this);
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
118 if (segmentsAcked > 0)
119 {
120 double adder = static_cast<double>(
121 ((tcb->m_segmentSize * tcb->m_segmentSize) + (tcb->m_cWnd * m_alpha)) / tcb->m_cWnd);
122 adder = std::max(1.0, adder);
123 tcb->m_cWnd += static_cast<uint32_t>(adder);
124 NS_LOG_INFO("In CongAvoid, updated to cwnd " << tcb->m_cWnd << " ssthresh "
125 << tcb->m_ssThresh);
126 }
127}
128
129void
131{
132 NS_LOG_FUNCTION(this);
133
135 if (m_delta <= m_deltaL)
136 {
137 m_alpha = 1;
138 }
139 else
140 {
141 Time diff = m_delta - m_deltaL;
142 double diffSec = diff.GetSeconds();
143 // alpha=1+10(Delta-Delta_L)+[0.5(Delta-Delta_L)]^2 (seconds)
144 // from Leith and Shorten H-TCP paper
145 m_alpha = (1 + 10 * diffSec + 0.25 * (diffSec * diffSec));
146 }
147 m_alpha = 2 * (1 - m_beta) * m_alpha;
148 if (m_alpha < 1)
149 {
150 m_alpha = 1;
151 }
152 NS_LOG_DEBUG("Updated m_alpha: " << m_alpha);
153}
154
155void
157{
158 NS_LOG_FUNCTION(this);
159
160 // Default value for m_beta
162
164 {
167 {
169 }
170 }
171 NS_LOG_DEBUG("Updated m_beta: " << m_beta);
172}
173
176{
177 NS_LOG_FUNCTION(this << tcb << bytesInFlight);
178
180
181 UpdateBeta();
182 UpdateAlpha();
183
184 uint32_t segWin = 2 * tcb->m_segmentSize;
185 auto bFlight = static_cast<uint32_t>(bytesInFlight * m_beta);
186 uint32_t ssThresh = std::max(segWin, bFlight);
190 m_throughput = 0;
191 m_dataSent = 0;
192 NS_LOG_DEBUG(this << " ssThresh: " << ssThresh << " m_beta: " << m_beta);
193 return ssThresh;
194}
195
196void
198{
199 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
200 NS_LOG_DEBUG("TcpSocketState: " << tcb->m_congState);
201 if (tcb->m_congState == TcpSocketState::CA_OPEN)
202 {
203 m_dataSent += segmentsAcked * tcb->m_segmentSize;
204 }
205
206 m_throughput = static_cast<uint32_t>(m_dataSent /
208
209 UpdateAlpha();
210 if (rtt < m_minRtt)
211 {
212 m_minRtt = rtt;
213 NS_LOG_DEBUG("Updated m_minRtt=" << m_minRtt);
214 }
215 if (rtt > m_maxRtt)
216 {
217 m_maxRtt = rtt;
218 NS_LOG_DEBUG("Updated m_maxRtt=" << m_maxRtt);
219 }
220}
221
222} // namespace ns3
#define Max(a, b)
#define Min(a, b)
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
An implementation of the H-TCP variant of TCP.
Definition: tcp-htcp.h:50
Time m_minRtt
Minimum RTT in each congestion period.
Definition: tcp-htcp.h:96
Time m_lastCon
Time of the last congestion for the flow.
Definition: tcp-htcp.h:95
void UpdateBeta()
Updates the multiplicative decrease factor beta for H-TCP.
Definition: tcp-htcp.cc:156
double m_defaultBackoff
default value when throughput ratio less than default
Definition: tcp-htcp.h:90
uint32_t m_dataSent
Current amount of data sent since last congestion.
Definition: tcp-htcp.h:100
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:175
double m_throughputRatio
ratio of two consequence throughput
Definition: tcp-htcp.h:91
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-htcp.cc:64
Time m_delta
Time in second that has elapsed since the.
Definition: tcp-htcp.h:92
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
NewReno congestion avoidance.
Definition: tcp-htcp.cc:115
uint32_t m_lastThroughput
Throughput in last congestion period.
Definition: tcp-htcp.h:99
double m_alpha
AIMD additive increase parameter.
Definition: tcp-htcp.h:88
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-htcp.cc:197
double m_beta
AIMD multiplicative decrease factor.
Definition: tcp-htcp.h:89
Time m_deltaL
Threshold for switching between standard and new increase function.
Definition: tcp-htcp.h:94
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition: tcp-htcp.cc:108
TcpHtcp()
Create an unbound tcp socket.
Definition: tcp-htcp.cc:69
Time m_maxRtt
Maximum RTT in each congestion period.
Definition: tcp-htcp.h:97
~TcpHtcp() override
Definition: tcp-htcp.cc:102
void UpdateAlpha()
Updates the additive increase parameter for H-TCP.
Definition: tcp-htcp.cc:130
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-htcp.cc:39
uint32_t m_throughput
Current throughput since last congestion.
Definition: tcp-htcp.h:98
The NewReno implementation.
@ CA_OPEN
Normal state, no dubious events.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:287
double GetDouble() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:450
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:297
AttributeValue implementation for Time.
Definition: nstime.h:1413
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1434
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.