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::TracedValue::DoubleCallback")
44  ;
45  return tid;
46 }
47 
49  : TcpNewReno (),
50  m_rho (1.0),
51  m_minRtt (Time::Max ()),
52  m_cWndCnt (0)
53 {
54  NS_LOG_FUNCTION (this);
55 }
56 
58  : TcpNewReno (sock),
59  m_rho (sock.m_rho),
60  m_minRtt (sock.m_minRtt),
61  m_cWndCnt (sock.m_cWndCnt)
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION (this << rtt);
75 
76  m_rho = std::max ((double) rtt.GetMilliSeconds () / m_rRtt.GetMilliSeconds (), 1.0);
77 
78  NS_ASSERT (m_rho > 0.0);
79  NS_LOG_DEBUG ("Calculated rho=" << m_rho);
80 }
81 
82 void
83 TcpHybla::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
84  const Time &rtt)
85 {
86  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
87 
88  if (rtt < m_minRtt)
89  {
90  RecalcParam (tcb, rtt);
91  m_minRtt = rtt;
92  NS_LOG_DEBUG ("Updated m_minRtt=" << m_minRtt);
93  }
94 }
95 
96 uint32_t
97 TcpHybla::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
98 {
99  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
100 
101  NS_ASSERT (tcb->m_cWnd <= tcb->m_ssThresh);
102 
103  if (segmentsAcked >= 1)
104  {
105  /*
106  * slow start
107  * INC = 2^RHO - 1
108  */
109 
110  double increment = std::pow (2, m_rho) - 1.0;
111  NS_LOG_INFO ("Slow start: inc=" << increment);
112 
113  tcb->m_cWnd = std::min (tcb->m_cWnd + (increment * tcb->m_segmentSize),
114  tcb->m_ssThresh);
115 
116  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd <<
117  " ssthresh " << tcb->m_ssThresh <<
118  " with an increment of " << increment * tcb->m_segmentSize);
119 
120  return segmentsAcked - 1;
121  }
122 
123  return 0;
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
130 
131  uint32_t segCwnd;
132  double increment;
133 
134  while (segmentsAcked > 0)
135  {
136  /*
137  * congestion avoidance
138  * INC = RHO^2 / W
139  */
140  segCwnd = tcb->GetCwndInSegments ();
141  increment = std::pow (m_rho, 2) / ((double) segCwnd);
142 
143  m_cWndCnt += increment;
144  segmentsAcked -= 1;
145  }
146 
147  if (m_cWndCnt >= 1.0)
148  {
149  // double to int truncates everytime.
150  uint32_t inc = (uint32_t) m_cWndCnt;
151  m_cWndCnt -= inc;
152 
153  NS_ASSERT (m_cWndCnt >= 0.0);
154 
155  /* This leaves space for a tcp pacing implementation; it would be easy
156  to setup a limit on the maximum increment of the cWnd per ACK received.
157  The remaining increment is leaved for the next ACK. */
158 
159  tcb->m_cWnd += inc * tcb->m_segmentSize;
160 
161 
162  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
163  " ssthresh " << tcb->m_ssThresh <<
164  " with an increment of " << inc * tcb->m_segmentSize);
165  }
166 }
167 
170 {
171  return CopyObject<TcpHybla> (this);
172 }
173 
174 std::string
176 {
177  return "TcpHybla";
178 }
179 
180 
181 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-hybla.cc:83
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#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:44
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-hybla.cc:175
#define min(a, b)
Definition: 80211b.c:44
#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:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
The NewReno implementation.
TcpHybla(void)
Create an unbound tcp socket.
Definition: tcp-hybla.cc:48
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:45
AttributeValue implementation for Time.
Definition: nstime.h:957
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
Time m_minRtt
Minimum smoothed round trip time value seen.
Definition: tcp-hybla.h:79
virtual ~TcpHybla(void)
Definition: tcp-hybla.cc:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:958
void RecalcParam(Ptr< TcpSocketState > tcb, const Time &rtt)
Recalculate algorithm paramenters.
Definition: tcp-hybla.cc:72
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-hybla.cc:30
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-hybla.cc:169
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
Definition: tcp-hybla.cc:97
Implementation of the TCP Hybla algorithm.
Definition: tcp-hybla.h:44
a unique identifier for an interface.
Definition: type-id.h:58
double m_cWndCnt
cWnd integer-to-float counter
Definition: tcp-hybla.h:81
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Definition: tcp-hybla.cc:127
Time m_rRtt
Reference RTT.
Definition: tcp-hybla.h:80
TracedValue< double > m_rho
Rho parameter.
Definition: tcp-hybla.h:78