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 * 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-vegas.h"
30#include "ns3/test.h"
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("TcpVegasTestSuite");
35
39class TcpVegasTest : public TestCase
40{
41 public:
55 uint32_t ssThresh,
56 Time rtt,
57 uint32_t segmentsAcked,
58 SequenceNumber32 nextTxSeq,
59 SequenceNumber32 lastAckedSeq,
60 const std::string& name);
61
62 private:
63 void DoRun() override;
73 void GetSsThresh(Ptr<TcpVegas> cong);
74
82
84};
85
88 uint32_t ssThresh,
89 Time rtt,
90 uint32_t segmentsAcked,
91 SequenceNumber32 nextTxSeq,
92 SequenceNumber32 lastAckedSeq,
93 const std::string& name)
94 : TestCase(name),
95 m_cWnd(cWnd),
96 m_segmentSize(segmentSize),
97 m_ssThresh(ssThresh),
98 m_rtt(rtt),
99 m_segmentsAcked(segmentsAcked),
100 m_nextTxSeq(nextTxSeq),
101 m_lastAckedSeq(lastAckedSeq)
102{
103}
104
105void
107{
108 m_state = CreateObject<TcpSocketState>();
109
116
117 Ptr<TcpVegas> cong = CreateObject<TcpVegas>();
118
119 // Set baseRtt to 100 ms
120 cong->PktsAcked(m_state, m_segmentsAcked, MilliSeconds(100));
121
122 // Re-set Vegas to assign a new value of minRtt
123 cong->CongestionStateSet(m_state, TcpSocketState::CA_OPEN);
124 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
125
126 // 2 more calls to PktsAcked to increment cntRtt beyond 2
127 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
128 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
129
130 // Update cwnd using Vegas algorithm
131 cong->IncreaseWindow(m_state, m_segmentsAcked);
132
133 // Our calculation of cwnd
134 IncreaseWindow(cong);
135
136 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "CWnd has not updated correctly");
139 "SsThresh has not updated correctly");
140}
141
142void
144{
145 Time baseRtt = MilliSeconds(100);
146 uint32_t segCwnd = m_cWnd / m_segmentSize;
147
148 // Calculate expected throughput
149 uint64_t expectedCwnd;
150 expectedCwnd =
151 (uint64_t)segCwnd * (double)baseRtt.GetMilliSeconds() / (double)m_rtt.GetMilliSeconds();
152
153 // Calculate the difference between actual and expected throughput
154 uint32_t diff;
155 diff = segCwnd - expectedCwnd;
156
157 // Get the alpha,beta, and gamma attributes
158 UintegerValue alpha;
159 UintegerValue beta;
160 UintegerValue gamma;
161 cong->GetAttribute("Alpha", alpha);
162 cong->GetAttribute("Beta", beta);
163 cong->GetAttribute("Gamma", gamma);
164
165 if (diff > gamma.Get() && (m_cWnd < m_ssThresh))
166 { // Change from slow-start to linear increase/decrease mode
167 segCwnd = std::min(segCwnd, (uint32_t)expectedCwnd + 1);
168 m_cWnd = segCwnd * m_segmentSize;
169 GetSsThresh(cong);
170 }
171 else if (m_cWnd < m_ssThresh)
172 { // Execute Reno slow start
173 if (m_segmentsAcked >= 1)
174 {
177 }
178 }
179 else
180 { // Linear increase/decrease mode
181 if (diff > beta.Get())
182 {
183 m_cWnd = (segCwnd - 1) * m_segmentSize;
184 GetSsThresh(cong);
185 }
186 else if (diff < alpha.Get())
187 {
188 m_cWnd = (segCwnd + 1) * m_segmentSize;
189 }
190 else
191 {
192 }
193 }
194 m_ssThresh = std::max(m_ssThresh, 3 * m_cWnd / 4);
195}
196
197void
199{
200 m_ssThresh = std::max(std::min(m_ssThresh, m_cWnd - m_segmentSize), 2 * m_segmentSize);
201}
202
209{
210 public:
212 : TestSuite("tcp-vegas-test", UNIT)
213 {
215 new TcpVegasTest(38 * 1446,
216 1446,
217 40 * 1446,
218 MilliSeconds(106),
219 1,
220 SequenceNumber32(2893),
221 SequenceNumber32(5785),
222 "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
225 new TcpVegasTest(5 * 536,
226 536,
227 10 * 536,
228 MilliSeconds(118),
229 1,
230 SequenceNumber32(3216),
231 SequenceNumber32(3753),
232 "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
234 AddTestCase(new TcpVegasTest(60 * 346,
235 346,
236 40 * 346,
237 MilliSeconds(206),
238 1,
239 SequenceNumber32(20761),
240 SequenceNumber32(21107),
241 "Vegas test on cWnd and ssThresh when diff > beta"),
243 AddTestCase(new TcpVegasTest(15 * 1446,
244 1446,
245 10 * 1446,
246 MilliSeconds(106),
247 1,
248 SequenceNumber32(21691),
249 SequenceNumber32(24583),
250 "Vegas test on cWnd and ssThresh when diff < alpha"),
252 AddTestCase(new TcpVegasTest(20 * 746,
253 746,
254 10 * 746,
255 MilliSeconds(109),
256 1,
257 SequenceNumber32(14921),
258 SequenceNumber32(15667),
259 "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
261 }
262};
263
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.
Time m_rtt
RTT.
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.
Definition: ptr.h:78
uint32_t m_segmentSize
Segment size.
Time m_minRtt
Minimum RTT observed throughout the connection.
@ CA_OPEN
Normal state, no dubious events.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
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
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:407
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
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:144
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpVegasTestSuite g_tcpVegasTest
Static variable for test initialization.