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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-hybla.h"
9
10#include "tcp-socket-state.h"
11
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("TcpHybla");
19
20TypeId
22{
23 static TypeId tid = TypeId("ns3::TcpHybla")
25 .AddConstructor<TcpHybla>()
26 .SetGroupName("Internet")
27 .AddAttribute("RRTT",
28 "Reference RTT",
32 .AddTraceSource("Rho",
33 "Rho parameter of Hybla",
35 "ns3::TracedValueCallback::Double");
36 return tid;
37}
38
40 : TcpNewReno(),
41 m_rho(1.0),
42 m_cWndCnt(0)
43{
44 NS_LOG_FUNCTION(this);
45}
46
48 : TcpNewReno(sock),
49 m_rho(sock.m_rho),
50 m_cWndCnt(sock.m_cWndCnt)
51{
52 NS_LOG_FUNCTION(this);
53}
54
59
60void
62{
63 NS_LOG_FUNCTION(this);
64
65 m_rho = std::max((double)tcb->m_minRtt.GetMilliSeconds() / m_rRtt.GetMilliSeconds(), 1.0);
66
67 NS_ASSERT(m_rho > 0.0);
68 NS_LOG_DEBUG("Calculated rho=" << m_rho);
69}
70
71void
73{
74 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
75
76 if (rtt == tcb->m_minRtt)
77 {
78 RecalcParam(tcb);
79 NS_LOG_DEBUG("min rtt seen: " << rtt);
80 }
81}
82
85{
86 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
87
88 NS_ASSERT(tcb->m_cWnd <= tcb->m_ssThresh);
89
90 if (segmentsAcked >= 1)
91 {
92 /*
93 * slow start
94 * INC = 2^RHO - 1
95 */
96
97 double increment = std::pow(2, m_rho) - 1.0;
98 auto incr = static_cast<uint32_t>(increment * tcb->m_segmentSize);
99 NS_LOG_INFO("Slow start: inc=" << increment);
100
101 tcb->m_cWnd = std::min(tcb->m_cWnd + incr, tcb->m_ssThresh);
102
103 NS_LOG_INFO("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh "
104 << tcb->m_ssThresh << " with an increment of "
105 << increment * tcb->m_segmentSize);
106
107 return segmentsAcked - 1;
108 }
109
110 return 0;
111}
112
113void
115{
116 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
117
118 uint32_t segCwnd;
119 double increment;
120
121 while (segmentsAcked > 0)
122 {
123 /*
124 * congestion avoidance
125 * INC = RHO^2 / W
126 */
127 segCwnd = tcb->GetCwndInSegments();
128 increment = std::pow(m_rho, 2) / static_cast<double>(segCwnd);
129
130 m_cWndCnt += increment;
131 segmentsAcked -= 1;
132 }
133
134 if (m_cWndCnt >= 1.0)
135 {
136 // double to int truncates every time.
137 auto inc = static_cast<uint32_t>(m_cWndCnt);
138 m_cWndCnt -= inc;
139
140 NS_ASSERT(m_cWndCnt >= 0.0);
141
142 /* This leaves space for a tcp pacing implementation; it would be easy
143 to setup a limit on the maximum increment of the cWnd per ACK received.
144 The remaining increment is leaved for the next ACK. */
145
146 tcb->m_cWnd += inc * tcb->m_segmentSize;
147
148 NS_LOG_INFO("In CongAvoid, updated to cwnd " << tcb->m_cWnd << " ssthresh "
149 << tcb->m_ssThresh << " with an increment of "
150 << inc * tcb->m_segmentSize);
151 }
152}
153
156{
157 return CopyObject<TcpHybla>(this);
158}
159
160std::string
162{
163 return "TcpHybla";
164}
165
166} // namespace ns3
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
Implementation of the TCP Hybla algorithm.
Definition tcp-hybla.h:37
static TypeId GetTypeId()
Get the type ID.
Definition tcp-hybla.cc:21
Time m_rRtt
Reference RTT.
Definition tcp-hybla.h:69
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition tcp-hybla.cc:155
TcpHybla()
Create an unbound tcp socket.
Definition tcp-hybla.cc:39
uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Tcp NewReno slow start algorithm.
Definition tcp-hybla.cc:84
TracedValue< double > m_rho
Rho parameter.
Definition tcp-hybla.h:68
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition tcp-hybla.cc:161
void RecalcParam(const Ptr< TcpSocketState > &tcb)
Recalculate algorithm parameters.
Definition tcp-hybla.cc:61
~TcpHybla() override
Definition tcp-hybla.cc:55
double m_cWndCnt
cWnd integer-to-float counter
Definition tcp-hybla.h:70
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition tcp-hybla.cc:72
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
NewReno congestion avoidance.
Definition tcp-hybla.cc:114
The NewReno implementation.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
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_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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 MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416