A Discrete-Event Network Simulator
API
tcp-scalable-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 * Authors: 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
27#include "ns3/log.h"
28#include "ns3/tcp-congestion-ops.h"
29#include "ns3/tcp-scalable.h"
30#include "ns3/tcp-socket-base.h"
31#include "ns3/test.h"
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE("TcpScalableTestSuite");
36
44{
45 public:
55 uint32_t segmentsAcked,
56 const std::string& name);
57
58 private:
59 void DoRun() override;
60
65};
66
69 uint32_t segmentsAcked,
70 const std::string& name)
71 : TestCase(name),
72 m_cWnd(cWnd),
73 m_segmentSize(segmentSize),
74 m_segmentsAcked(segmentsAcked)
75{
76}
77
78void
80{
81 m_state = CreateObject<TcpSocketState>();
82
85
86 Ptr<TcpScalable> cong = CreateObject<TcpScalable>();
87
88 uint32_t segCwnd = m_cWnd / m_segmentSize;
89
90 // Get default value of additive increase factor
91 UintegerValue aiFactor;
92 cong->GetAttribute("AIFactor", aiFactor);
93
94 // To see an increase of 1 MSS, the number of segments ACKed has to be at least
95 // min (segCwnd, aiFactor).
96
97 uint32_t w = std::min(segCwnd, (uint32_t)aiFactor.Get());
98 uint32_t delta = m_segmentsAcked / w;
99
100 cong->IncreaseWindow(m_state, m_segmentsAcked);
101
103 m_cWnd + delta * m_segmentSize,
104 "CWnd has not increased");
105}
106
114{
115 public:
122 TcpScalableDecrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string& name);
123
124 private:
125 void DoRun() override;
126
130};
131
134 const std::string& name)
135 : TestCase(name),
136 m_cWnd(cWnd),
137 m_segmentSize(segmentSize)
138{
139}
140
141void
143{
144 m_state = CreateObject<TcpSocketState>();
145
148
149 Ptr<TcpScalable> cong = CreateObject<TcpScalable>();
150
151 uint32_t segCwnd = m_cWnd / m_segmentSize;
152
153 // Get default value of multiplicative decrease factor
154 DoubleValue mdFactor;
155 cong->GetAttribute("MDFactor", mdFactor);
156
157 double b = 1.0 - mdFactor.Get();
158
159 uint32_t ssThresh = std::max(2.0, segCwnd * b);
160
161 uint32_t ssThreshInSegments = cong->GetSsThresh(m_state, m_state->m_cWnd) / m_segmentSize;
162
163 NS_TEST_ASSERT_MSG_EQ(ssThreshInSegments, ssThresh, "Scalable decrement fn not used");
164}
165
173{
174 public:
176 : TestSuite("tcp-scalable-test", UNIT)
177 {
180 38 * 536,
181 536,
182 38,
183 "Scalable increment test on cWnd = 38 segments and segmentSize = 536 bytes"),
184 TestCase::QUICK);
186 38,
187 1,
188 100,
189 "Scalable increment test on cWnd = 38 segments and segmentSize = 1 byte"),
190 TestCase::QUICK);
193 53 * 1446,
194 1446,
195 50,
196 "Scalable increment test on cWnd = 53 segments and segmentSize = 1446 bytes"),
197 TestCase::QUICK);
198
200 38,
201 1,
202 "Scalable decrement test on cWnd = 38 segments and segmentSize = 1 byte"),
203 TestCase::QUICK);
206 100 * 536,
207 536,
208 "Scalable decrement test on cWnd = 100 segments and segmentSize = 536 bytes"),
209 TestCase::QUICK);
212 40 * 1446,
213 1446,
214 "Scalable decrement test on cWnd = 40 segments and segmentSize = 1446 bytes"),
215 TestCase::QUICK);
216 }
217};
218
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Testing the multiplicative decrease on TcpScalable.
uint32_t m_segmentSize
Segment size.
Ptr< TcpSocketState > m_state
TCP socket state.
TcpScalableDecrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string &name)
Constructor.
uint32_t m_cWnd
Congestion window.
void DoRun() override
Implementation to actually run this TestCase.
Testing the congestion avoidance increment on TcpScalable.
TcpScalableIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, const std::string &name)
Constructor.
uint32_t m_segmentSize
Segment size.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentsAcked
Segments ACKed.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_cWnd
Congestion window.
TcpScalable TestSuite.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double Get() const
Definition: double.cc:37
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
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
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpScalableTestSuite g_tcpScalableTest
Static variable for test initialization.