A Discrete-Event Network Simulator
API
tcp-veno-test.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 "ns3/test.h"
28 #include "ns3/log.h"
29 #include "ns3/tcp-congestion-ops.h"
30 #include "ns3/tcp-socket-base.h"
31 #include "ns3/tcp-veno.h"
32 
33 using namespace ns3;
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpVenoTestSuite");
36 
43 class TcpVenoTest : public TestCase
44 {
45 public:
56  TcpVenoTest (uint32_t cWnd,
57  uint32_t segmentSize,
58  uint32_t ssThresh,
59  Time rtt,
60  uint32_t segmentsAcked,
61  uint32_t numRtt,
62  const std::string &name);
63 
64 private:
65  virtual void DoRun (void);
66 
73  void AdditiveIncrease (Ptr<TcpSocketState> state, uint32_t diff, UintegerValue beta);
74 
82  uint32_t MultiplicativeDecrease (uint32_t diff, const UintegerValue &beta, uint32_t bytesInFlight);
83 
89  void NewReno_IncreaseWindow (Ptr<TcpSocketState> state, uint32_t segmentsAcked);
90 
97  uint32_t NewReno_SlowStart (Ptr<TcpSocketState> state, uint32_t segmentsAcked);
98 
104  void NewReno_CongestionAvoidance (Ptr<TcpSocketState> state, uint32_t segmentsAcked);
105 
106 
107  uint32_t m_cWnd;
108  uint32_t m_segmentSize;
109  uint32_t m_ssThresh;
111  uint32_t m_segmentsAcked;
112  uint32_t m_numRtt;
113  bool m_inc;
115 };
116 
118  uint32_t segmentSize,
119  uint32_t ssThresh,
120  Time rtt,
121  uint32_t segmentsAcked,
122  uint32_t numRtt,
123  const std::string &name)
124  : TestCase (name),
125  m_cWnd (cWnd),
126  m_segmentSize (segmentSize),
127  m_ssThresh (ssThresh),
128  m_rtt (rtt),
129  m_segmentsAcked (segmentsAcked),
130  m_numRtt (numRtt),
131  m_inc (true)
132 {
133 }
134 
135 void
137 {
138  m_state = CreateObject<TcpSocketState> ();
139 
140  m_state->m_cWnd = m_cWnd;
143 
144  Ptr<TcpVeno> cong = CreateObject <TcpVeno> ();
145 
146  // Set baseRtt to 100 ms
147  Time baseRtt = MilliSeconds (100);
148  cong->PktsAcked (m_state, m_segmentsAcked, baseRtt);
149 
150  // Re-set Veno to assign a new value of minRtt
151  cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
152 
153  uint32_t segCwnd = m_cWnd / m_segmentSize;
154 
155  // Calculate expected throughput
156  uint32_t expectedCwnd;
157  double tmp = baseRtt.GetSeconds () / m_rtt.GetSeconds ();
158  expectedCwnd = segCwnd * tmp;
159 
160  // Calculate the difference between actual and expected throughput
161  uint32_t diff;
162  diff = segCwnd - expectedCwnd;
163 
164  // Get the beta attribute
165  UintegerValue beta;
166  cong->GetAttribute ("Beta", beta);
167 
168  uint32_t cntRtt = 0;
169 
170  TcpSocketState state;
171  state.m_cWnd = m_cWnd;
172  state.m_ssThresh = m_ssThresh;
174 
175  while (m_numRtt != 0)
176  {
177  // Update cwnd using Veno's additive increase algorithm
180 
181  // The first round the internal m_diff of cong will be 4, just like us
182  if (cntRtt == 0)
183  {
184  // Update ssthresh using Veno's multiplicative decrease algorithm
185  uint32_t ssThresh = cong->GetSsThresh (m_state, m_state->m_cWnd);
186 
187  // Our calculation of ssthresh
188  uint32_t calculatedSsThresh = MultiplicativeDecrease (diff, beta, m_state->m_cWnd.Get ());
189 
190  NS_TEST_ASSERT_MSG_EQ (ssThresh, calculatedSsThresh,
191  "Veno has not decremented cWnd correctly based on its"
192  "multiplicative decrease algo.");
193  }
194 
195  // Our calculation of cwnd
196  if (cntRtt <= 2)
197  {
198  NewReno_IncreaseWindow (&state, 1);
199  }
200  else
201  {
202  AdditiveIncrease (&state, diff, beta);
203  }
204 
206  "CWnd has not updated correctly based on Veno linear increase algorithm");
207  m_numRtt--;
208  cntRtt++;
209  }
210 }
211 
212 void
214 {
215  if (m_cWnd < m_ssThresh)
216  { // Slow start
217  NewReno_SlowStart (state, 1);
218  }
219  else
220  { // Congestion avoidance
221  if (diff < beta.Get ())
222  { // Increase cwnd by 1 every RTT when bandwidth is not fully utilized
223  NewReno_CongestionAvoidance (state, 1);
224  }
225  else
226  { // Increase cwnd by 1 every other RTT when bandwidth is fully utilized
227  if (m_inc)
228  {
229  NewReno_CongestionAvoidance (state, 1);
230  m_inc = false;
231  }
232  else
233  {
234  m_inc = true;
235  }
236  }
237  }
238 }
239 
240 uint32_t
242  uint32_t bytesInFlight)
243 {
244  uint32_t calculatedSsThresh;
245  if (diff < beta.Get ())
246  {
247  static double tmp = 4.0 / 5.0;
248  calculatedSsThresh = std::max (2 * m_segmentSize, static_cast<uint32_t> (bytesInFlight * tmp));
249  }
250  else
251  {
252  calculatedSsThresh = std::max (2 * m_segmentSize, bytesInFlight / 2);
253  }
254  return calculatedSsThresh;
255 }
256 
257 void
259 {
260  if (state->m_cWnd < state->m_ssThresh)
261  {
262  segmentsAcked = NewReno_SlowStart (state, segmentsAcked);
263  }
264 
265  if (state->m_cWnd >= state->m_ssThresh)
266  {
267  NewReno_CongestionAvoidance (state, segmentsAcked);
268  }
269 }
270 
271 uint32_t
273 {
274  if (segmentsAcked >= 1)
275  {
276  state->m_cWnd += state->m_segmentSize;
277  return segmentsAcked - 1;
278  }
279 
280  return 0;
281 }
282 
283 void
285 {
286  if (segmentsAcked > 0)
287  {
288  double adder = static_cast<double> (state->m_segmentSize * state->m_segmentSize) / state->m_cWnd.Get ();
289  adder = std::max (1.0, adder);
290  state->m_cWnd += static_cast<uint32_t> (adder);
291  }
292 }
293 
294 
302 {
303 public:
304  TcpVenoTestSuite () : TestSuite ("tcp-veno-test", UNIT)
305  {
306  AddTestCase (new TcpVenoTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (100), 1, 1,
307  "Veno test on cWnd in slow start and non-congestive loss"),
308  TestCase::QUICK);
309  AddTestCase (new TcpVenoTest (30 * 536, 536, 20 * 536, MilliSeconds (106), 1, 1,
310  "Veno test on cWnd with diff < beta"),
311  TestCase::QUICK);
312  AddTestCase (new TcpVenoTest (60 * 536, 536, 40 * 536, MilliSeconds (106), 1, 3,
313  "Veno increment test on cWnd with diff > beta"),
314  TestCase::QUICK);
315  }
316 };
317 
319 
320 
TCP Veno TestSuite.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Testing the additive increase and multiplicative decrease of TcpVeno.
A suite of tests to run.
Definition: test.h:1342
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold during Veno multiplicative-decrease phase.
Definition: tcp-veno.cc:241
void NewReno_IncreaseWindow(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno IncreaseWindow algorithm.
#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:1001
uint32_t m_segmentSize
Segment size.
Data structure that records the congestion state of a connection.
encapsulates test code
Definition: test.h:1155
This test suite implements a Unit Test.
Definition: test.h:1352
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
uint32_t m_segmentsAcked
Number of segments ACKed.
uint64_t Get(void) const
Definition: uinteger.cc:35
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
#define max(a, b)
Definition: 80211b.c:45
TcpVenoTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, uint32_t numRtt, const std::string &name)
Constructor.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:168
bool m_inc
Internal flag to increase every other round.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_ssThresh
Slow Start Threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AdditiveIncrease(Ptr< TcpSocketState > state, uint32_t diff, UintegerValue beta)
TCP Veno additive increase formula.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
uint32_t m_numRtt
Number of RTT (i.e., rounds) of the test.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Enable/disable Veno depending on the congestion state.
Definition: tcp-veno.cc:131
TracedValue< uint32_t > m_cWnd
Congestion window.
uint32_t MultiplicativeDecrease(uint32_t diff, const UintegerValue &beta, uint32_t bytesInFlight)
TCP Veno multiplicative decrease formula.
uint32_t NewReno_SlowStart(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno SlowStart algorithm.
uint32_t m_segmentSize
Segment size.
static TcpVenoTestSuite g_tcpVenoTest
Static variable for test initialization.
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
void NewReno_CongestionAvoidance(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno Congestion Avoidance algorithm.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Veno additive increase algorithm.
Definition: tcp-veno.cc:148
uint32_t m_cWnd
Congestion window.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time m_rtt
RTT.