A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-bbr-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 NITK Surathkal
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: Vivek Jain <jain.vivek.anand@gmail.com>
18 * Viyom Mittal <viyommittal@gmail.com>
19 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
20 *
21 */
22
23#include "ns3/log.h"
24#include "ns3/tcp-bbr.h"
25#include "ns3/tcp-congestion-ops.h"
26#include "ns3/tcp-socket-base.h"
27#include "ns3/test.h"
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("TcpBbrTestSuite");
33
34/**
35 * \brief Testing whether BBR enables pacing
36 */
38{
39 public:
40 /**
41 * \brief constructor
42 * \param pacing pacing configuration
43 * \param name description of the test
44 */
45 TcpBbrPacingEnableTest(bool pacing, const std::string& name);
46
47 private:
48 void DoRun() override;
49 /**
50 * \brief Execute the test.
51 */
52 void ExecuteTest();
53 bool m_pacing; //!< Initial pacing configuration.
54};
55
56TcpBbrPacingEnableTest::TcpBbrPacingEnableTest(bool pacing, const std::string& name)
57 : TestCase(name),
58 m_pacing(pacing)
59{
60}
61
62void
64{
68}
69
70void
72{
73 Ptr<TcpSocketState> state = CreateObject<TcpSocketState>();
74 state->m_pacing = m_pacing;
75
76 Ptr<TcpBbr> cong = CreateObject<TcpBbr>();
77
78 cong->CongestionStateSet(state, TcpSocketState::CA_OPEN);
79
80 NS_TEST_ASSERT_MSG_EQ(state->m_pacing, true, "BBR has not updated pacing value");
81}
82
83/**
84 * \brief Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
85 */
87{
88 public:
89 /**
90 * \brief constructor
91 * \param state BBR state/mode under test
92 * \param highGain value of pacing and cwnd gain
93 * \param name description of the test
94 */
95 TcpBbrCheckGainValuesTest(TcpBbr::BbrMode_t state, double highGain, const std::string& name);
96
97 private:
98 void DoRun() override;
99 /**
100 * \brief Execute the test.
101 */
102 void ExecuteTest();
103 TcpBbr::BbrMode_t m_mode; //!< BBR mode under test
104 double m_highGain; //!< Value of BBR high gain
105};
106
108 double highGain,
109 const std::string& name)
110 : TestCase(name),
111 m_mode(state),
112 m_highGain(highGain)
113{
114}
115
116void
118{
122}
123
124void
126{
127 Ptr<TcpBbr> cong = CreateObject<TcpBbr>();
128 cong->SetAttribute("HighGain", DoubleValue(m_highGain));
129 double actualPacingGain;
130 double actualCwndGain;
131 double desiredPacingGain = m_highGain;
132 double desiredCwndGain = m_highGain;
134 switch (m_mode)
135 {
137 cong->EnterStartup();
138 desiredPacingGain = m_highGain;
139 desiredCwndGain = m_highGain;
140 actualPacingGain = cong->GetPacingGain();
141 actualCwndGain = cong->GetCwndGain();
142 desiredMode = TcpBbr::BBR_STARTUP;
143 break;
145 cong->EnterDrain();
146 desiredPacingGain = 1 / m_highGain;
147 desiredCwndGain = m_highGain;
148 desiredMode = TcpBbr::BBR_DRAIN;
149 break;
151 cong->EnterProbeBW();
152 // The value of desiredPacingGain is sensitive to the setting of random
153 // variable stream. The value of 1.25 has been used in this test with a
154 // stream value of 4 (default for TCP BBR). Note that if the stream value
155 // is changed, this test might fail because when BBR enters the PROBE_BW
156 // phase, the value of actualPacingGain is chosen randomly from 1.25,
157 // 0.75, 1, 1, 1, 1, 1, 1.
158 desiredPacingGain = 1.25;
159 desiredCwndGain = 2;
160 desiredMode = TcpBbr::BBR_PROBE_BW;
161 break;
163 cong->EnterProbeRTT();
164 desiredPacingGain = 1;
165 desiredCwndGain = 1;
166 desiredMode = TcpBbr::BBR_PROBE_RTT;
167 break;
168 default:
169 NS_ASSERT(false);
170 }
171
172 actualPacingGain = cong->GetPacingGain();
173 actualCwndGain = cong->GetCwndGain();
174 NS_TEST_ASSERT_MSG_EQ(m_mode, desiredMode, "BBR has not entered into desired state");
175 NS_TEST_ASSERT_MSG_EQ(actualPacingGain,
176 desiredPacingGain,
177 "BBR has not updated into desired pacing gain");
178 NS_TEST_ASSERT_MSG_EQ(actualCwndGain,
179 desiredCwndGain,
180 "BBR has not updated into desired cwnd gain");
181}
182
183/**
184 * \ingroup internet-test
185 *
186 * \brief TCP BBR TestSuite
187 */
189{
190 public:
191 /**
192 * \brief constructor
193 */
195 : TestSuite("tcp-bbr-test", Type::UNIT)
196 {
197 AddTestCase(new TcpBbrPacingEnableTest(true, "BBR must keep pacing feature on"),
199
200 AddTestCase(new TcpBbrPacingEnableTest(false, "BBR must turn on pacing feature"),
202
206 4,
207 "BBR should enter to STARTUP phase and set cwnd and pacing gain accordingly"),
209
212 4,
213 "BBR should enter to DRAIN phase and set cwnd and pacing gain accordingly"),
215
219 4,
220 "BBR should enter to BBR_PROBE_BW phase and set cwnd and pacing gain accordingly"),
222
226 4,
227 "BBR should enter to BBR_PROBE_RTT phase and set cwnd and pacing gain accordingly"),
229 }
230};
231
232static TcpBbrTestSuite g_tcpBbrTest; //!< static variable for test initialization
233} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
Definition: tcp-bbr-test.cc:87
void DoRun() override
Implementation to actually run this TestCase.
TcpBbrCheckGainValuesTest(TcpBbr::BbrMode_t state, double highGain, const std::string &name)
constructor
TcpBbr::BbrMode_t m_mode
BBR mode under test.
double m_highGain
Value of BBR high gain.
void ExecuteTest()
Execute the test.
BbrMode_t
BBR has the following 4 modes for deciding how fast to send:
Definition: tcp-bbr.h:79
@ BBR_PROBE_RTT
Cut inflight to min to probe min_rtt.
Definition: tcp-bbr.h:83
@ BBR_DRAIN
Drain any queue created during startup.
Definition: tcp-bbr.h:81
@ BBR_STARTUP
Ramp up sending rate rapidly to fill pipe.
Definition: tcp-bbr.h:80
@ BBR_PROBE_BW
Discover, share bw: pace around estimated bw.
Definition: tcp-bbr.h:82
Testing whether BBR enables pacing.
Definition: tcp-bbr-test.cc:38
TcpBbrPacingEnableTest(bool pacing, const std::string &name)
constructor
Definition: tcp-bbr-test.cc:56
bool m_pacing
Initial pacing configuration.
Definition: tcp-bbr-test.cc:53
void DoRun() override
Implementation to actually run this TestCase.
Definition: tcp-bbr-test.cc:63
void ExecuteTest()
Execute the test.
Definition: tcp-bbr-test.cc:71
TCP BBR TestSuite.
TcpBbrTestSuite()
constructor
@ CA_OPEN
Normal state, no dubious events.
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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBbrTestSuite g_tcpBbrTest
static variable for test initialization