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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * by: Amir Modarresi <amodarresi@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 */
14
15#include "tcp-htcp.h"
16
17#include "ns3/log.h"
18#include "ns3/simulator.h"
19
20namespace ns3
21{
22
24
26
27TypeId
29{
30 static TypeId tid = TypeId("ns3::TcpHtcp")
32 .AddConstructor<TcpHtcp>()
33 .SetGroupName("Internet")
34 .AddAttribute("DefaultBackoff",
35 "The default AIMD backoff factor",
36 DoubleValue(0.5),
39 .AddAttribute("ThroughputRatio",
40 "Threshold value for updating beta",
41 DoubleValue(0.2),
44 .AddAttribute("DeltaL",
45 "Delta_L parameter in increase function",
49 return tid;
50}
51
52std::string
54{
55 return "TcpHtcp";
56}
57
59 : TcpNewReno(),
60 m_alpha(0),
61 m_beta(0),
62 m_delta(0),
63 m_lastCon(0),
64 m_minRtt(Time::Max()),
65 m_maxRtt(Time::Min()),
66 m_throughput(0),
67 m_lastThroughput(0),
68 m_dataSent(0)
69{
70 NS_LOG_FUNCTION(this);
71}
72
74 : TcpNewReno(sock),
75 m_alpha(sock.m_alpha),
76 m_beta(sock.m_beta),
77 m_defaultBackoff(sock.m_defaultBackoff),
78 m_throughputRatio(sock.m_throughputRatio),
79 m_delta(sock.m_delta),
80 m_deltaL(sock.m_deltaL),
81 m_lastCon(sock.m_lastCon),
82 m_minRtt(sock.m_minRtt),
83 m_maxRtt(sock.m_maxRtt),
84 m_throughput(sock.m_throughput),
85 m_lastThroughput(sock.m_lastThroughput),
86 m_dataSent(sock.m_dataSent)
87{
88 NS_LOG_FUNCTION(this);
89}
90
95
98{
99 NS_LOG_FUNCTION(this);
100 return CopyObject<TcpHtcp>(this);
101}
102
103void
105{
106 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
107 if (segmentsAcked > 0)
108 {
109 double adder = static_cast<double>(
110 ((tcb->m_segmentSize * tcb->m_segmentSize) + (tcb->m_cWnd * m_alpha)) / tcb->m_cWnd);
111 adder = std::max(1.0, adder);
112 tcb->m_cWnd += static_cast<uint32_t>(adder);
113 NS_LOG_INFO("In CongAvoid, updated to cwnd " << tcb->m_cWnd << " ssthresh "
114 << tcb->m_ssThresh);
115 }
116}
117
118void
120{
121 NS_LOG_FUNCTION(this);
122
124 if (m_delta <= m_deltaL)
125 {
126 m_alpha = 1;
127 }
128 else
129 {
130 Time diff = m_delta - m_deltaL;
131 double diffSec = diff.GetSeconds();
132 // alpha=1+10(Delta-Delta_L)+[0.5(Delta-Delta_L)]^2 (seconds)
133 // from Leith and Shorten H-TCP paper
134 m_alpha = (1 + 10 * diffSec + 0.25 * (diffSec * diffSec));
135 }
136 m_alpha = 2 * (1 - m_beta) * m_alpha;
137 if (m_alpha < 1)
138 {
139 m_alpha = 1;
140 }
141 NS_LOG_DEBUG("Updated m_alpha: " << m_alpha);
142}
143
144void
146{
147 NS_LOG_FUNCTION(this);
148
149 // Default value for m_beta
151
153 {
156 {
158 }
159 }
160 NS_LOG_DEBUG("Updated m_beta: " << m_beta);
161}
162
165{
166 NS_LOG_FUNCTION(this << tcb << bytesInFlight);
167
169
170 UpdateBeta();
171 UpdateAlpha();
172
173 uint32_t segWin = 2 * tcb->m_segmentSize;
174 auto bFlight = static_cast<uint32_t>(bytesInFlight * m_beta);
175 uint32_t ssThresh = std::max(segWin, bFlight);
179 m_throughput = 0;
180 m_dataSent = 0;
181 NS_LOG_DEBUG(this << " ssThresh: " << ssThresh << " m_beta: " << m_beta);
182 return ssThresh;
183}
184
185void
187{
188 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
189 NS_LOG_DEBUG("TcpSocketState: " << tcb->m_congState);
190 if (tcb->m_congState == TcpSocketState::CA_OPEN)
191 {
192 m_dataSent += segmentsAcked * tcb->m_segmentSize;
193 }
194
195 m_throughput = static_cast<uint32_t>(m_dataSent /
197
198 UpdateAlpha();
199 if (rtt < m_minRtt)
200 {
201 m_minRtt = rtt;
202 NS_LOG_DEBUG("Updated m_minRtt=" << m_minRtt);
203 }
204 if (rtt > m_maxRtt)
205 {
206 m_maxRtt = rtt;
207 NS_LOG_DEBUG("Updated m_maxRtt=" << m_maxRtt);
208 }
209}
210
211} // 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:31
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
An implementation of the H-TCP variant of TCP.
Definition tcp-htcp.h:39
Time m_minRtt
Minimum RTT in each congestion period.
Definition tcp-htcp.h:85
Time m_lastCon
Time of the last congestion for the flow.
Definition tcp-htcp.h:84
void UpdateBeta()
Updates the multiplicative decrease factor beta for H-TCP.
Definition tcp-htcp.cc:145
double m_defaultBackoff
default value when throughput ratio less than default
Definition tcp-htcp.h:79
uint32_t m_dataSent
Current amount of data sent since last congestion.
Definition tcp-htcp.h:89
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition tcp-htcp.cc:164
double m_throughputRatio
ratio of two consequence throughput
Definition tcp-htcp.h:80
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition tcp-htcp.cc:53
Time m_delta
Time in second that has elapsed since the.
Definition tcp-htcp.h:81
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
NewReno congestion avoidance.
Definition tcp-htcp.cc:104
uint32_t m_lastThroughput
Throughput in last congestion period.
Definition tcp-htcp.h:88
double m_alpha
AIMD additive increase parameter.
Definition tcp-htcp.h:77
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition tcp-htcp.cc:186
double m_beta
AIMD multiplicative decrease factor.
Definition tcp-htcp.h:78
Time m_deltaL
Threshold for switching between standard and new increase function.
Definition tcp-htcp.h:83
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition tcp-htcp.cc:97
TcpHtcp()
Create an unbound tcp socket.
Definition tcp-htcp.cc:58
Time m_maxRtt
Maximum RTT in each congestion period.
Definition tcp-htcp.h:86
~TcpHtcp() override
Definition tcp-htcp.cc:91
void UpdateAlpha()
Updates the additive increase parameter for H-TCP.
Definition tcp-htcp.cc:119
static TypeId GetTypeId()
Get the type ID.
Definition tcp-htcp.cc:28
uint32_t m_throughput
Current throughput since last congestion.
Definition tcp-htcp.h:87
The NewReno implementation.
@ CA_OPEN
Normal state, no dubious events.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition nstime.h:276
double GetDouble() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:439
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition nstime.h:286
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416