A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-abe-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: N Nagabhushanam <thechosentwins2005@gmail.com>
7 * Namburi Yaswanth <yaswanthnamburi1010@gmail.com>
8 * Vishruth S Kumar <vishruthskumar@gmail.com>
9 * Yashas <yashas80dj@gmail.com>
10 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
11 */
12#include "ns3/log.h"
13#include "ns3/tcp-cubic.h"
14#include "ns3/tcp-linux-reno.h"
15#include "ns3/tcp-socket-state.h"
16#include "ns3/test.h"
17
18namespace ns3
19{
20NS_LOG_COMPONENT_DEFINE("TcpAbeTestSuite");
21
22constexpr uint32_t WITHOUT_ABE = 0; //!< Test case without ABE
23constexpr uint32_t WITH_ABE = 1; //!< Test case with ABE
24
25/**
26 * @ingroup internet-test
27 * @brief Test Socket Base class for ABE testing
28 *
29 * This class provides access to the TCP socket state and allows
30 * manipulation of ECN state for testing purposes.
31 */
33{
34 public:
35 /**
36 * @brief Get the pointer for socket state
37 * @return ptr to TcpSocketState
38 */
40 {
41 return m_tcb;
42 }
43
44 /**
45 * @brief Set the ECE state for testing ECN behavior
46 */
47 void SetECE()
48 {
50 }
51};
52
53/**
54 * @ingroup internet-test
55 * @brief Checks if users are able to enable ABE or not.
56 **/
57
59{
60 protected:
61 Ptr<TestTcpSocketBase> m_socket; //!< Socket used for testing
62
63 public:
64 /**
65 * @brief Constructor
66 * @param desc Test case description
67 */
68 TcpAbeToggleTest(const std::string& desc)
69 : TestCase(desc)
70 {
71 }
72
73 /**
74 * @brief Runs the test
75 */
76 void DoRun() override
77 {
79 m_socket->SetUseAbe(true);
80 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_abeEnabled, true, "ABE should be enabled");
81 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_useEcn,
82 true,
83 "ECN should be enabled along with ABE");
84
85 m_socket->SetUseAbe(false);
86 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_abeEnabled, false, "ABE should be disabled");
87 }
88};
89
90/**
91 * @ingroup internet-test
92 * @brief Test case for congestion control algorithms with ABE
93 *
94 * This test verifies that when a TCP socket has ABE enabled, the congestion
95 * window value returned by its GetSsThresh() method will be calculated using
96 * the default BetaEcn value, and when ABE is disabled, the standard
97 * multiplicative decrease by half is used.
98 * ABE should only work for TcpCubic, TcpNewReno, TcpLinuxReno as specified in
99 * RFC-8511
100 */
101class TcpAbeTest : public TestCase
102{
103 private:
104 uint32_t testCase; //!< Test case number
105 uint32_t m_segmentSize; //!< Segment size
106 uint32_t m_initialCwnd; //!< Initial congestion window
107 uint32_t m_expectedCwnd; //!< Expected congestion window after applying Beta(BetaLoss)/BetaEcn
108 uint32_t m_bytesInFlight; //!< Bytes in flight
109 TypeId m_congestionControlType; //!< TypeId of the congestion control algorithm type used for
110 //!< the test
111 Ptr<TestTcpSocketBase> m_socket; //!< Socket used for testing
112
113 public:
114 /**
115 * @brief Constructor
116 * @param desc Test case description
117 * @param testCase Test case identifier (0 for without ABE, 1 for with ABE)
118 * @param segmentSize Segment size
119 * @param initialCwnd Initial congestion window
120 * @param expectedCwnd Expected congestion window after applying Beta(BetaLoss)/BetaEcn
121 * @param bytesInFlight Bytes in flight
122 * @param congestionControlType TypeId of the congestion control algorithm type used for the
123 * test
124 */
127 uint32_t initialCwnd,
128 uint32_t expectedCwnd,
129 uint32_t bytesInFlight,
130 TypeId& congestionControlType,
131 const std::string& desc)
132 : TestCase(desc),
135 m_initialCwnd(initialCwnd),
136 m_expectedCwnd(expectedCwnd),
137 m_bytesInFlight(bytesInFlight),
138 m_congestionControlType(congestionControlType)
139 {
140 }
141
142 /**
143 * @brief Runs the test
144 */
145 void DoRun() override
146 {
148 ObjectFactory congestionAlgorithmFactory;
149 congestionAlgorithmFactory.SetTypeId(m_congestionControlType);
150 Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps>();
151 m_socket->SetCongestionControlAlgorithm(algo);
152
153 if (testCase == WITH_ABE)
154 {
155 m_socket->SetUseAbe(true);
156 m_socket->SetECE();
157 m_socket->GetTcb()->m_segmentSize = m_segmentSize;
158 m_socket->GetTcb()->m_cWnd = m_initialCwnd;
159 m_socket->GetTcb()->m_bytesInFlight = m_bytesInFlight;
160 uint32_t newCwnd = algo->GetSsThresh(m_socket->GetTcb(), m_bytesInFlight);
162 newCwnd,
164 m_congestionControlType.GetName() +
165 " congestion control with ABE should apply BetaEcn correctly");
166 }
167 else if (testCase == WITHOUT_ABE)
168 {
169 m_socket->SetUseAbe(false);
170 m_socket->SetECE();
171 m_socket->GetTcb()->m_segmentSize = m_segmentSize;
172 m_socket->GetTcb()->m_cWnd = m_initialCwnd;
173 m_socket->GetTcb()->m_bytesInFlight = m_bytesInFlight;
174 uint32_t newCwnd = algo->GetSsThresh(m_socket->GetTcb(), m_bytesInFlight);
176 newCwnd,
178 m_congestionControlType.GetName() +
179 " congestion control without ABE should apply Beta correctly");
180 }
181 else
182 {
183 NS_TEST_EXPECT_MSG_EQ(0, 1, "Invalid test case");
184 }
185 }
186};
187
188/**
189 * @ingroup internet-test
190 * @brief Test suite for Alternative Backoff with ECN (ABE)
191 *
192 * This test suite verifies the behavior of TCP ABE with different
193 * congestion control algorithms.
194 */
196{
197 public:
198 /**
199 * @brief Constructor
200 */
202 : TestSuite("tcp-abe-test", Type::UNIT)
203 {
204 AddTestCase(new TcpAbeToggleTest("Test enabling and disabling ABE"),
206
207 TypeId cong_control_type = TcpCubic::GetTypeId();
209 1,
210 1000,
211 700,
212 100,
213 cong_control_type,
214 "Test TCP CUBIC without ABE"),
217 1,
218 1000,
219 850,
220 100,
221 cong_control_type,
222 "Test TCP CUBIC with ABE"),
224
225 cong_control_type = TcpLinuxReno::GetTypeId();
227 1,
228 1000,
229 500,
230 100,
231 cong_control_type,
232 "Test TCP Linux Reno without ABE"),
235 1,
236 1000,
237 700,
238 100,
239 cong_control_type,
240 "Test TCP Linux Reno with ABE"),
242
243 cong_control_type = TcpNewReno::GetTypeId();
245 1,
246 1000,
247 500,
248 1000,
249 cong_control_type,
250 "Test TCP New Reno without ABE"),
253 1,
254 1000,
255 700,
256 1000,
257 cong_control_type,
258 "Test TCP New Reno with ABE"),
260 }
261};
262
263static TcpAbeTestSuite g_tcpAbeTestSuite; //!< static var for test initialization
264
265} // namespace ns3
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Test case for congestion control algorithms with ABE.
uint32_t testCase
Test case number.
uint32_t m_expectedCwnd
Expected congestion window after applying Beta(BetaLoss)/BetaEcn.
uint32_t m_bytesInFlight
Bytes in flight.
TcpAbeTest(uint32_t testCase, uint32_t segmentSize, uint32_t initialCwnd, uint32_t expectedCwnd, uint32_t bytesInFlight, TypeId &congestionControlType, const std::string &desc)
Constructor.
void DoRun() override
Runs the test.
TypeId m_congestionControlType
TypeId of the congestion control algorithm type used for the test.
uint32_t m_segmentSize
Segment size.
uint32_t m_initialCwnd
Initial congestion window.
Ptr< TestTcpSocketBase > m_socket
Socket used for testing.
Test suite for Alternative Backoff with ECN (ABE)
TcpAbeTestSuite()
Constructor.
Checks if users are able to enable ABE or not.
void DoRun() override
Runs the test.
Ptr< TestTcpSocketBase > m_socket
Socket used for testing.
TcpAbeToggleTest(const std::string &desc)
Constructor.
Congestion control abstract class.
static TypeId GetTypeId()
Get the type ID.
Definition tcp-cubic.cc:25
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
Ptr< TcpSocketState > m_tcb
Congestion control information.
TcpSocketBase()
Create an unbound TCP socket.
@ ECN_ECE_RCVD
Last ACK received had ECE bit set in TCP header.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:293
@ QUICK
Fast test.
Definition test.h:1054
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1257
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1259
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:491
Test Socket Base class for ABE testing.
Ptr< TcpSocketState > GetTcb() const
Get the pointer for socket state.
void SetECE()
Set the ECE state for testing ECN behavior.
a unique identifier for an interface.
Definition type-id.h:49
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_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr uint32_t WITH_ABE
Test case with ABE.
constexpr uint32_t WITHOUT_ABE
Test case without ABE.
static TcpAbeTestSuite g_tcpAbeTestSuite
static var for test initialization
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585