A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpVenoTestSuite");
36 
40 class TcpVenoTest : public TestCase
41 {
42 public:
43  TcpVenoTest (uint32_t cWnd,
44  uint32_t segmentSize,
45  uint32_t ssThresh,
46  Time rtt,
47  uint32_t segmentsAcked,
48  uint32_t numRtt,
49  const std::string &name);
50 
51 private:
52  virtual void DoRun (void);
53  uint32_t AdditiveIncrease (Ptr<TcpVeno> cong, uint32_t diff, UintegerValue beta);
54  uint32_t MultiplicativeDecrease (uint32_t diff, UintegerValue beta);
55 
56  uint32_t m_cWnd;
57  uint32_t m_segmentSize;
58  uint32_t m_ssThresh;
60  uint32_t m_segmentsAcked;
61  uint32_t m_numRtt;
62  bool m_inc;
64 };
65 
66 TcpVenoTest::TcpVenoTest (uint32_t cWnd,
67  uint32_t segmentSize,
68  uint32_t ssThresh,
69  Time rtt,
70  uint32_t segmentsAcked,
71  uint32_t numRtt,
72  const std::string &name)
73  : TestCase (name),
74  m_cWnd (cWnd),
75  m_segmentSize (segmentSize),
76  m_ssThresh (ssThresh),
77  m_rtt (rtt),
78  m_segmentsAcked (segmentsAcked),
79  m_numRtt (numRtt),
80  m_inc (true)
81 {
82 }
83 
84 void
86 {
87  m_state = CreateObject<TcpSocketState> ();
88 
89  m_state->m_cWnd = m_cWnd;
90  m_state->m_segmentSize = m_segmentSize;
91  m_state->m_ssThresh = m_ssThresh;
92 
93  Ptr<TcpVeno> cong = CreateObject <TcpVeno> ();
94 
95  // Set baseRtt to 100 ms
96  cong->PktsAcked (m_state, m_segmentsAcked, MilliSeconds (100));
97 
98  // Re-set Veno to assign a new value of minRtt
99  cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
100  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
101 
102  // Another call to PktsAcked to increment cntRtt beyond 2
103  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
104 
105  Time baseRtt = MilliSeconds (100);
106  uint32_t segCwnd = m_cWnd / m_segmentSize;
107 
108  // Calculate expected throughput
109  uint64_t expectedCwnd;
110  expectedCwnd = (uint64_t) segCwnd * (double) baseRtt.GetMilliSeconds () * 2 / (double) m_rtt.GetMilliSeconds ();
111 
112  // Calculate the difference between actual and expected throughput
113  uint32_t diff;
114  diff = (segCwnd * 2) - expectedCwnd;
115 
116  // Get the beta attribute
117  UintegerValue beta;
118  cong->GetAttribute ("Beta", beta);
119 
120  while (m_numRtt != 0)
121  {
122  // Update cwnd using Veno's additive increase algorithm
123  cong->IncreaseWindow (m_state, m_segmentsAcked);
124 
125  // Our calculation of cwnd
126  uint32_t calculatedCwnd = AdditiveIncrease (cong, diff, beta);
127 
128  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), calculatedCwnd,
129  "CWnd has not updated correctly based on Veno linear increase algorithm");
130  m_numRtt--;
131  }
132 
133  // Update ssthresh using Veno's multiplicative decrease algorithm
134  uint32_t ssThresh = cong->GetSsThresh (m_state, m_state->m_cWnd);
135 
136  // Our calculation of ssthresh
137  uint32_t calculatedSsThresh = MultiplicativeDecrease (diff, beta);
138 
139  NS_TEST_ASSERT_MSG_EQ (ssThresh, calculatedSsThresh,
140  "Veno has not decremented cWnd correctly based on its multiplicative decrease algo.");
141 }
142 
143 uint32_t
145 {
146  if (m_cWnd < m_ssThresh)
147  { // Slow start
148  if (m_segmentsAcked >= 1)
149  {
151  m_segmentsAcked--;
152  }
153  }
154  else
155  { // Congestion avoidance
156  if (diff < beta.Get ())
157  { // Increase cwnd by 1 every RTT when bandwidth is not fully utilized
158  if (m_segmentsAcked > 0)
159  {
160  double adder = static_cast<double> (m_segmentSize * m_segmentSize) / m_cWnd;
161  adder = std::max (1.0, adder);
162  m_cWnd += static_cast<uint32_t> (adder);
163  }
164  }
165  else
166  { // Increase cwnd by 1 every other RTT when bandwidth is fully utilized
167  if (m_inc)
168  {
169  if (m_segmentsAcked > 0)
170  {
171  double adder = static_cast<double> (m_segmentSize * m_segmentSize) / m_cWnd;
172  adder = std::max (1.0, adder);
173  m_cWnd += static_cast<uint32_t> (adder);
174  }
175  m_inc = false;
176  }
177  else
178  {
179  m_inc = true;
180  }
181  }
182  }
183  return m_cWnd;
184 }
185 
186 uint32_t
188 {
189  uint32_t calculatedSsThresh;
190  if (diff < beta.Get ())
191  {
192  calculatedSsThresh = std::max (2 * m_segmentSize, m_cWnd * 4 / 5);
193  }
194  else
195  {
196  calculatedSsThresh = std::max (2 * m_segmentSize, m_cWnd / 2);
197  }
198  return calculatedSsThresh;
199 }
200 
201 
202 // -------------------------------------------------------------------
203 static class TcpVenoTestSuite : public TestSuite
204 {
205 public:
206  TcpVenoTestSuite () : TestSuite ("tcp-veno-test", UNIT)
207  {
208  AddTestCase (new TcpVenoTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (100), 1, 1,
209  "Veno test on cWnd in slow start and non-congestive loss"),
211  AddTestCase (new TcpVenoTest (30 * 536, 536, 20 * 536, MilliSeconds (106), 1, 1,
212  "Veno test on cWnd with diff < beta"),
214  AddTestCase (new TcpVenoTest (60 * 536, 536, 40 * 536, MilliSeconds (106), 1, 3,
215  "Veno increment test on cWnd with diff > beta"),
217  }
218 } g_tcpVenoTest;
219 
220 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Normal state, no dubious events.
A suite of tests to run.
Definition: test.h:1333
#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
uint32_t m_segmentSize
encapsulates test code
Definition: test.h:1147
Ptr< TcpSocketState > m_state
uint64_t Get(void) const
Definition: uinteger.cc:35
Testing the additive increase and multiplicative decrease of TcpVeno.
#define max(a, b)
Definition: 80211b.c:45
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
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:161
uint32_t MultiplicativeDecrease(uint32_t diff, UintegerValue beta)
uint32_t m_segmentsAcked
TcpVenoTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, uint32_t numRtt, const std::string &name)
Fast test.
Definition: test.h:1152
virtual void DoRun(void)
Implementation to actually run this TestCase.
This test suite implements a Unit Test.
Definition: test.h:1343
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
uint32_t AdditiveIncrease(Ptr< TcpVeno > cong, uint32_t diff, UintegerValue beta)
ns3::TcpVenoTestSuite g_tcpVenoTest