A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-veno-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 */
14
15#include "ns3/log.h"
16#include "ns3/tcp-congestion-ops.h"
17#include "ns3/tcp-socket-base.h"
18#include "ns3/tcp-veno.h"
19#include "ns3/test.h"
20
21using namespace ns3;
22
23NS_LOG_COMPONENT_DEFINE("TcpVenoTestSuite");
24
25/**
26 * @ingroup internet-test
27 *
28 * @brief Testing the additive increase and multiplicative decrease of TcpVeno
29 */
30class TcpVenoTest : public TestCase
31{
32 public:
33 /**
34 * @brief Constructor.
35 * @param cWnd Congestion window.
36 * @param segmentSize Segment size.
37 * @param ssThresh Slow Start Threshold.
38 * @param rtt The RTT.
39 * @param segmentsAcked Number of segments acked.
40 * @param numRtt Number of RTTs (i.e., rounds) in the test.
41 * @param name Test description.
42 */
45 uint32_t ssThresh,
46 Time rtt,
47 uint32_t segmentsAcked,
48 uint32_t numRtt,
49 const std::string& name);
50
51 private:
52 void DoRun() override;
53
54 /**
55 * @brief TCP Veno additive increase formula.
56 * @param state The congestion control state.
57 * @param diff The difference between actual and expected throughput.
58 * @param beta TCP Veno beta param.
59 */
61
62 /**
63 * @brief TCP Veno multiplicative decrease formula.
64 * @param diff The difference between actual and expected throughput.
65 * @param beta TCP Veno beta param.
66 * @param bytesInFlight Bytes in flight.
67 * @returns The calculated SsThresh.
68 */
70 const UintegerValue& beta,
71 uint32_t bytesInFlight) const;
72
73 /**
74 * @brief Mimics the NewReno IncreaseWindow algorithm.
75 * @param state TCP socket state.
76 * @param segmentsAcked Number of segments acked.
77 */
78 void NewReno_IncreaseWindow(Ptr<TcpSocketState> state, uint32_t segmentsAcked);
79
80 /**
81 * @brief Mimics the NewReno SlowStart algorithm.
82 * @param state TCP socket state.
83 * @param segmentsAcked Number of segments acked.
84 * @returns The number of segments that could be sent.
85 */
87
88 /**
89 * @brief Mimics the NewReno Congestion Avoidance algorithm.
90 * @param state TCP socket state.
91 * @param segmentsAcked Number of segments acked.
92 */
94
95 uint32_t m_cWnd; //!< Congestion window.
96 uint32_t m_segmentSize; //!< Segment size.
97 uint32_t m_ssThresh; //!< Slow Start Threshold.
98 Time m_rtt; //!< RTT.
99 uint32_t m_segmentsAcked; //!< Number of segments ACKed.
100 uint32_t m_numRtt; //!< Number of RTT (i.e., rounds) of the test.
101 bool m_inc; //!< Internal flag to increase every other round.
102 Ptr<TcpSocketState> m_state; //!< TCP socket state.
103};
104
107 uint32_t ssThresh,
108 Time rtt,
109 uint32_t segmentsAcked,
110 uint32_t numRtt,
111 const std::string& name)
112 : TestCase(name),
113 m_cWnd(cWnd),
114 m_segmentSize(segmentSize),
115 m_ssThresh(ssThresh),
116 m_rtt(rtt),
117 m_segmentsAcked(segmentsAcked),
118 m_numRtt(numRtt),
119 m_inc(true)
120{
121}
122
123void
125{
127
128 m_state->m_cWnd = m_cWnd;
129 m_state->m_segmentSize = m_segmentSize;
130 m_state->m_ssThresh = m_ssThresh;
131 m_state->m_minRtt = m_rtt;
132
134
135 // Set baseRtt to 100 ms
136 Time baseRtt = MilliSeconds(100);
137 cong->PktsAcked(m_state, m_segmentsAcked, baseRtt);
138
139 // Re-set Veno to assign a new value of minRtt
140 cong->CongestionStateSet(m_state, TcpSocketState::CA_OPEN);
141
142 uint32_t segCwnd = m_cWnd / m_segmentSize;
143
144 // Calculate expected throughput
145 uint32_t expectedCwnd;
146 double tmp = baseRtt.GetSeconds() / m_rtt.GetSeconds();
147 expectedCwnd = segCwnd * tmp;
148
149 // Calculate the difference between actual and expected throughput
150 uint32_t diff;
151 diff = segCwnd - expectedCwnd;
152
153 // Get the beta attribute
154 UintegerValue beta;
155 cong->GetAttribute("Beta", beta);
156
157 uint32_t cntRtt = 0;
158
159 TcpSocketState state;
160 state.m_cWnd = m_cWnd;
161 state.m_ssThresh = m_ssThresh;
163
164 while (m_numRtt != 0)
165 {
166 // Update cwnd using Veno's additive increase algorithm
167 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
168 cong->IncreaseWindow(m_state, m_segmentsAcked);
169
170 // The first round the internal m_diff of cong will be 4, just like us
171 if (cntRtt == 0)
172 {
173 // Update ssthresh using Veno's multiplicative decrease algorithm
174 uint32_t ssThresh = cong->GetSsThresh(m_state, m_state->m_cWnd);
175
176 // Our calculation of ssthresh
177 uint32_t calculatedSsThresh = MultiplicativeDecrease(diff, beta, m_state->m_cWnd.Get());
178
179 NS_TEST_ASSERT_MSG_EQ(ssThresh,
180 calculatedSsThresh,
181 "Veno has not decremented cWnd correctly based on its"
182 "multiplicative decrease algo.");
183 }
184
185 // Our calculation of cwnd
186 if (cntRtt <= 2)
187 {
188 NewReno_IncreaseWindow(&state, 1);
189 }
190 else
191 {
192 AdditiveIncrease(&state, diff, beta);
193 }
194
196 m_state->m_cWnd.Get(),
197 state.m_cWnd.Get(),
198 "CWnd has not updated correctly based on Veno linear increase algorithm");
199 m_numRtt--;
200 cntRtt++;
201 }
202}
203
204void
206{
207 if (m_cWnd < m_ssThresh)
208 { // Slow start
209 NewReno_SlowStart(state, 1);
210 }
211 else
212 { // Congestion avoidance
213 if (diff < beta.Get())
214 { // Increase cwnd by 1 every RTT when bandwidth is not fully utilized
216 }
217 else
218 { // Increase cwnd by 1 every other RTT when bandwidth is fully utilized
219 if (m_inc)
220 {
222 m_inc = false;
223 }
224 else
225 {
226 m_inc = true;
227 }
228 }
229 }
230}
231
234 const UintegerValue& beta,
235 uint32_t bytesInFlight) const
236{
237 uint32_t calculatedSsThresh;
238 if (diff < beta.Get())
239 {
240 static double tmp = 4.0 / 5.0;
241 calculatedSsThresh =
242 std::max(2 * m_segmentSize, static_cast<uint32_t>(bytesInFlight * tmp));
243 }
244 else
245 {
246 calculatedSsThresh = std::max(2 * m_segmentSize, bytesInFlight / 2);
247 }
248 return calculatedSsThresh;
249}
250
251void
253{
254 if (state->m_cWnd < state->m_ssThresh)
255 {
256 segmentsAcked = NewReno_SlowStart(state, segmentsAcked);
257 }
258
259 if (state->m_cWnd >= state->m_ssThresh)
260 {
261 NewReno_CongestionAvoidance(state, segmentsAcked);
262 }
263}
264
267{
268 if (segmentsAcked >= 1)
269 {
270 state->m_cWnd += state->m_segmentSize;
271 return segmentsAcked - 1;
272 }
273
274 return 0;
275}
276
277void
279{
280 if (segmentsAcked > 0)
281 {
282 double adder =
283 static_cast<double>(state->m_segmentSize * state->m_segmentSize) / state->m_cWnd.Get();
284 adder = std::max(1.0, adder);
285 state->m_cWnd += static_cast<uint32_t>(adder);
286 }
287}
288
289/**
290 * @ingroup internet-test
291 *
292 * @brief TCP Veno TestSuite
293 */
295{
296 public:
298 : TestSuite("tcp-veno-test", Type::UNIT)
299 {
300 AddTestCase(new TcpVenoTest(38 * 1446,
301 1446,
302 40 * 1446,
303 MilliSeconds(100),
304 1,
305 1,
306 "Veno test on cWnd in slow start and non-congestive loss"),
307 TestCase::Duration::QUICK);
308 AddTestCase(new TcpVenoTest(30 * 536,
309 536,
310 20 * 536,
311 MilliSeconds(106),
312 1,
313 1,
314 "Veno test on cWnd with diff < beta"),
315 TestCase::Duration::QUICK);
316 AddTestCase(new TcpVenoTest(60 * 536,
317 536,
318 40 * 536,
319 MilliSeconds(106),
320 1,
321 3,
322 "Veno increment test on cWnd with diff > beta"),
323 TestCase::Duration::QUICK);
324 }
325};
326
327static TcpVenoTestSuite g_tcpVenoTest; //!< Static variable for test initialization
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.
Smart pointer class similar to boost::intrusive_ptr.
Data structure that records the congestion state of a connection.
uint32_t m_segmentSize
Segment size.
@ CA_OPEN
Normal state, no dubious events.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
T Get() const
Get the underlying value.
Hold an unsigned integer type.
Definition uinteger.h:34
uint64_t Get() const
Definition uinteger.cc:26
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpVenoTestSuite g_tcpVenoTest
Static variable for test initialization.