A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-highspeed-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
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 */
18
19#include "ns3/log.h"
20#include "ns3/tcp-congestion-ops.h"
21#include "ns3/tcp-highspeed.h"
22#include "ns3/tcp-socket-base.h"
23#include "ns3/test.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpHighSpeedTestSuite");
28
29/**
30 * \ingroup internet-test
31 *
32 * \brief Testing the congestion avoidance increment on TcpHighSpeed
33 */
35{
36 public:
37 /**
38 * \brief Constructor.
39 * \param cWnd Congestion window.
40 * \param segmentSize Segment size.
41 * \param name Test description.
42 */
43 TcpHighSpeedIncrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string& name);
44
45 private:
46 void DoRun() override;
47
48 uint32_t m_cWnd; //!< Congestion window.
49 uint32_t m_segmentSize; //!< Segment size.
50 Ptr<TcpSocketState> m_state; //!< TCP socket state.
51};
52
55 const std::string& name)
56 : TestCase(name),
57 m_cWnd(cWnd),
58 m_segmentSize(segmentSize)
59{
60}
61
62void
64{
65 m_state = CreateObject<TcpSocketState>();
66
69
70 Ptr<TcpHighSpeed> cong = CreateObject<TcpHighSpeed>();
71
72 uint32_t segCwnd = m_cWnd / m_segmentSize;
73 uint32_t coeffA = TcpHighSpeed::TableLookupA(segCwnd);
74
75 // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
76 // to ACK at least segCwnd/coeffA ACK.
77
78 cong->IncreaseWindow(m_state, (segCwnd / coeffA) + 1);
79
80 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd + m_segmentSize, "CWnd has not increased");
81}
82
83/**
84 * \ingroup internet-test
85 *
86 * \brief Testing the congestion avoidance decrement on TcpHighSpeed
87 */
89{
90 public:
91 /**
92 * \brief Constructor.
93 * \param cWnd Congestion window.
94 * \param segmentSize Segment size.
95 * \param name Test description.
96 */
97 TcpHighSpeedDecrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string& name);
98
99 private:
100 void DoRun() override;
101
102 uint32_t m_cWnd; //!< Congestion window.
103 uint32_t m_segmentSize; //!< Segment size.
104 Ptr<TcpSocketState> m_state; //!< TCP socket state.
105};
106
109 const std::string& name)
110 : TestCase(name),
111 m_cWnd(cWnd),
112 m_segmentSize(segmentSize)
113{
114}
115
116void
118{
119 m_state = CreateObject<TcpSocketState>();
120
123
124 Ptr<TcpHighSpeed> cong = CreateObject<TcpHighSpeed>();
125
126 uint32_t segCwnd = m_cWnd / m_segmentSize;
127 double coeffB = 1.0 - TcpHighSpeed::TableLookupB(segCwnd);
128
129 uint32_t ret = cong->GetSsThresh(m_state, m_state->m_cWnd);
130
131 uint32_t ssThHS = std::max(2.0, segCwnd * coeffB);
132
133 NS_TEST_ASSERT_MSG_EQ(ret / m_segmentSize, ssThHS, "HighSpeed decrement fn not used");
134}
135
136/**
137 * \ingroup internet-test
138 *
139 * \brief TcpHighSpeed Congestion window values to test.
140 */
142{
143 unsigned int cwnd; //!< Congestion window.
144 unsigned int md; //!< Currently unused.
145};
146
147/// List of data to be tested
149 {38, 128, /* 0.50 */}, {118, 112, /* 0.44 */}, {221, 104, /* 0.41 */},
150 {347, 98, /* 0.38 */}, {495, 93, /* 0.37 */}, {663, 89, /* 0.35 */},
151 {851, 86, /* 0.34 */}, {1058, 83, /* 0.33 */}, {1284, 81, /* 0.32 */},
152 {1529, 78, /* 0.31 */}, {1793, 76, /* 0.30 */}, {2076, 74, /* 0.29 */},
153 {2378, 72, /* 0.28 */}, {2699, 71, /* 0.28 */}, {3039, 69, /* 0.27 */},
154 {3399, 68, /* 0.27 */}, {3778, 66, /* 0.26 */}, {4177, 65, /* 0.26 */},
155 {4596, 64, /* 0.25 */}, {5036, 62, /* 0.25 */}, {5497, 61, /* 0.24 */},
156 {5979, 60, /* 0.24 */}, {6483, 59, /* 0.23 */}, {7009, 58, /* 0.23 */},
157 {7558, 57, /* 0.22 */}, {8130, 56, /* 0.22 */}, {8726, 55, /* 0.22 */},
158 {9346, 54, /* 0.21 */}, {9991, 53, /* 0.21 */}, {10661, 52, /* 0.21 */},
159 {11358, 52, /* 0.20 */}, {12082, 51, /* 0.20 */}, {12834, 50, /* 0.20 */},
160 {13614, 49, /* 0.19 */}, {14424, 48, /* 0.19 */}, {15265, 48, /* 0.19 */},
161 {16137, 47, /* 0.19 */}, {17042, 46, /* 0.18 */}, {17981, 45, /* 0.18 */},
162 {18955, 45, /* 0.18 */}, {19965, 44, /* 0.17 */}, {21013, 43, /* 0.17 */},
163 {22101, 43, /* 0.17 */}, {23230, 42, /* 0.17 */}, {24402, 41, /* 0.16 */},
164 {25618, 41, /* 0.16 */}, {26881, 40, /* 0.16 */}, {28193, 39, /* 0.16 */},
165 {29557, 39, /* 0.15 */}, {30975, 38, /* 0.15 */}, {32450, 38, /* 0.15 */},
166 {33986, 37, /* 0.15 */}, {35586, 36, /* 0.14 */}, {37253, 36, /* 0.14 */},
167 {38992, 35, /* 0.14 */}, {40808, 35, /* 0.14 */}, {42707, 34, /* 0.13 */},
168 {44694, 33, /* 0.13 */}, {46776, 33, /* 0.13 */}, {48961, 32, /* 0.13 */},
169 {51258, 32, /* 0.13 */}, {53677, 31, /* 0.12 */}, {56230, 30, /* 0.12 */},
170 {58932, 30, /* 0.12 */}, {61799, 29, /* 0.12 */}, {64851, 28, /* 0.11 */},
171 {68113, 28, /* 0.11 */}, {71617, 27, /* 0.11 */}, {75401, 26, /* 0.10 */},
172 {79517, 26, /* 0.10 */}, {84035, 25, /* 0.10 */}, {89053, 24, /* 0.10 */},
173};
174
175#define HIGHSPEED_VALUES_N 71
176
177/**
178 * \ingroup internet-test
179 *
180 * \brief TCP HighSpeed TestSuite
181 */
183{
184 public:
186 : TestSuite("tcp-highspeed-test", Type::UNIT)
187 {
188 std::stringstream ss;
189
190 for (uint32_t i = 0; i < HIGHSPEED_VALUES_N; ++i)
191 {
195 1,
196 "Highspeed increment test on cWnd " + ss.str()),
197 TestCase::Duration::QUICK);
200 536,
201 "Highspeed increment test on cWnd " + ss.str()),
202 TestCase::Duration::QUICK);
205 1446,
206 "Highspeed increment test on cWnd " + ss.str()),
207 TestCase::Duration::QUICK);
210 1,
211 "Highspeed Decrement test on cWnd " + ss.str()),
212 TestCase::Duration::QUICK);
215 536,
216 "Highspeed Decrement test on cWnd " + ss.str()),
217 TestCase::Duration::QUICK);
220 1446,
221 "Highspeed Decrement test on cWnd " + ss.str()),
222 TestCase::Duration::QUICK);
223 ss.flush();
224 }
225 }
226};
227
228static TcpHighSpeedTestSuite g_tcpHighSpeedTest; //!< Static variable for test initialization
Testing the congestion avoidance decrement on TcpHighSpeed.
uint32_t m_segmentSize
Segment size.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_cWnd
Congestion window.
Ptr< TcpSocketState > m_state
TCP socket state.
TcpHighSpeedDecrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string &name)
Constructor.
Testing the congestion avoidance increment on TcpHighSpeed.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_cWnd
Congestion window.
TcpHighSpeedIncrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string &name)
Constructor.
TCP HighSpeed TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static double TableLookupB(uint32_t w)
Lookup table for the coefficient b (from RFC 3649)
static uint32_t TableLookupA(uint32_t w)
Lookup table for the coefficient a (from RFC 3649)
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
T Get() const
Get the underlying value.
Definition: traced-value.h:249
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:145
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TcpHighSpeed Congestion window values to test.
unsigned int cwnd
Congestion window.
unsigned int md
Currently unused.
static TcpHighSpeedTestSuite g_tcpHighSpeedTest
Static variable for test initialization.
static const HighSpeedImportantValues highSpeedImportantValues[]
List of data to be tested.
#define HIGHSPEED_VALUES_N