A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-vegas-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-vegas.h"
19#include "ns3/test.h"
20
21using namespace ns3;
22
23NS_LOG_COMPONENT_DEFINE("TcpVegasTestSuite");
24
25/**
26 * \brief TcpVegas congestion control algorithm test
27 */
28class TcpVegasTest : public TestCase
29{
30 public:
31 /**
32 * \brief Constructor.
33 * \param cWnd Congestion window.
34 * \param segmentSize Segment size.
35 * \param ssThresh Slow Start Threshold.
36 * \param rtt The RTT.
37 * \param segmentsAcked Number of segments ACKed.
38 * \param nextTxSeq Next Tx sequence number.
39 * \param lastAckedSeq Last ACKed sequence number.
40 * \param name Test description.
41 */
44 uint32_t ssThresh,
45 Time rtt,
46 uint32_t segmentsAcked,
47 SequenceNumber32 nextTxSeq,
48 SequenceNumber32 lastAckedSeq,
49 const std::string& name);
50
51 private:
52 void DoRun() override;
53 /**
54 * \brief Increases the TCP window.
55 * \param cong The congestion control.
56 */
58 /**
59 * brief Get and check the SSH threshold.
60 * \param cong The congestion control.
61 */
62 void GetSsThresh(Ptr<TcpVegas> cong);
63
64 uint32_t m_cWnd; //!< Congestion window.
65 uint32_t m_segmentSize; //!< Segment size.
66 uint32_t m_ssThresh; //!< Slow Start Threshold.
67 Time m_rtt; //!< RTT.
68 uint32_t m_segmentsAcked; //!< Number of segments ACKed.
69 SequenceNumber32 m_nextTxSeq; //!< Next Tx sequence number.
70 SequenceNumber32 m_lastAckedSeq; //!< Last ACKed sequence number.
71
72 Ptr<TcpSocketState> m_state; //!< TCP socket state.
73};
74
77 uint32_t ssThresh,
78 Time rtt,
79 uint32_t segmentsAcked,
80 SequenceNumber32 nextTxSeq,
81 SequenceNumber32 lastAckedSeq,
82 const std::string& name)
83 : TestCase(name),
84 m_cWnd(cWnd),
85 m_segmentSize(segmentSize),
86 m_ssThresh(ssThresh),
87 m_rtt(rtt),
88 m_segmentsAcked(segmentsAcked),
89 m_nextTxSeq(nextTxSeq),
90 m_lastAckedSeq(lastAckedSeq)
91{
92}
93
94void
96{
98
99 m_state->m_cWnd = m_cWnd;
100 m_state->m_segmentSize = m_segmentSize;
101 m_state->m_ssThresh = m_ssThresh;
102 m_state->m_nextTxSequence = m_nextTxSeq;
103 m_state->m_lastAckedSeq = m_lastAckedSeq;
104 m_state->m_minRtt = m_rtt;
105
107
108 // Set baseRtt to 100 ms
109 cong->PktsAcked(m_state, m_segmentsAcked, MilliSeconds(100));
110
111 // Re-set Vegas to assign a new value of minRtt
112 cong->CongestionStateSet(m_state, TcpSocketState::CA_OPEN);
113 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
114
115 // 2 more calls to PktsAcked to increment cntRtt beyond 2
116 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
117 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
118
119 // Update cwnd using Vegas algorithm
120 cong->IncreaseWindow(m_state, m_segmentsAcked);
121
122 // Our calculation of cwnd
123 IncreaseWindow(cong);
124
125 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "CWnd has not updated correctly");
126 NS_TEST_ASSERT_MSG_EQ(m_state->m_ssThresh.Get(),
128 "SsThresh has not updated correctly");
129}
130
131void
133{
134 Time baseRtt = MilliSeconds(100);
135 uint32_t segCwnd = m_cWnd / m_segmentSize;
136
137 // Calculate expected throughput
138 uint64_t expectedCwnd;
139 expectedCwnd =
140 (uint64_t)segCwnd * (double)baseRtt.GetMilliSeconds() / (double)m_rtt.GetMilliSeconds();
141
142 // Calculate the difference between actual and expected throughput
143 uint32_t diff;
144 diff = segCwnd - expectedCwnd;
145
146 // Get the alpha,beta, and gamma attributes
147 UintegerValue alpha;
148 UintegerValue beta;
149 UintegerValue gamma;
150 cong->GetAttribute("Alpha", alpha);
151 cong->GetAttribute("Beta", beta);
152 cong->GetAttribute("Gamma", gamma);
153
154 if (diff > gamma.Get() && (m_cWnd < m_ssThresh))
155 { // Change from slow-start to linear increase/decrease mode
156 segCwnd = std::min(segCwnd, (uint32_t)expectedCwnd + 1);
157 m_cWnd = segCwnd * m_segmentSize;
158 GetSsThresh(cong);
159 }
160 else if (m_cWnd < m_ssThresh)
161 { // Execute Reno slow start
162 if (m_segmentsAcked >= 1)
163 {
166 }
167 }
168 else
169 { // Linear increase/decrease mode
170 if (diff > beta.Get())
171 {
172 m_cWnd = (segCwnd - 1) * m_segmentSize;
173 GetSsThresh(cong);
174 }
175 else if (diff < alpha.Get())
176 {
177 m_cWnd = (segCwnd + 1) * m_segmentSize;
178 }
179 else
180 {
181 }
182 }
183 m_ssThresh = std::max(m_ssThresh, 3 * m_cWnd / 4);
184}
185
186void
191
192/**
193 * \ingroup internet-test
194 *
195 * \brief TCP Vegas TestSuite
196 */
198{
199 public:
201 : TestSuite("tcp-vegas-test", Type::UNIT)
202 {
204 new TcpVegasTest(38 * 1446,
205 1446,
206 40 * 1446,
207 MilliSeconds(106),
208 1,
209 SequenceNumber32(2893),
210 SequenceNumber32(5785),
211 "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
212 TestCase::Duration::QUICK);
214 new TcpVegasTest(5 * 536,
215 536,
216 10 * 536,
217 MilliSeconds(118),
218 1,
219 SequenceNumber32(3216),
220 SequenceNumber32(3753),
221 "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
222 TestCase::Duration::QUICK);
223 AddTestCase(new TcpVegasTest(60 * 346,
224 346,
225 40 * 346,
226 MilliSeconds(206),
227 1,
228 SequenceNumber32(20761),
229 SequenceNumber32(21107),
230 "Vegas test on cWnd and ssThresh when diff > beta"),
231 TestCase::Duration::QUICK);
232 AddTestCase(new TcpVegasTest(15 * 1446,
233 1446,
234 10 * 1446,
235 MilliSeconds(106),
236 1,
237 SequenceNumber32(21691),
238 SequenceNumber32(24583),
239 "Vegas test on cWnd and ssThresh when diff < alpha"),
240 TestCase::Duration::QUICK);
241 AddTestCase(new TcpVegasTest(20 * 746,
242 746,
243 10 * 746,
244 MilliSeconds(109),
245 1,
246 SequenceNumber32(14921),
247 SequenceNumber32(15667),
248 "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
249 TestCase::Duration::QUICK);
250 }
251};
252
253static TcpVegasTestSuite g_tcpVegasTest; //!< Static variable for test initialization
TcpVegas congestion control algorithm test.
void DoRun() override
Implementation to actually run this TestCase.
SequenceNumber32 m_lastAckedSeq
Last ACKed sequence number.
void GetSsThresh(Ptr< TcpVegas > cong)
brief Get and check the SSH threshold.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_cWnd
Congestion window.
SequenceNumber32 m_nextTxSeq
Next Tx sequence number.
void IncreaseWindow(Ptr< TcpVegas > cong)
Increases the TCP window.
uint32_t m_segmentSize
Segment size.
TcpVegasTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, SequenceNumber32 nextTxSeq, SequenceNumber32 lastAckedSeq, const std::string &name)
Constructor.
uint32_t m_segmentsAcked
Number of segments ACKed.
uint32_t m_ssThresh
Slow Start Threshold.
TCP Vegas TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
@ CA_OPEN
Normal state, no dubious events.
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
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
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
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#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:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpVegasTestSuite g_tcpVegasTest
Static variable for test initialization.