A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-hybla-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/log.h"
9#include "ns3/tcp-congestion-ops.h"
10#include "ns3/tcp-hybla.h"
11#include "ns3/tcp-socket-base.h"
12#include "ns3/test.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpHyblaTestSuite");
17
18/**
19 * @ingroup internet-test
20 *
21 * @brief Testing the congestion avoidance increment on TcpHybla
22 */
24{
25 public:
26 /**
27 * @brief Constructor.
28 * @param cWnd Congestion window.
29 * @param ssThresh Slow Start Threshold.
30 * @param segmentSize Segment size.
31 * @param rtt Round trip time.
32 * @param name Test description.
33 */
35 uint32_t ssThresh,
37 const Time& rtt,
38 const std::string& name);
39
40 private:
41 void DoRun() override;
42
43 /**
44 * @brief Tracks TCP Hybla rho parameter changes.
45 * @param oldVal Previous value.
46 * @param newVal Actual value.
47 */
48 void RhoUpdated(double oldVal, double newVal);
49
50 uint32_t m_cWnd; //!< Congestion window.
51 uint32_t m_ssThresh; //!< Slow Start Threshold.
52 uint32_t m_segmentSize; //!< Segment size.
53 Time m_rtt; //!< Round trip time.
54 double m_rho; //!< TCP Hybla rho parameter.
55 Ptr<TcpSocketState> m_state; //!< TCP socket state.
56};
57
59 uint32_t ssThresh,
61 const Time& rtt,
62 const std::string& name)
63 : TestCase(name),
64 m_cWnd(cWnd),
65 m_ssThresh(ssThresh),
66 m_segmentSize(segmentSize),
67 m_rtt(rtt),
68 m_rho(0)
69{
70}
71
72void
73TcpHyblaIncrementTest::RhoUpdated(double /* oldVal */, double newVal)
74{
75 m_rho = newVal;
76}
77
78void
80{
82
83 m_state->m_cWnd = m_cWnd;
84 m_state->m_ssThresh = m_ssThresh;
85 m_state->m_segmentSize = m_segmentSize;
86 m_state->m_minRtt = m_rtt;
87
89
90 cong->TraceConnectWithoutContext("Rho", MakeCallback(&TcpHyblaIncrementTest::RhoUpdated, this));
91
92 // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
93 // to ACK at least segCwnd/coeffA ACK.
94
95 TimeValue rRtt;
96 cong->GetAttribute("RRTT", rRtt);
97 cong->PktsAcked(m_state, 1, m_rtt);
98
99 double calcRho = std::max(m_rtt.GetSeconds() / rRtt.Get().GetSeconds(), 1.0);
100
101 NS_TEST_ASSERT_MSG_NE(m_rho, 0.0, "Rho never updated by implementation");
103 m_rho,
104 0.01,
105 "Different rho values between implementation and test");
106
107 cong->IncreaseWindow(m_state, 1);
108
109 if (m_cWnd <= m_ssThresh)
110 {
111 // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
112 double inc = std::pow(2, calcRho) - 1.0;
113 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
115 m_state->m_ssThresh.Get(),
116 "Congestion window has gone too far");
117 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(),
118 cWndExpected,
119 "Congestion window different than expected");
120 }
121 else
122 {
123 // We expect an increment of rho^2 / cWnd
124 uint32_t segCwnd = m_cWnd / m_segmentSize;
125 double inc = std::pow(m_rho, 2) / ((double)segCwnd);
126 uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
127
128 if (inc >= 1.0)
129 {
130 // LT because implementation does not add value less than MSS.
132 cWndExpected,
133 "Congestion window different than expected");
134 }
135 }
136}
137
138/**
139 * @ingroup internet-test
140 *
141 * @brief TCP Hybla TestSuite
142 */
144{
145 public:
147 : TestSuite("tcp-hybla-test", Type::UNIT)
148 {
150 0xFFFFFFFF,
151 500,
152 MilliSeconds(55),
153 "Rho=1.1, slow start"),
154 TestCase::Duration::QUICK);
156 0xFFFFFFFF,
157 500,
158 MilliSeconds(100),
159 "Rho=2, slow start"),
160 TestCase::Duration::QUICK);
162 0xFFFFFFFF,
163 500,
164 MilliSeconds(750),
165 "Rho=30, slow start"),
166 TestCase::Duration::QUICK);
167 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.55), "Rho=1.1, cong avoid"),
168 TestCase::Duration::QUICK);
169 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.1), "Rho=2, cong avoid"),
170 TestCase::Duration::QUICK);
171 AddTestCase(new TcpHyblaIncrementTest(1000, 500, 500, Seconds(0.75), "Rho=30, cong avoid"),
172 TestCase::Duration::QUICK);
173 }
174};
175
176static TcpHyblaTestSuite g_tcpHyblaTest; //!< Static variable for test initialization
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.
Smart pointer class similar to boost::intrusive_ptr.
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
AttributeValue implementation for Time.
Definition nstime.h:1431
Time Get() const
Definition time.cc:519
uint32_t segmentSize
#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
#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:554
#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:327
#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:740
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
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:684
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.