A Discrete-Event Network Simulator
API
tcp-hybla.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com>
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  */
19 
20 #include "tcp-hybla.h"
21 #include "ns3/log.h"
22 #include "ns3/tcp-socket-base.h"
23 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("TcpHybla");
28 
29 TypeId
31 {
32  static TypeId tid = TypeId ("ns3::TcpHybla")
34  .AddConstructor<TcpHybla> ()
35  .SetGroupName ("Internet")
36  .AddAttribute ("RRTT", "Reference RTT",
37  TimeValue (MilliSeconds (50)),
39  MakeTimeChecker ())
40  .AddTraceSource ("Rho",
41  "Rho parameter of Hybla",
43  "ns3::TracedValueCallback::Double")
44  ;
45  return tid;
46 }
47 
49  : TcpNewReno (),
50  m_rho (1.0),
51  m_cWndCnt (0)
52 {
53  NS_LOG_FUNCTION (this);
54 }
55 
57  : TcpNewReno (sock),
58  m_rho (sock.m_rho),
59  m_cWndCnt (sock.m_cWndCnt)
60 {
61  NS_LOG_FUNCTION (this);
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION (this);
73 
74  m_rho = std::max ((double) tcb->m_minRtt.GetMilliSeconds () / m_rRtt.GetMilliSeconds (), 1.0);
75 
76  NS_ASSERT (m_rho > 0.0);
77  NS_LOG_DEBUG ("Calculated rho=" << m_rho);
78 }
79 
80 void
81 TcpHybla::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
82  const Time &rtt)
83 {
84  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
85 
86  if (rtt == tcb->m_minRtt)
87  {
88  RecalcParam (tcb);
89  NS_LOG_DEBUG ("min rtt seen: " << rtt);
90  }
91 }
92 
93 uint32_t
94 TcpHybla::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
95 {
96  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
97 
98  NS_ASSERT (tcb->m_cWnd <= tcb->m_ssThresh);
99 
100  if (segmentsAcked >= 1)
101  {
102  /*
103  * slow start
104  * INC = 2^RHO - 1
105  */
106 
107  double increment = std::pow (2, m_rho) - 1.0;
108  uint32_t incr = static_cast<uint32_t> (increment * tcb->m_segmentSize);
109  NS_LOG_INFO ("Slow start: inc=" << increment);
110 
111  tcb->m_cWnd = std::min (tcb->m_cWnd + incr, tcb->m_ssThresh);
112 
113  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd <<
114  " ssthresh " << tcb->m_ssThresh <<
115  " with an increment of " << increment * tcb->m_segmentSize);
116 
117  return segmentsAcked - 1;
118  }
119 
120  return 0;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
127 
128  uint32_t segCwnd;
129  double increment;
130 
131  while (segmentsAcked > 0)
132  {
133  /*
134  * congestion avoidance
135  * INC = RHO^2 / W
136  */
137  segCwnd = tcb->GetCwndInSegments ();
138  increment = std::pow (m_rho, 2) / static_cast<double> (segCwnd);
139 
140  m_cWndCnt += increment;
141  segmentsAcked -= 1;
142  }
143 
144  if (m_cWndCnt >= 1.0)
145  {
146  // double to int truncates every time.
147  uint32_t inc = static_cast<uint32_t> (m_cWndCnt);
148  m_cWndCnt -= inc;
149 
150  NS_ASSERT (m_cWndCnt >= 0.0);
151 
152  /* This leaves space for a tcp pacing implementation; it would be easy
153  to setup a limit on the maximum increment of the cWnd per ACK received.
154  The remaining increment is leaved for the next ACK. */
155 
156  tcb->m_cWnd += inc * tcb->m_segmentSize;
157 
158 
159  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
160  " ssthresh " << tcb->m_ssThresh <<
161  " with an increment of " << inc * tcb->m_segmentSize);
162  }
163 }
164 
167 {
168  return CopyObject<TcpHybla> (this);
169 }
170 
171 std::string
173 {
174  return "TcpHybla";
175 }
176 
177 
178 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void RecalcParam(const Ptr< TcpSocketState > &tcb)
Recalculate algorithm parameters.
Definition: tcp-hybla.cc:70
#define min(a, b)
Definition: 80211b.c:42
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
NewReno congestion avoidance.
Definition: tcp-hybla.cc:124
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
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.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-hybla.cc:81
TcpHybla(void)
Create an unbound tcp socket.
Definition: tcp-hybla.cc:48
virtual std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-hybla.cc:172
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1076
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Tcp NewReno slow start algorithm
Definition: tcp-hybla.cc:94
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across socket.
Definition: tcp-hybla.cc:166
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
TracedValue< uint32_t > m_cWnd
Congestion window.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-hybla.cc:30
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time m_minRtt
Minimum RTT observed throughout the connection.
Implementation of the TCP Hybla algorithm.
Definition: tcp-hybla.h:45
a unique identifier for an interface.
Definition: type-id.h:58
double m_cWndCnt
cWnd integer-to-float counter
Definition: tcp-hybla.h:80
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
virtual ~TcpHybla(void) override
Definition: tcp-hybla.cc:64
Time m_rRtt
Reference RTT.
Definition: tcp-hybla.h:79
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
TracedValue< double > m_rho
Rho parameter.
Definition: tcp-hybla.h:78