A Discrete-Event Network Simulator
API
tcp-veno.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
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  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  */
26 
27 #include "tcp-veno.h"
28 #include "ns3/log.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("TcpVeno");
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::TcpVeno")
40  .AddConstructor<TcpVeno> ()
41  .SetGroupName ("Internet")
42  .AddAttribute ("Beta", "Threshold for congestion detection",
43  UintegerValue (3),
45  MakeUintegerChecker<uint32_t> ())
46  ;
47  return tid;
48 }
49 
51  : TcpNewReno (),
52  m_baseRtt (Time::Max ()),
53  m_minRtt (Time::Max ()),
54  m_cntRtt (0),
55  m_doingVenoNow (true),
56  m_diff (0),
57  m_inc (true),
58  m_ackCnt (0),
59  m_beta (6)
60 {
61  NS_LOG_FUNCTION (this);
62 }
63 
65  : TcpNewReno (sock),
66  m_baseRtt (sock.m_baseRtt),
67  m_minRtt (sock.m_minRtt),
68  m_cntRtt (sock.m_cntRtt),
69  m_doingVenoNow (true),
70  m_diff (0),
71  m_inc (true),
72  m_ackCnt (sock.m_ackCnt),
73  m_beta (sock.m_beta)
74 {
75  NS_LOG_FUNCTION (this);
76 }
77 
79 {
80  NS_LOG_FUNCTION (this);
81 }
82 
85 {
86  return CopyObject<TcpVeno> (this);
87 }
88 
89 void
90 TcpVeno::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
91  const Time& rtt)
92 {
93  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
94 
95  if (rtt.IsZero ())
96  {
97  return;
98  }
99 
100  m_minRtt = std::min (m_minRtt, rtt);
101  NS_LOG_DEBUG ("Updated m_minRtt= " << m_minRtt);
102 
103 
104  m_baseRtt = std::min (m_baseRtt, rtt);
105  NS_LOG_DEBUG ("Updated m_baseRtt= " << m_baseRtt);
106 
107  // Update RTT counter
108  m_cntRtt++;
109  NS_LOG_DEBUG ("Updated m_cntRtt= " << m_cntRtt);
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION (this);
116 
117  m_doingVenoNow = true;
118  m_minRtt = Time::Max ();
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION (this);
125 
126  m_doingVenoNow = false;
127 }
128 
129 void
131  const TcpSocketState::TcpCongState_t newState)
132 {
133  NS_LOG_FUNCTION (this << tcb << newState);
134  if (newState == TcpSocketState::CA_OPEN)
135  {
136  EnableVeno ();
137  NS_LOG_LOGIC ("Veno is now on.");
138  }
139  else
140  {
141  DisableVeno ();
142  NS_LOG_LOGIC ("Veno is turned off.");
143  }
144 }
145 
146 void
147 TcpVeno::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
148 {
149  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
150 
151  // Always calculate m_diff, even if we are not doing Veno now
152  uint32_t targetCwnd;
153  uint32_t segCwnd = tcb->GetCwndInSegments ();
154 
155  /*
156  * Calculate the cwnd we should have. baseRtt is the minimum RTT
157  * per-connection, minRtt is the minimum RTT in this window
158  *
159  * little trick:
160  * desidered throughput is currentCwnd * baseRtt
161  * target cwnd is throughput / minRtt
162  */
163  double tmp = m_baseRtt.GetSeconds () / m_minRtt.GetSeconds ();
164  targetCwnd = static_cast<uint32_t> (segCwnd * tmp);
165  NS_LOG_DEBUG ("Calculated targetCwnd = " << targetCwnd);
166  NS_ASSERT (segCwnd >= targetCwnd); // implies baseRtt <= minRtt
167 
168  // Calculate the difference between actual and target cwnd
169  m_diff = segCwnd - targetCwnd;
170  NS_LOG_DEBUG ("Calculated m_diff = " << m_diff);
171 
172  if (!m_doingVenoNow)
173  {
174  // If Veno is not on, we follow NewReno algorithm
175  NS_LOG_LOGIC ("Veno is not turned on, we follow NewReno algorithm.");
176  TcpNewReno::IncreaseWindow (tcb, segmentsAcked);
177  return;
178  }
179 
180  // We do the Veno calculations only if we got enough RTT samples
181  if (m_cntRtt <= 2)
182  { // We do not have enough RTT samples, so we should behave like NewReno
183  NS_LOG_LOGIC ("We do not have enough RTT samples to perform Veno "
184  "calculations, we behave like NewReno.");
185  TcpNewReno::IncreaseWindow (tcb, segmentsAcked);
186  }
187  else
188  {
189  NS_LOG_LOGIC ("We have enough RTT samples to perform Veno calculations.");
190 
191  if (tcb->m_cWnd < tcb->m_ssThresh)
192  { // Slow start mode. Veno employs same slow start algorithm as NewReno's.
193  NS_LOG_LOGIC ("We are in slow start, behave like NewReno.");
194  TcpNewReno::SlowStart (tcb, segmentsAcked);
195  }
196  else
197  { // Congestion avoidance mode
198  NS_LOG_LOGIC ("We are in congestion avoidance, execute Veno additive "
199  "increase algo.");
200 
201  if (m_diff < m_beta)
202  {
203  // Available bandwidth is not fully utilized,
204  // increase cwnd by 1 every RTT
205  NS_LOG_LOGIC ("Available bandwidth not fully utilized, increase "
206  "cwnd by 1 every RTT");
207  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
208  }
209  else
210  {
211  // Available bandwidth is fully utilized,
212  // increase cwnd by 1 every other RTT
213  NS_LOG_LOGIC ("Available bandwidth fully utilized, increase cwnd "
214  "by 1 every other RTT");
215  if (m_inc)
216  {
217  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
218  m_inc = false;
219  }
220  else
221  {
222  m_inc = true;
223  }
224  }
225  }
226  }
227 
228  // Reset cntRtt & minRtt every RTT
229  m_cntRtt = 0;
230  m_minRtt = Time::Max ();
231 }
232 
233 std::string
235 {
236  return "TcpVeno";
237 }
238 
239 uint32_t
241  uint32_t bytesInFlight)
242 {
243  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
244 
245  if (m_diff < m_beta)
246  {
247  // random loss due to bit errors is most likely to have occurred,
248  // we cut cwnd by 1/5
249  NS_LOG_LOGIC ("Random loss is most likely to have occurred, "
250  "cwnd is reduced by 1/5");
251  static double tmp = 4.0/5.0;
252  return std::max (static_cast<uint32_t> (bytesInFlight * tmp),
253  2 * tcb->m_segmentSize);
254  }
255  else
256  {
257  // congestion-based loss is most likely to have occurred,
258  // we reduce cwnd by 1/2 as in NewReno
259  NS_LOG_LOGIC ("Congestive loss is most likely to have occurred, "
260  "cwnd is halved");
261  return TcpNewReno::GetSsThresh (tcb, bytesInFlight);
262  }
263 }
264 
265 } // namespace ns3
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-veno.cc:84
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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 "...
Normal state, no dubious events.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define min(a, b)
Definition: 80211b.c:42
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold during Veno multiplicative-decrease phase.
Definition: tcp-veno.cc:240
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
TcpVeno(void)
Create an unbound tcp socket.
Definition: tcp-veno.cc:50
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm
#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
void DisableVeno()
Turn off Veno.
Definition: tcp-veno.cc:122
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
The NewReno implementation.
An implementation of TCP Veno.
Definition: tcp-veno.h:70
bool m_inc
If true, cwnd needs to be incremented.
Definition: tcp-veno.h:168
uint32_t m_beta
Threshold for congestion detection.
Definition: tcp-veno.h:170
static Time Max()
Maximum representable Time.
Definition: nstime.h:273
#define max(a, b)
Definition: 80211b.c:43
bool IsZero(void) const
Definition: nstime.h:288
bool m_doingVenoNow
If true, do Veno for this RTT.
Definition: tcp-veno.h:166
Hold an unsigned integer type.
Definition: uinteger.h:44
uint32_t m_diff
Difference between expected and actual throughput.
Definition: tcp-veno.h:167
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
TcpCongState_t
Definition of the Congestion state machine.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-veno.cc:234
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Enable/disable Veno depending on the congestion state.
Definition: tcp-veno.cc:130
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-veno.cc:36
TracedValue< uint32_t > m_cWnd
Congestion window.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Perform RTT sampling needed to execute Veno algorithm.
Definition: tcp-veno.cc:90
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time m_baseRtt
Minimum of all RTT measurements seen during connection.
Definition: tcp-veno.h:163
uint32_t m_cntRtt
Number of RTT measurements during last RTT.
Definition: tcp-veno.h:165
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Veno additive increase algorithm.
Definition: tcp-veno.cc:147
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
virtual ~TcpVeno(void)
Definition: tcp-veno.cc:78
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Time m_minRtt
Minimum of RTTs measured within last RTT.
Definition: tcp-veno.h:164
void EnableVeno()
Enable Veno algorithm to start Veno sampling.
Definition: tcp-veno.cc:113
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.