A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-hybla.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com>
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 */
18
19#include "tcp-hybla.h"
20
21#include "tcp-socket-state.h"
22
23#include "ns3/log.h"
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("TcpHybla");
30
31TypeId
33{
34 static TypeId tid = TypeId("ns3::TcpHybla")
36 .AddConstructor<TcpHybla>()
37 .SetGroupName("Internet")
38 .AddAttribute("RRTT",
39 "Reference RTT",
43 .AddTraceSource("Rho",
44 "Rho parameter of Hybla",
46 "ns3::TracedValueCallback::Double");
47 return tid;
48}
49
51 : TcpNewReno(),
52 m_rho(1.0),
53 m_cWndCnt(0)
54{
55 NS_LOG_FUNCTION(this);
56}
57
59 : TcpNewReno(sock),
60 m_rho(sock.m_rho),
61 m_cWndCnt(sock.m_cWndCnt)
62{
63 NS_LOG_FUNCTION(this);
64}
65
67{
68 NS_LOG_FUNCTION(this);
69}
70
71void
73{
74 NS_LOG_FUNCTION(this);
75
76 m_rho = std::max((double)tcb->m_minRtt.GetMilliSeconds() / m_rRtt.GetMilliSeconds(), 1.0);
77
78 NS_ASSERT(m_rho > 0.0);
79 NS_LOG_DEBUG("Calculated rho=" << m_rho);
80}
81
82void
84{
85 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
86
87 if (rtt == tcb->m_minRtt)
88 {
89 RecalcParam(tcb);
90 NS_LOG_DEBUG("min rtt seen: " << rtt);
91 }
92}
93
96{
97 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
98
99 NS_ASSERT(tcb->m_cWnd <= tcb->m_ssThresh);
100
101 if (segmentsAcked >= 1)
102 {
103 /*
104 * slow start
105 * INC = 2^RHO - 1
106 */
107
108 double increment = std::pow(2, m_rho) - 1.0;
109 auto incr = static_cast<uint32_t>(increment * tcb->m_segmentSize);
110 NS_LOG_INFO("Slow start: inc=" << increment);
111
112 tcb->m_cWnd = std::min(tcb->m_cWnd + incr, tcb->m_ssThresh);
113
114 NS_LOG_INFO("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh "
115 << tcb->m_ssThresh << " with an increment of "
116 << increment * tcb->m_segmentSize);
117
118 return segmentsAcked - 1;
119 }
120
121 return 0;
122}
123
124void
126{
127 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
128
129 uint32_t segCwnd;
130 double increment;
131
132 while (segmentsAcked > 0)
133 {
134 /*
135 * congestion avoidance
136 * INC = RHO^2 / W
137 */
138 segCwnd = tcb->GetCwndInSegments();
139 increment = std::pow(m_rho, 2) / static_cast<double>(segCwnd);
140
141 m_cWndCnt += increment;
142 segmentsAcked -= 1;
143 }
144
145 if (m_cWndCnt >= 1.0)
146 {
147 // double to int truncates every time.
148 auto inc = static_cast<uint32_t>(m_cWndCnt);
149 m_cWndCnt -= inc;
150
151 NS_ASSERT(m_cWndCnt >= 0.0);
152
153 /* This leaves space for a tcp pacing implementation; it would be easy
154 to setup a limit on the maximum increment of the cWnd per ACK received.
155 The remaining increment is leaved for the next ACK. */
156
157 tcb->m_cWnd += inc * tcb->m_segmentSize;
158
159 NS_LOG_INFO("In CongAvoid, updated to cwnd " << tcb->m_cWnd << " ssthresh "
160 << tcb->m_ssThresh << " with an increment of "
161 << inc * tcb->m_segmentSize);
162 }
163}
164
167{
168 return CopyObject<TcpHybla>(this);
169}
170
171std::string
173{
174 return "TcpHybla";
175}
176
177} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Implementation of the TCP Hybla algorithm.
Definition: tcp-hybla.h:48
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-hybla.cc:32
Time m_rRtt
Reference RTT.
Definition: tcp-hybla.h:80
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition: tcp-hybla.cc:166
TcpHybla()
Create an unbound tcp socket.
Definition: tcp-hybla.cc:50
uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Tcp NewReno slow start algorithm.
Definition: tcp-hybla.cc:95
TracedValue< double > m_rho
Rho parameter.
Definition: tcp-hybla.h:79
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-hybla.cc:172
void RecalcParam(const Ptr< TcpSocketState > &tcb)
Recalculate algorithm parameters.
Definition: tcp-hybla.cc:72
~TcpHybla() override
Definition: tcp-hybla.cc:66
double m_cWndCnt
cWnd integer-to-float counter
Definition: tcp-hybla.h:81
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-hybla.cc:83
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
NewReno congestion avoidance.
Definition: tcp-hybla.cc:125
The NewReno implementation.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:408
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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
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 MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.