A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/tcp-socket-base.h"
29 #include "ns3/log.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("TcpVeno");
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::TcpVeno")
41  .AddConstructor<TcpVeno> ()
42  .SetGroupName ("Internet")
43  .AddAttribute ("Beta", "Threshold for congestion detection",
44  UintegerValue (6),
46  MakeUintegerChecker<uint32_t> ())
47  ;
48  return tid;
49 }
50 
52  : TcpNewReno (),
53  m_baseRtt (Time::Max ()),
54  m_minRtt (Time::Max ()),
55  m_cntRtt (0),
56  m_doingVenoNow (true),
57  m_diff (0),
58  m_inc (true),
59  m_ackCnt (0),
60  m_beta (6)
61 {
62  NS_LOG_FUNCTION (this);
63 }
64 
66  : TcpNewReno (sock),
67  m_baseRtt (sock.m_baseRtt),
68  m_minRtt (sock.m_minRtt),
69  m_cntRtt (sock.m_cntRtt),
70  m_doingVenoNow (true),
71  m_diff (0),
72  m_inc (true),
73  m_ackCnt (sock.m_ackCnt),
74  m_beta (sock.m_beta)
75 {
76  NS_LOG_FUNCTION (this);
77 }
78 
80 {
81  NS_LOG_FUNCTION (this);
82 }
83 
86 {
87  return CopyObject<TcpVeno> (this);
88 }
89 
90 void
91 TcpVeno::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
92  const Time& rtt)
93 {
94  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
95 
96  if (rtt.IsZero ())
97  {
98  return;
99  }
100 
101  m_minRtt = std::min (m_minRtt, rtt);
102  NS_LOG_DEBUG ("Updated m_minRtt= " << m_minRtt);
103 
104 
105  m_baseRtt = std::min (m_baseRtt, rtt);
106  NS_LOG_DEBUG ("Updated m_baseRtt= " << m_baseRtt);
107 
108  // Update RTT counter
109  m_cntRtt++;
110  NS_LOG_DEBUG ("Updated m_cntRtt= " << m_cntRtt);
111 }
112 
113 void
115 {
116  NS_LOG_FUNCTION (this << tcb);
117 
118  m_doingVenoNow = true;
119  m_minRtt = Time::Max ();
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this);
126 
127  m_doingVenoNow = false;
128 }
129 
130 void
132  const TcpSocketState::TcpCongState_t newState)
133 {
134  NS_LOG_FUNCTION (this << tcb << newState);
135  if (newState == TcpSocketState::CA_OPEN)
136  {
137  EnableVeno (tcb);
138  NS_LOG_LOGIC ("Veno is now on.");
139  }
140  else
141  {
142  DisableVeno ();
143  NS_LOG_LOGIC ("Veno is turned off.");
144  }
145 }
146 
147 void
148 TcpVeno::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
149 {
150  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
151 
152  if (!m_doingVenoNow)
153  {
154  // If Veno is not on, we follow NewReno algorithm
155  NS_LOG_LOGIC ("Veno is not turned on, we follow NewReno algorithm.");
156  TcpNewReno::IncreaseWindow (tcb, segmentsAcked);
157  return;
158  }
159 
160  // We do the Veno calculations only if we got enough RTT samples
161  if (m_cntRtt <= 2)
162  { // We do not have enough RTT samples, so we should behave like NewReno
163  NS_LOG_LOGIC ("We do not have enough RTT samples to perform Veno "
164  "calculations, we behave like NewReno.");
165  TcpNewReno::IncreaseWindow (tcb, segmentsAcked);
166  }
167  else
168  {
169  NS_LOG_LOGIC ("We have enough RTT samples to perform Veno calculations.");
170 
171  uint64_t targetCwnd;
172  uint32_t segCwnd = tcb->GetCwndInSegments ();
173 
174  // Calculate the cwnd we should have
175  targetCwnd = (uint64_t) segCwnd * (double) m_baseRtt.GetMilliSeconds () * 2;
176  targetCwnd = targetCwnd / (double) m_minRtt.GetMilliSeconds ();
177  NS_LOG_DEBUG ("Calculated targetCwnd = " << targetCwnd);
178 
179  // Calculate the difference between actual and target cwnd
180  m_diff = (segCwnd * 2) - targetCwnd;
181  NS_LOG_DEBUG ("Calculated m_diff = " << m_diff);
182 
183  if (tcb->m_cWnd < tcb->m_ssThresh)
184  { // Slow start mode. Veno employs same slow start algorithm as NewReno's.
185  NS_LOG_LOGIC ("We are in slow start, behave like NewReno.");
186  segmentsAcked = TcpNewReno::SlowStart (tcb, segmentsAcked);
187  }
188  else
189  { // Congestion avoidance mode
190  NS_LOG_LOGIC ("We are in congestion avoidance, execute Veno additive "
191  "increase algo.");
192  if (m_diff < m_beta)
193  {
194  // Available bandwidth is not fully utilized,
195  // increase cwnd by 1 every RTT
196  NS_LOG_LOGIC ("Available bandwidth not fully utilized, increase "
197  "cwnd by 1 every RTT");
198  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
199  }
200  else
201  {
202  // Available bandwidth is fully utilized,
203  // increase cwnd by 1 every other RTT
204  NS_LOG_LOGIC ("Available bandwidth fully utilized, increase cwnd "
205  "by 1 every other RTT");
206  if (m_inc)
207  {
208  TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
209  m_inc = false;
210  }
211  else
212  {
213  m_inc = true;
214  }
215  }
216  }
217  }
218 
219  // Reset minRtt
220  m_minRtt = Time::Max ();
221 }
222 
223 std::string
225 {
226  return "TcpVeno";
227 }
228 
229 uint32_t
231  uint32_t bytesInFlight)
232 {
233  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
234 
235  if (m_diff < m_beta)
236  {
237  // random loss due to bit errors is most likely to have occurred,
238  // we cut cwnd by 1/5
239  NS_LOG_LOGIC ("Random loss is most likely to have occurred, "
240  "cwnd is reduced by 1/5");
241  return std::max (bytesInFlight * 4 / 5, 2 * tcb->m_segmentSize);
242  }
243  else
244  {
245  // congestion-based loss is most likely to have occurred,
246  // we reduce cwnd by 1/2 as in NewReno
247  NS_LOG_LOGIC ("Congestive loss is most likely to have occurred, "
248  "cwnd is halved");
249  return std::max (bytesInFlight / 2, 2 * tcb->m_segmentSize);
250  }
251 }
252 
253 } // namespace ns3
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-veno.cc:85
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:44
#define min(a, b)
Definition: 80211b.c:44
bool IsZero(void) const
Definition: nstime.h:274
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold during Veno multiplicative-decrease phase.
Definition: tcp-veno.cc:230
TcpVeno(void)
Create an unbound tcp socket.
Definition: tcp-veno.cc:51
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void DisableVeno()
Turn off Veno.
Definition: tcp-veno.cc:123
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:69
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:259
#define max(a, b)
Definition: 80211b.c:45
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
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-veno.cc:224
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
TcpCongState_t
Definition of the Congestion state machine.
void EnableVeno(Ptr< TcpSocketState > tcb)
Enable Veno algorithm to start Veno sampling.
Definition: tcp-veno.cc:114
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Enable/disable Veno depending on the congestion state.
Definition: tcp-veno.cc:131
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-veno.cc:37
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Perform RTT sampling needed to execute Veno algorithm.
Definition: tcp-veno.cc:91
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time m_baseRtt
Minimum of all RTT measurements seen during connection.
Definition: tcp-veno.h:163
uint32_t m_cntRtt
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:148
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
virtual ~TcpVeno(void)
Definition: tcp-veno.cc:79
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
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:827
Time m_minRtt
Minimum of RTTs measured within last RTT.
Definition: tcp-veno.h:164