A Discrete-Event Network Simulator
API
tcp-bbr-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 NITK Surathkal
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  * Authors: Vivek Jain <jain.vivek.anand@gmail.com>
19  * Viyom Mittal <viyommittal@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  *
22  */
23 
24 #include "ns3/test.h"
25 #include "ns3/log.h"
26 #include "ns3/tcp-congestion-ops.h"
27 #include "ns3/tcp-socket-base.h"
28 #include "ns3/tcp-bbr.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("TcpBbrTestSuite");
33 
38 {
39 public:
45  TcpBbrPacingEnableTest (bool pacing, const std::string &name);
46 
47 private:
48  virtual void DoRun (void);
52  void ExecuteTest (void);
53  bool m_pacing;
54 };
55 
56 TcpBbrPacingEnableTest::TcpBbrPacingEnableTest (bool pacing, const std::string &name)
57  : TestCase (name),
58  m_pacing (pacing)
59 {}
60 
61 void
63 {
65  Simulator::Run ();
67 }
68 
69 void
71 {
72  Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
73  state->m_pacing = m_pacing;
74 
75  Ptr<TcpBbr> cong = CreateObject <TcpBbr> ();
76 
77  cong->CongestionStateSet (state, TcpSocketState::CA_OPEN);
78 
79  NS_TEST_ASSERT_MSG_EQ (state->m_pacing, true,
80  "BBR has not updated pacing value");
81 }
82 
87 {
88 public:
95  TcpBbrCheckGainValuesTest (TcpBbr::BbrMode_t state, double highGain, const std::string &name);
96 
97 private:
98  virtual void DoRun (void);
102  void ExecuteTest (void);
104  double m_highGain;
105 };
106 
108  double highGain, const std::string &name)
109  : TestCase (name),
110  m_mode (state),
111  m_highGain (highGain)
112 {}
113 
114 void
116 {
118  Simulator::Run ();
120 }
121 
122 void
124 {
125  Ptr<TcpBbr> cong = CreateObject <TcpBbr> ();
126  cong->SetAttribute ("HighGain", DoubleValue (m_highGain));
127  double actualPacingGain, actualCwndGain, desiredPacingGain = m_highGain, desiredCwndGain = m_highGain;
129  switch (m_mode)
130  {
131  case TcpBbr::BBR_STARTUP:
132  cong->EnterStartup ();
133  desiredPacingGain = m_highGain;
134  desiredCwndGain = m_highGain;
135  actualPacingGain = cong->GetPacingGain ();
136  actualCwndGain = cong->GetCwndGain ();
137  desiredMode = TcpBbr::BBR_STARTUP;
138  break;
139  case TcpBbr::BBR_DRAIN:
140  cong->EnterDrain ();
141  desiredPacingGain = 1 / m_highGain;
142  desiredCwndGain = m_highGain;
143  desiredMode = TcpBbr::BBR_DRAIN;
144  break;
146  cong->EnterProbeBW ();
147  // The value of desiredPacingGain is sensitive to the setting of random
148  // variable stream. The value of 1.25 has been used in this test with a
149  // stream value of 4 (default for TCP BBR). Note that if the stream value
150  // is changed, this test might fail because when BBR enters the PROBE_BW
151  // phase, the value of actualPacingGain is chosen randomly from 1.25,
152  // 0.75, 1, 1, 1, 1, 1, 1.
153  desiredPacingGain = 1.25;
154  desiredCwndGain = 2;
155  desiredMode = TcpBbr::BBR_PROBE_BW;
156  break;
158  cong->EnterProbeRTT ();
159  desiredPacingGain = 1;
160  desiredCwndGain = 1;
161  desiredMode = TcpBbr::BBR_PROBE_RTT;
162  break;
163  default:
164  NS_ASSERT (false);
165  }
166 
167  actualPacingGain = cong->GetPacingGain ();
168  actualCwndGain = cong->GetCwndGain ();
169  NS_TEST_ASSERT_MSG_EQ (m_mode, desiredMode, "BBR has not entered into desired state");
170  NS_TEST_ASSERT_MSG_EQ (actualPacingGain, desiredPacingGain, "BBR has not updated into desired pacing gain");
171  NS_TEST_ASSERT_MSG_EQ (actualCwndGain, desiredCwndGain, "BBR has not updated into desired cwnd gain");
172 }
173 
181 {
182 public:
186  TcpBbrTestSuite () : TestSuite ("tcp-bbr-test", UNIT)
187  {
188  AddTestCase (new TcpBbrPacingEnableTest (true, "BBR must keep pacing feature on"), TestCase::QUICK);
189 
190  AddTestCase (new TcpBbrPacingEnableTest (false, "BBR must turn on pacing feature"), TestCase::QUICK);
191 
192  AddTestCase (new TcpBbrCheckGainValuesTest (TcpBbr::BBR_STARTUP, 4, "BBR should enter to STARTUP phase and set cwnd and pacing gain accordingly"), TestCase::QUICK);
193 
194  AddTestCase (new TcpBbrCheckGainValuesTest (TcpBbr::BBR_DRAIN, 4, "BBR should enter to DRAIN phase and set cwnd and pacing gain accordingly"), TestCase::QUICK);
195 
196  AddTestCase (new TcpBbrCheckGainValuesTest (TcpBbr::BBR_PROBE_BW, 4, "BBR should enter to BBR_PROBE_BW phase and set cwnd and pacing gain accordingly"), TestCase::QUICK);
197 
198  AddTestCase (new TcpBbrCheckGainValuesTest (TcpBbr::BBR_PROBE_RTT, 4, "BBR should enter to BBR_PROBE_RTT phase and set cwnd and pacing gain accordingly"), TestCase::QUICK);
199  }
200 };
201 
203 }
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
Definition: tcp-bbr-test.cc:87
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void ExecuteTest(void)
Execute the test.
BbrMode_t
BBR has the following 4 modes for deciding how fast to send:
Definition: tcp-bbr.h:78
@ BBR_PROBE_RTT
Cut inflight to min to probe min_rtt.
Definition: tcp-bbr.h:82
@ BBR_DRAIN
Drain any queue created during startup.
Definition: tcp-bbr.h:80
@ BBR_STARTUP
Ramp up sending rate rapidly to fill pipe.
Definition: tcp-bbr.h:79
@ BBR_PROBE_BW
Discover, share bw: pace around estimated bw.
Definition: tcp-bbr.h:81
Testing whether BBR enables pacing.
Definition: tcp-bbr-test.cc:38
void ExecuteTest(void)
Execute the test.
Definition: tcp-bbr-test.cc:70
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
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-bbr-test.cc:62
TCP BBR TestSuite.
TcpBbrTestSuite()
constructor
bool m_pacing
Pacing status.
@ CA_OPEN
Normal state, no dubious events.
encapsulates test code
Definition: test.h:994
@ QUICK
Fast test.
Definition: test.h:999
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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#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 Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpBbrTestSuite g_tcpBbrTest
static variable for test initialization