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
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpHyblaTestSuite");
28
36{
37 public:
47 uint32_t ssThresh,
49 const Time& rtt,
50 const std::string& name);
51
52 private:
53 void DoRun() override;
54
60 void RhoUpdated(double oldVal, double newVal);
61
66 double m_rho;
68};
69
71 uint32_t ssThresh,
73 const Time& rtt,
74 const std::string& name)
75 : TestCase(name),
76 m_cWnd(cWnd),
77 m_ssThresh(ssThresh),
78 m_segmentSize(segmentSize),
79 m_rtt(rtt),
80 m_rho(0)
81{
82}
83
84void
85TcpHyblaIncrementTest::RhoUpdated(double /* oldVal */, double newVal)
86{
87 m_rho = newVal;
88}
89
90void
92{
93 m_state = CreateObject<TcpSocketState>();
94
99
100 Ptr<TcpHybla> cong = CreateObject<TcpHybla>();
101
102 cong->TraceConnectWithoutContext("Rho", MakeCallback(&TcpHyblaIncrementTest::RhoUpdated, this));
103
104 // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
105 // to ACK at least segCwnd/coeffA ACK.
106
107 TimeValue rRtt;
108 cong->GetAttribute("RRTT", rRtt);
109 cong->PktsAcked(m_state, 1, m_rtt);
110
111 double calcRho = std::max(m_rtt.GetSeconds() / rRtt.Get().GetSeconds(), 1.0);
112
113 NS_TEST_ASSERT_MSG_NE(m_rho, 0.0, "Rho never updated by implementation");
115 m_rho,
116 0.01,
117 "Different rho values between implementation and test");
118
119 cong->IncreaseWindow(m_state, 1);
120
121 if (m_cWnd <= m_ssThresh)
122 {
123 // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
124 double inc = std::pow(2, calcRho) - 1.0;
125 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
128 "Congestion window has gone too far");
130 cWndExpected,
131 "Congestion window different than expected");
132 }
133 else
134 {
135 // We expect an increment of rho^2 / cWnd
136 uint32_t segCwnd = m_cWnd / m_segmentSize;
137 double inc = std::pow(m_rho, 2) / ((double)segCwnd);
138 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
139
140 if (inc >= 1.0)
141 {
142 // LT because implementation does not add value less than MSS.
144 cWndExpected,
145 "Congestion window different than expected");
146 }
147 }
148}
149
157{
158 public:
160 : TestSuite("tcp-hybla-test", UNIT)
161 {
163 0xFFFFFFFF,
164 500,
165 MilliSeconds(55),
166 "Rho=1.1, slow start"),
167 TestCase::QUICK);
169 0xFFFFFFFF,
170 500,
171 MilliSeconds(100),
172 "Rho=2, slow start"),
173 TestCase::QUICK);
175 0xFFFFFFFF,
176 500,
177 MilliSeconds(750),
178 "Rho=30, slow start"),
179 TestCase::QUICK);
180 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.55), "Rho=1.1, cong avoid"),
181 TestCase::QUICK);
182 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.1), "Rho=2, cong avoid"),
183 TestCase::QUICK);
184 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.75), "Rho=30, cong avoid"),
185 TestCase::QUICK);
186 }
187};
188
#define max(a, b)
Definition: 80211b.c:43
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:305
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:402
AttributeValue implementation for Time.
Definition: nstime.h:1425
Time Get() const
Definition: time.cc:532
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:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
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:691
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.