A Discrete-Event Network Simulator
API
tcp-hybla-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-hybla.h"
22 #include "ns3/tcp-socket-base.h"
23 #include "ns3/test.h"
24 
25 using namespace ns3;
26 
27 NS_LOG_COMPONENT_DEFINE("TcpHyblaTestSuite");
28 
35 {
36  public:
45  TcpHyblaIncrementTest(uint32_t cWnd,
46  uint32_t ssThresh,
47  uint32_t segmentSize,
48  const Time& rtt,
49  const std::string& name);
50 
51  private:
52  void DoRun() override;
53 
59  void RhoUpdated(double oldVal, double newVal);
60 
61  uint32_t m_cWnd;
62  uint32_t m_ssThresh;
63  uint32_t m_segmentSize;
65  double m_rho;
67 };
68 
70  uint32_t ssThresh,
71  uint32_t segmentSize,
72  const Time& rtt,
73  const std::string& name)
74  : TestCase(name),
75  m_cWnd(cWnd),
76  m_ssThresh(ssThresh),
77  m_segmentSize(segmentSize),
78  m_rtt(rtt),
79  m_rho(0)
80 {
81 }
82 
83 void
84 TcpHyblaIncrementTest::RhoUpdated(double /* oldVal */, double newVal)
85 {
86  m_rho = newVal;
87 }
88 
89 void
91 {
92  m_state = CreateObject<TcpSocketState>();
93 
98 
99  Ptr<TcpHybla> cong = CreateObject<TcpHybla>();
100 
101  cong->TraceConnectWithoutContext("Rho", MakeCallback(&TcpHyblaIncrementTest::RhoUpdated, this));
102 
103  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
104  // to ACK at least segCwnd/coeffA ACK.
105 
106  TimeValue rRtt;
107  cong->GetAttribute("RRTT", rRtt);
108  cong->PktsAcked(m_state, 1, m_rtt);
109 
110  double calcRho = std::max(m_rtt.GetSeconds() / rRtt.Get().GetSeconds(), 1.0);
111 
112  NS_TEST_ASSERT_MSG_NE(m_rho, 0.0, "Rho never updated by implementation");
114  m_rho,
115  0.01,
116  "Different rho values between implementation and test");
117 
118  cong->IncreaseWindow(m_state, 1);
119 
120  if (m_cWnd <= m_ssThresh)
121  {
122  // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
123  double inc = std::pow(2, calcRho) - 1.0;
124  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
127  "Congestion window has gone too far");
129  cWndExpected,
130  "Congestion window different than expected");
131  }
132  else
133  {
134  // We expect an increment of rho^2 / cWnd
135  uint32_t segCwnd = m_cWnd / m_segmentSize;
136  double inc = std::pow(m_rho, 2) / ((double)segCwnd);
137  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
138 
139  if (inc >= 1.0)
140  {
141  // LT because implementation does not add value less than MSS.
143  cWndExpected,
144  "Congestion window different than expected");
145  }
146  }
147 }
148 
155 {
156  public:
158  : TestSuite("tcp-hybla-test", UNIT)
159  {
161  0xFFFFFFFF,
162  500,
163  MilliSeconds(55),
164  "Rho=1.1, slow start"),
165  TestCase::QUICK);
167  0xFFFFFFFF,
168  500,
169  MilliSeconds(100),
170  "Rho=2, slow start"),
171  TestCase::QUICK);
173  0xFFFFFFFF,
174  500,
175  MilliSeconds(750),
176  "Rho=30, slow start"),
177  TestCase::QUICK);
178  AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.55), "Rho=1.1, cong avoid"),
179  TestCase::QUICK);
180  AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.1), "Rho=2, cong avoid"),
181  TestCase::QUICK);
182  AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.75), "Rho=30, cong avoid"),
183  TestCase::QUICK);
184  }
185 };
186 
#define max(a, b)
Definition: 80211b.c:42
Testing the congestion avoidance increment on TcpHybla.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_cWnd
Congestion window.
uint32_t m_segmentSize
Segment size.
uint32_t m_ssThresh
Slow Start Threshold.
Ptr< TcpSocketState > m_state
TCP socket state.
void RhoUpdated(double oldVal, double newVal)
Tracks TCP Hybla rho parameter changes.
Time m_rtt
Round trip time.
double m_rho
TCP Hybla rho parameter.
TcpHyblaIncrementTest(uint32_t cWnd, uint32_t ssThresh, uint32_t segmentSize, const Time &rtt, const std::string &name)
Constructor.
TCP Hybla TestSuite.
uint32_t m_segmentSize
Segment size.
Time m_minRtt
Minimum RTT observed throughout the connection.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
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:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
Time Get() const
Definition: time.cc:530
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:144
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition: test.h:564
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:337
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Definition: test.h:750
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.