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
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("TcpVenoTestSuite");
35
42class TcpVenoTest : public TestCase
43{
44 public:
57 uint32_t ssThresh,
58 Time rtt,
59 uint32_t segmentsAcked,
60 uint32_t numRtt,
61 const std::string& name);
62
63 private:
64 void DoRun() override;
65
73
82 const UintegerValue& beta,
83 uint32_t bytesInFlight);
84
90 void NewReno_IncreaseWindow(Ptr<TcpSocketState> state, uint32_t segmentsAcked);
91
99
106
113 bool m_inc;
115};
116
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
135void
137{
138 m_state = CreateObject<TcpSocketState>();
139
144
145 Ptr<TcpVeno> cong = CreateObject<TcpVeno>();
146
147 // Set baseRtt to 100 ms
148 Time baseRtt = MilliSeconds(100);
149 cong->PktsAcked(m_state, m_segmentsAcked, baseRtt);
150
151 // Re-set Veno to assign a new value of minRtt
152 cong->CongestionStateSet(m_state, TcpSocketState::CA_OPEN);
153
154 uint32_t segCwnd = m_cWnd / m_segmentSize;
155
156 // Calculate expected throughput
157 uint32_t expectedCwnd;
158 double tmp = baseRtt.GetSeconds() / m_rtt.GetSeconds();
159 expectedCwnd = segCwnd * tmp;
160
161 // Calculate the difference between actual and expected throughput
162 uint32_t diff;
163 diff = segCwnd - expectedCwnd;
164
165 // Get the beta attribute
166 UintegerValue beta;
167 cong->GetAttribute("Beta", beta);
168
169 uint32_t cntRtt = 0;
170
171 TcpSocketState state;
172 state.m_cWnd = m_cWnd;
173 state.m_ssThresh = m_ssThresh;
175
176 while (m_numRtt != 0)
177 {
178 // Update cwnd using Veno's additive increase algorithm
179 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
180 cong->IncreaseWindow(m_state, m_segmentsAcked);
181
182 // The first round the internal m_diff of cong will be 4, just like us
183 if (cntRtt == 0)
184 {
185 // Update ssthresh using Veno's multiplicative decrease algorithm
186 uint32_t ssThresh = cong->GetSsThresh(m_state, m_state->m_cWnd);
187
188 // Our calculation of ssthresh
189 uint32_t calculatedSsThresh = MultiplicativeDecrease(diff, beta, m_state->m_cWnd.Get());
190
191 NS_TEST_ASSERT_MSG_EQ(ssThresh,
192 calculatedSsThresh,
193 "Veno has not decremented cWnd correctly based on its"
194 "multiplicative decrease algo.");
195 }
196
197 // Our calculation of cwnd
198 if (cntRtt <= 2)
199 {
200 NewReno_IncreaseWindow(&state, 1);
201 }
202 else
203 {
204 AdditiveIncrease(&state, diff, beta);
205 }
206
208 m_state->m_cWnd.Get(),
209 state.m_cWnd.Get(),
210 "CWnd has not updated correctly based on Veno linear increase algorithm");
211 m_numRtt--;
212 cntRtt++;
213 }
214}
215
216void
218{
219 if (m_cWnd < m_ssThresh)
220 { // Slow start
221 NewReno_SlowStart(state, 1);
222 }
223 else
224 { // Congestion avoidance
225 if (diff < beta.Get())
226 { // Increase cwnd by 1 every RTT when bandwidth is not fully utilized
228 }
229 else
230 { // Increase cwnd by 1 every other RTT when bandwidth is fully utilized
231 if (m_inc)
232 {
234 m_inc = false;
235 }
236 else
237 {
238 m_inc = true;
239 }
240 }
241 }
242}
243
246 const UintegerValue& beta,
247 uint32_t bytesInFlight)
248{
249 uint32_t calculatedSsThresh;
250 if (diff < beta.Get())
251 {
252 static double tmp = 4.0 / 5.0;
253 calculatedSsThresh =
254 std::max(2 * m_segmentSize, static_cast<uint32_t>(bytesInFlight * tmp));
255 }
256 else
257 {
258 calculatedSsThresh = std::max(2 * m_segmentSize, bytesInFlight / 2);
259 }
260 return calculatedSsThresh;
261}
262
263void
265{
266 if (state->m_cWnd < state->m_ssThresh)
267 {
268 segmentsAcked = NewReno_SlowStart(state, segmentsAcked);
269 }
270
271 if (state->m_cWnd >= state->m_ssThresh)
272 {
273 NewReno_CongestionAvoidance(state, segmentsAcked);
274 }
275}
276
279{
280 if (segmentsAcked >= 1)
281 {
282 state->m_cWnd += state->m_segmentSize;
283 return segmentsAcked - 1;
284 }
285
286 return 0;
287}
288
289void
291{
292 if (segmentsAcked > 0)
293 {
294 double adder =
295 static_cast<double>(state->m_segmentSize * state->m_segmentSize) / state->m_cWnd.Get();
296 adder = std::max(1.0, adder);
297 state->m_cWnd += static_cast<uint32_t>(adder);
298 }
299}
300
308{
309 public:
311 : TestSuite("tcp-veno-test", UNIT)
312 {
313 AddTestCase(new TcpVenoTest(38 * 1446,
314 1446,
315 40 * 1446,
316 MilliSeconds(100),
317 1,
318 1,
319 "Veno test on cWnd in slow start and non-congestive loss"),
320 TestCase::QUICK);
321 AddTestCase(new TcpVenoTest(30 * 536,
322 536,
323 20 * 536,
324 MilliSeconds(106),
325 1,
326 1,
327 "Veno test on cWnd with diff < beta"),
328 TestCase::QUICK);
329 AddTestCase(new TcpVenoTest(60 * 536,
330 536,
331 40 * 536,
332 MilliSeconds(106),
333 1,
334 3,
335 "Veno increment test on cWnd with diff > beta"),
336 TestCase::QUICK);
337 }
338};
339
#define max(a, b)
Definition: 80211b.c:43
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 MultiplicativeDecrease(uint32_t diff, const UintegerValue &beta, uint32_t bytesInFlight)
TCP Veno multiplicative decrease formula.
uint32_t m_segmentsAcked
Number of segments ACKed.
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:305
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:402
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:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpVenoTestSuite g_tcpVenoTest
Static variable for test initialization.