A Discrete-Event Network Simulator
API
tcp-vegas-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-vegas.h"
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE ("TcpVegasTestSuite");
36
40class TcpVegasTest : public TestCase
41{
42public:
56 uint32_t ssThresh,
57 Time rtt,
58 uint32_t segmentsAcked,
59 SequenceNumber32 nextTxSeq,
60 SequenceNumber32 lastAckedSeq,
61 const std::string &name);
62
63private:
64 virtual void DoRun (void);
69 void IncreaseWindow (Ptr<TcpVegas> cong);
74 void GetSsThresh (Ptr<TcpVegas> cong);
75
83
85};
86
89 uint32_t ssThresh,
90 Time rtt,
91 uint32_t segmentsAcked,
92 SequenceNumber32 nextTxSeq,
93 SequenceNumber32 lastAckedSeq,
94 const std::string &name)
95 : TestCase (name),
96 m_cWnd (cWnd),
97 m_segmentSize (segmentSize),
98 m_ssThresh (ssThresh),
99 m_rtt (rtt),
100 m_segmentsAcked (segmentsAcked),
101 m_nextTxSeq (nextTxSeq),
102 m_lastAckedSeq (lastAckedSeq)
103{
104}
105
106void
108{
109 m_state = CreateObject<TcpSocketState> ();
110
117
118 Ptr<TcpVegas> cong = CreateObject <TcpVegas> ();
119
120 // Set baseRtt to 100 ms
121 cong->PktsAcked (m_state, m_segmentsAcked, MilliSeconds (100));
122
123 // Re-set Vegas to assign a new value of minRtt
124 cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
125 cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
126
127 // 2 more calls to PktsAcked to increment cntRtt beyond 2
128 cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
129 cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
130
131 // Update cwnd using Vegas algorithm
132 cong->IncreaseWindow (m_state, m_segmentsAcked);
133
134 // Our calculation of cwnd
135 IncreaseWindow (cong);
136
138 "CWnd has not updated correctly");
140 "SsThresh has not updated correctly");
141}
142
143void
145{
146 Time baseRtt = MilliSeconds (100);
147 uint32_t segCwnd = m_cWnd / m_segmentSize;
148
149 // Calculate expected throughput
150 uint64_t expectedCwnd;
151 expectedCwnd = (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, beta, gamma;
159 cong->GetAttribute ("Alpha", alpha);
160 cong->GetAttribute ("Beta", beta);
161 cong->GetAttribute ("Gamma", gamma);
162
163 if (diff > gamma.Get () && (m_cWnd < m_ssThresh))
164 { // Change from slow-start to linear increase/decrease mode
165 segCwnd = std::min (segCwnd, (uint32_t) expectedCwnd + 1);
166 m_cWnd = segCwnd * m_segmentSize;
167 GetSsThresh (cong);
168 }
169 else if (m_cWnd < m_ssThresh)
170 { // Execute Reno slow start
171 if (m_segmentsAcked >= 1)
172 {
175 }
176 }
177 else
178 { // Linear increase/decrease mode
179 if (diff > beta.Get ())
180 {
181 m_cWnd = (segCwnd - 1) * m_segmentSize;
182 GetSsThresh (cong);
183 }
184 else if (diff < alpha.Get ())
185 {
186 m_cWnd = (segCwnd + 1) * m_segmentSize;
187 }
188 else
189 {
190 }
191 }
193}
194
195void
197{
199}
200
201
209{
210public:
211 TcpVegasTestSuite () : TestSuite ("tcp-vegas-test", UNIT)
212 {
213 AddTestCase (new TcpVegasTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (106), 1, SequenceNumber32 (2893), SequenceNumber32 (5785),
214 "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
215 TestCase::QUICK);
216 AddTestCase (new TcpVegasTest (5 * 536, 536, 10 * 536, MilliSeconds (118), 1, SequenceNumber32 (3216), SequenceNumber32 (3753),
217 "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
218 TestCase::QUICK);
219 AddTestCase (new TcpVegasTest (60 * 346, 346, 40 * 346, MilliSeconds (206), 1, SequenceNumber32 (20761), SequenceNumber32 (21107),
220 "Vegas test on cWnd and ssThresh when diff > beta"),
221 TestCase::QUICK);
222 AddTestCase (new TcpVegasTest (15 * 1446, 1446, 10 * 1446, MilliSeconds (106), 1, SequenceNumber32 (21691), SequenceNumber32 (24583),
223 "Vegas test on cWnd and ssThresh when diff < alpha"),
224 TestCase::QUICK);
225 AddTestCase (new TcpVegasTest (20 * 746, 746, 10 * 746, MilliSeconds (109), 1, SequenceNumber32 (14921), SequenceNumber32 (15667),
226 "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
227 TestCase::QUICK);
228 }
229};
230
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
TcpVegas congestion control algorithm test.
virtual void DoRun(void)
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:74
uint32_t m_segmentSize
Segment size.
Time m_minRtt
Minimum RTT observed throughout the connection.
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
Hold an unsigned integer type.
Definition: uinteger.h:44
uint64_t Get(void) const
Definition: uinteger.cc:35
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:141
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
float alpha
Plot alpha value (transparency)
static TcpVegasTestSuite g_tcpVegasTest
Static variable for test initialization.