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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Vivek Jain <jain.vivek.anand@gmail.com>
7 * Viyom Mittal <viyommittal@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 *
10 */
11
12#include "ns3/log.h"
13#include "ns3/tcp-bbr.h"
14#include "ns3/tcp-congestion-ops.h"
15#include "ns3/tcp-socket-base.h"
16#include "ns3/test.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("TcpBbrTestSuite");
22
23/**
24 * @brief Testing whether BBR enables pacing
25 */
27{
28 public:
29 /**
30 * @brief constructor
31 * @param pacing pacing configuration
32 * @param name description of the test
33 */
34 TcpBbrPacingEnableTest(bool pacing, const std::string& name);
35
36 private:
37 void DoRun() override;
38 /**
39 * @brief Execute the test.
40 */
41 void ExecuteTest();
42 bool m_pacing; //!< Initial pacing configuration.
43};
44
45TcpBbrPacingEnableTest::TcpBbrPacingEnableTest(bool pacing, const std::string& name)
46 : TestCase(name),
47 m_pacing(pacing)
48{
49}
50
51void
58
59void
61{
63 state->m_pacing = m_pacing;
64
66
67 cong->CongestionStateSet(state, TcpSocketState::CA_OPEN);
68
69 NS_TEST_ASSERT_MSG_EQ(state->m_pacing, true, "BBR has not updated pacing value");
70}
71
72/**
73 * @brief Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
74 */
76{
77 public:
78 /**
79 * @brief constructor
80 * @param state BBR state/mode under test
81 * @param highGain value of pacing and cwnd gain
82 * @param name description of the test
83 */
84 TcpBbrCheckGainValuesTest(TcpBbr::BbrMode_t state, double highGain, const std::string& name);
85
86 private:
87 void DoRun() override;
88 /**
89 * @brief Execute the test.
90 */
91 void ExecuteTest();
92 TcpBbr::BbrMode_t m_mode; //!< BBR mode under test
93 double m_highGain; //!< Value of BBR high gain
94};
95
97 double highGain,
98 const std::string& name)
99 : TestCase(name),
100 m_mode(state),
101 m_highGain(highGain)
102{
103}
104
105void
112
113void
115{
117 cong->SetAttribute("HighGain", DoubleValue(m_highGain));
118 double actualPacingGain;
119 double actualCwndGain;
120 double desiredPacingGain = m_highGain;
121 double desiredCwndGain = m_highGain;
123 switch (m_mode)
124 {
126 cong->EnterStartup();
127 desiredPacingGain = m_highGain;
128 desiredCwndGain = m_highGain;
129 actualPacingGain = cong->GetPacingGain();
130 actualCwndGain = cong->GetCwndGain();
131 desiredMode = TcpBbr::BBR_STARTUP;
132 break;
134 cong->EnterDrain();
135 desiredPacingGain = 1 / m_highGain;
136 desiredCwndGain = m_highGain;
137 desiredMode = TcpBbr::BBR_DRAIN;
138 break;
140 cong->EnterProbeBW();
141 // The value of desiredPacingGain is sensitive to the setting of random
142 // variable stream. The value of 1.25 has been used in this test with a
143 // stream value of 4 (default for TCP BBR). Note that if the stream value
144 // is changed, this test might fail because when BBR enters the PROBE_BW
145 // phase, the value of actualPacingGain is chosen randomly from 1.25,
146 // 0.75, 1, 1, 1, 1, 1, 1.
147 desiredPacingGain = 1.25;
148 desiredCwndGain = 2;
149 desiredMode = TcpBbr::BBR_PROBE_BW;
150 break;
152 cong->EnterProbeRTT();
153 desiredPacingGain = 1;
154 desiredCwndGain = 1;
155 desiredMode = TcpBbr::BBR_PROBE_RTT;
156 break;
157 default:
158 NS_ASSERT(false);
159 }
160
161 actualPacingGain = cong->GetPacingGain();
162 actualCwndGain = cong->GetCwndGain();
163 NS_TEST_ASSERT_MSG_EQ(m_mode, desiredMode, "BBR has not entered into desired state");
164 NS_TEST_ASSERT_MSG_EQ(actualPacingGain,
165 desiredPacingGain,
166 "BBR has not updated into desired pacing gain");
167 NS_TEST_ASSERT_MSG_EQ(actualCwndGain,
168 desiredCwndGain,
169 "BBR has not updated into desired cwnd gain");
170}
171
172/**
173 * @ingroup internet-test
174 *
175 * @brief TCP BBR TestSuite
176 */
178{
179 public:
180 /**
181 * @brief constructor
182 */
184 : TestSuite("tcp-bbr-test", Type::UNIT)
185 {
186 AddTestCase(new TcpBbrPacingEnableTest(true, "BBR must keep pacing feature on"),
188
189 AddTestCase(new TcpBbrPacingEnableTest(false, "BBR must turn on pacing feature"),
191
195 4,
196 "BBR should enter to STARTUP phase and set cwnd and pacing gain accordingly"),
198
201 4,
202 "BBR should enter to DRAIN phase and set cwnd and pacing gain accordingly"),
204
208 4,
209 "BBR should enter to BBR_PROBE_BW phase and set cwnd and pacing gain accordingly"),
211
215 4,
216 "BBR should enter to BBR_PROBE_RTT phase and set cwnd and pacing gain accordingly"),
218 }
219};
220
221static TcpBbrTestSuite g_tcpBbrTest; //!< static variable for test initialization
222} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
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:68
@ BBR_PROBE_RTT
Cut inflight to min to probe min_rtt.
Definition tcp-bbr.h:72
@ BBR_DRAIN
Drain any queue created during startup.
Definition tcp-bbr.h:70
@ BBR_STARTUP
Ramp up sending rate rapidly to fill pipe.
Definition tcp-bbr.h:69
@ BBR_PROBE_BW
Discover, share bw: pace around estimated bw.
Definition tcp-bbr.h:71
Testing whether BBR enables pacing.
TcpBbrPacingEnableTest(bool pacing, const std::string &name)
constructor
bool m_pacing
Initial pacing configuration.
void DoRun() override
Implementation to actually run this TestCase.
void ExecuteTest()
Execute the test.
TCP BBR TestSuite.
TcpBbrTestSuite()
constructor
@ CA_OPEN
Normal state, no dubious events.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBbrTestSuite g_tcpBbrTest
static variable for test initialization