A Discrete-Event Network Simulator
API
tcp-hybla-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
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 */
19
20#include "ns3/test.h"
21#include "ns3/log.h"
22#include "ns3/tcp-congestion-ops.h"
23#include "ns3/tcp-socket-base.h"
24#include "ns3/tcp-hybla.h"
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE ("TcpHyblaTestSuite");
29
37{
38public:
48 uint32_t segmentSize, const Time& rtt,
49 const std::string &name);
50
51private:
52 virtual void DoRun (void);
53
59 void RhoUpdated (double oldVal, double newVal);
60
65 double m_rho;
67};
68
70 uint32_t segmentSize, const Time &rtt,
71 const std::string &name)
72 : TestCase (name),
73 m_cWnd (cWnd),
74 m_ssThresh (ssThresh),
75 m_segmentSize (segmentSize),
76 m_rtt (rtt),
77 m_rho (0)
78{
79}
80
81void
82TcpHyblaIncrementTest::RhoUpdated ([[maybe_unused]] double oldVal, double newVal)
83{
84 m_rho = newVal;
85}
86
87void
89{
90 m_state = CreateObject<TcpSocketState> ();
91
96
97 Ptr<TcpHybla> cong = CreateObject <TcpHybla> ();
98
99 cong->TraceConnectWithoutContext ("Rho",
101
102 // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
103 // to ACK at least segCwnd/coeffA ACK.
104
105 TimeValue rRtt;
106 cong->GetAttribute ("RRTT", rRtt);
107 cong->PktsAcked (m_state, 1, m_rtt);
108
109 double calcRho = std::max (m_rtt.GetSeconds () / rRtt.Get ().GetSeconds (), 1.0);
110
112 "Rho never updated by implementation");
113 NS_TEST_ASSERT_MSG_EQ_TOL (calcRho, m_rho, 0.01,
114 "Different rho values between implementation and test");
115
116 cong->IncreaseWindow (m_state, 1);
117
118 if (m_cWnd <= m_ssThresh)
119 {
120 // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
121 double inc = std::pow (2, calcRho) - 1.0;
122 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
124 "Congestion window has gone too far");
125 NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), cWndExpected,
126 "Congestion window different than expected");
127 }
128 else
129 {
130 // We expect an increment of rho^2 / cWnd
131 uint32_t segCwnd = m_cWnd / m_segmentSize;
132 double inc = std::pow (m_rho, 2) / ((double) segCwnd);
133 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
134
135 if (inc >= 1.0)
136 {
137 // LT because implementation does not add value less than MSS.
139 "Congestion window different than expected");
140 }
141 }
142
143}
144
145
146
154{
155public:
156 TcpHyblaTestSuite () : TestSuite ("tcp-hybla-test", UNIT)
157 {
158 AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (55), "Rho=1.1, slow start"),
159 TestCase::QUICK);
160 AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (100), "Rho=2, slow start"),
161 TestCase::QUICK);
162 AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (750), "Rho=30, slow start"),
163 TestCase::QUICK);
164 AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.55), "Rho=1.1, cong avoid"),
165 TestCase::QUICK);
166 AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.1), "Rho=2, cong avoid"),
167 TestCase::QUICK);
168 AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.75), "Rho=30, cong avoid"),
169 TestCase::QUICK);
170 }
171};
172
#define max(a, b)
Definition: 80211b.c:43
Testing the congestion avoidance increment on TcpHybla.
uint32_t m_cWnd
Congestion window.
virtual void DoRun(void)
Implementation to actually run this TestCase.
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:994
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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
AttributeValue implementation for Time.
Definition: nstime.h:1308
Time Get(void) const
Definition: time.cc:533
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
uint32_t segmentSize
#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
#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:542
#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:323
#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:712
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.