A Discrete-Event Network Simulator
API
tcp-veno-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
18  *
19  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20  * ResiliNets Research Group https://resilinets.org/
21  * Information and Telecommunication Technology Center (ITTC)
22  * and Department of Electrical Engineering and Computer Science
23  * The University of Kansas Lawrence, KS USA.
24  */
25 
26 #include "ns3/log.h"
27 #include "ns3/tcp-congestion-ops.h"
28 #include "ns3/tcp-socket-base.h"
29 #include "ns3/tcp-veno.h"
30 #include "ns3/test.h"
31 
32 using namespace ns3;
33 
34 NS_LOG_COMPONENT_DEFINE("TcpVenoTestSuite");
35 
41 class TcpVenoTest : public TestCase
42 {
43  public:
54  TcpVenoTest(uint32_t cWnd,
55  uint32_t segmentSize,
56  uint32_t ssThresh,
57  Time rtt,
58  uint32_t segmentsAcked,
59  uint32_t numRtt,
60  const std::string& name);
61 
62  private:
63  void DoRun() override;
64 
71  void AdditiveIncrease(Ptr<TcpSocketState> state, uint32_t diff, UintegerValue beta);
72 
80  uint32_t MultiplicativeDecrease(uint32_t diff,
81  const UintegerValue& beta,
82  uint32_t bytesInFlight) const;
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  uint32_t m_cWnd;
107  uint32_t m_segmentSize;
108  uint32_t m_ssThresh;
110  uint32_t m_segmentsAcked;
111  uint32_t m_numRtt;
112  bool m_inc;
114 };
115 
117  uint32_t segmentSize,
118  uint32_t ssThresh,
119  Time rtt,
120  uint32_t segmentsAcked,
121  uint32_t numRtt,
122  const std::string& name)
123  : TestCase(name),
124  m_cWnd(cWnd),
125  m_segmentSize(segmentSize),
126  m_ssThresh(ssThresh),
127  m_rtt(rtt),
128  m_segmentsAcked(segmentsAcked),
129  m_numRtt(numRtt),
130  m_inc(true)
131 {
132 }
133 
134 void
136 {
137  m_state = CreateObject<TcpSocketState>();
138 
139  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
178  cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
179  cong->IncreaseWindow(m_state, m_segmentsAcked);
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,
191  calculatedSsThresh,
192  "Veno has not decremented cWnd correctly based on its"
193  "multiplicative decrease algo.");
194  }
195 
196  // Our calculation of cwnd
197  if (cntRtt <= 2)
198  {
199  NewReno_IncreaseWindow(&state, 1);
200  }
201  else
202  {
203  AdditiveIncrease(&state, diff, beta);
204  }
205 
207  m_state->m_cWnd.Get(),
208  state.m_cWnd.Get(),
209  "CWnd has not updated correctly based on Veno linear increase algorithm");
210  m_numRtt--;
211  cntRtt++;
212  }
213 }
214 
215 void
217 {
218  if (m_cWnd < m_ssThresh)
219  { // Slow start
220  NewReno_SlowStart(state, 1);
221  }
222  else
223  { // Congestion avoidance
224  if (diff < beta.Get())
225  { // Increase cwnd by 1 every RTT when bandwidth is not fully utilized
226  NewReno_CongestionAvoidance(state, 1);
227  }
228  else
229  { // Increase cwnd by 1 every other RTT when bandwidth is fully utilized
230  if (m_inc)
231  {
232  NewReno_CongestionAvoidance(state, 1);
233  m_inc = false;
234  }
235  else
236  {
237  m_inc = true;
238  }
239  }
240  }
241 }
242 
243 uint32_t
245  const UintegerValue& beta,
246  uint32_t bytesInFlight) const
247 {
248  uint32_t calculatedSsThresh;
249  if (diff < beta.Get())
250  {
251  static double tmp = 4.0 / 5.0;
252  calculatedSsThresh =
253  std::max(2 * m_segmentSize, static_cast<uint32_t>(bytesInFlight * tmp));
254  }
255  else
256  {
257  calculatedSsThresh = std::max(2 * m_segmentSize, bytesInFlight / 2);
258  }
259  return calculatedSsThresh;
260 }
261 
262 void
264 {
265  if (state->m_cWnd < state->m_ssThresh)
266  {
267  segmentsAcked = NewReno_SlowStart(state, segmentsAcked);
268  }
269 
270  if (state->m_cWnd >= state->m_ssThresh)
271  {
272  NewReno_CongestionAvoidance(state, segmentsAcked);
273  }
274 }
275 
276 uint32_t
278 {
279  if (segmentsAcked >= 1)
280  {
281  state->m_cWnd += state->m_segmentSize;
282  return segmentsAcked - 1;
283  }
284 
285  return 0;
286 }
287 
288 void
290 {
291  if (segmentsAcked > 0)
292  {
293  double adder =
294  static_cast<double>(state->m_segmentSize * state->m_segmentSize) / state->m_cWnd.Get();
295  adder = std::max(1.0, adder);
296  state->m_cWnd += static_cast<uint32_t>(adder);
297  }
298 }
299 
306 {
307  public:
309  : TestSuite("tcp-veno-test", UNIT)
310  {
311  AddTestCase(new TcpVenoTest(38 * 1446,
312  1446,
313  40 * 1446,
314  MilliSeconds(100),
315  1,
316  1,
317  "Veno test on cWnd in slow start and non-congestive loss"),
318  TestCase::QUICK);
319  AddTestCase(new TcpVenoTest(30 * 536,
320  536,
321  20 * 536,
322  MilliSeconds(106),
323  1,
324  1,
325  "Veno test on cWnd with diff < beta"),
326  TestCase::QUICK);
327  AddTestCase(new TcpVenoTest(60 * 536,
328  536,
329  40 * 536,
330  MilliSeconds(106),
331  1,
332  3,
333  "Veno increment test on cWnd with diff > beta"),
334  TestCase::QUICK);
335  }
336 };
337 
#define max(a, b)
Definition: 80211b.c:42
Testing the additive increase and multiplicative decrease of TcpVeno.
void NewReno_CongestionAvoidance(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno Congestion Avoidance algorithm.
Time m_rtt
RTT.
uint32_t m_numRtt
Number of RTT (i.e., rounds) of the test.
bool m_inc
Internal flag to increase every other round.
uint32_t m_segmentsAcked
Number of segments ACKed.
uint32_t MultiplicativeDecrease(uint32_t diff, const UintegerValue &beta, uint32_t bytesInFlight) const
TCP Veno multiplicative decrease formula.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t NewReno_SlowStart(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno SlowStart algorithm.
uint32_t m_cWnd
Congestion window.
TcpVenoTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, uint32_t numRtt, const std::string &name)
Constructor.
uint32_t m_ssThresh
Slow Start Threshold.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
void NewReno_IncreaseWindow(Ptr< TcpSocketState > state, uint32_t segmentsAcked)
Mimics the NewReno IncreaseWindow algorithm.
void AdditiveIncrease(Ptr< TcpSocketState > state, uint32_t diff, UintegerValue beta)
TCP Veno additive increase formula.
TCP Veno TestSuite.
Data structure that records the congestion state of a connection.
uint32_t m_segmentSize
Segment size.
Time m_minRtt
Minimum RTT observed throughout the connection.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
T Get() const
Get the underlying value.
Definition: traced-value.h:249
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:144
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpVenoTestSuite g_tcpVenoTest
Static variable for test initialization.