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 {
78 NS_LOG_FUNCTION(this);
80 m_socket->SetUseAbe(true);
81 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_abeEnabled, true, "ABE should be enabled");
82 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_useEcn,
83 true,
84 "ECN should be enabled along with ABE");
85
86 m_socket->SetUseAbe(false);
87 NS_TEST_EXPECT_MSG_EQ(m_socket->GetTcb()->m_abeEnabled, false, "ABE should be disabled");
88 }
89};
90
91/**
92 * @ingroup internet-test
93 * @brief Test case for congestion control algorithms with ABE
94 *
95 * This test verifies that when a TCP socket has ABE enabled, the congestion
96 * window value returned by its GetSsThresh() method will be calculated using
97 * the default BetaEcn value, and when ABE is disabled, the standard
98 * multiplicative decrease by half is used.
99 * ABE should only work for TcpCubic, TcpNewReno, TcpLinuxReno as specified in
100 * RFC-8511
101 */
102class TcpAbeTest : public TestCase
103{
104 private:
105 uint32_t testCase; //!< Test case number
106 uint32_t m_segmentSize; //!< Segment size
107 uint32_t m_initialCwnd; //!< Initial congestion window
108 uint32_t m_expectedCwnd; //!< Expected congestion window after applying Beta(BetaLoss)/BetaEcn
109 uint32_t m_bytesInFlight; //!< Bytes in flight
110 TypeId m_congestionControlType; //!< TypeId of the congestion control algorithm type used for
111 //!< the test
112 Ptr<TestTcpSocketBase> m_socket; //!< Socket used for testing
113
114 public:
115 /**
116 * @brief Constructor
117 * @param desc Test case description
118 * @param testCase Test case identifier (0 for without ABE, 1 for with ABE)
119 * @param segmentSize Segment size
120 * @param initialCwnd Initial congestion window
121 * @param expectedCwnd Expected congestion window after applying Beta(BetaLoss)/BetaEcn
122 * @param bytesInFlight Bytes in flight
123 * @param congestionControlType TypeId of the congestion control algorithm type used for the
124 * test
125 */
128 uint32_t initialCwnd,
129 uint32_t expectedCwnd,
130 uint32_t bytesInFlight,
131 TypeId& congestionControlType,
132 const std::string& desc)
133 : TestCase(desc),
136 m_initialCwnd(initialCwnd),
137 m_expectedCwnd(expectedCwnd),
138 m_bytesInFlight(bytesInFlight),
139 m_congestionControlType(congestionControlType)
140 {
141 NS_LOG_FUNCTION(this << desc);
142 }
143
144 /**
145 * @brief Runs the test
146 */
147 void DoRun() override
148 {
149 NS_LOG_FUNCTION(this);
151 ObjectFactory congestionAlgorithmFactory;
152 congestionAlgorithmFactory.SetTypeId(m_congestionControlType);
153 Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps>();
154 m_socket->SetCongestionControlAlgorithm(algo);
155
156 if (testCase == WITH_ABE)
157 {
158 m_socket->SetUseAbe(true);
159 m_socket->SetECE();
160 m_socket->GetTcb()->m_segmentSize = m_segmentSize;
161 m_socket->GetTcb()->m_cWnd = m_initialCwnd;
162 m_socket->GetTcb()->m_bytesInFlight = m_bytesInFlight;
163 uint32_t newCwnd = algo->GetSsThresh(m_socket->GetTcb(), m_bytesInFlight);
165 newCwnd,
167 m_congestionControlType.GetName() +
168 " congestion control with ABE should apply BetaEcn correctly");
169 }
170 else if (testCase == WITHOUT_ABE)
171 {
172 m_socket->SetUseAbe(false);
173 m_socket->SetECE();
174 m_socket->GetTcb()->m_segmentSize = m_segmentSize;
175 m_socket->GetTcb()->m_cWnd = m_initialCwnd;
176 m_socket->GetTcb()->m_bytesInFlight = m_bytesInFlight;
177 uint32_t newCwnd = algo->GetSsThresh(m_socket->GetTcb(), m_bytesInFlight);
179 newCwnd,
181 m_congestionControlType.GetName() +
182 " congestion control without ABE should apply Beta correctly");
183 }
184 else
185 {
186 NS_TEST_EXPECT_MSG_EQ(0, 1, "Invalid test case");
187 }
189 m_socket = nullptr;
190 }
191};
192
193/**
194 * @ingroup internet-test
195 * @brief Test suite for Alternative Backoff with ECN (ABE)
196 *
197 * This test suite verifies the behavior of TCP ABE with different
198 * congestion control algorithms.
199 */
201{
202 public:
203 /**
204 * @brief Constructor
205 */
207 : TestSuite("tcp-abe-test", Type::UNIT)
208 {
209 AddTestCase(new TcpAbeToggleTest("Test enabling and disabling ABE"),
211
212 TypeId cong_control_type = TcpCubic::GetTypeId();
214 1,
215 1000,
216 700,
217 100,
218 cong_control_type,
219 "Test TCP CUBIC without ABE"),
222 1,
223 1000,
224 850,
225 100,
226 cong_control_type,
227 "Test TCP CUBIC with ABE"),
229
230 cong_control_type = TcpLinuxReno::GetTypeId();
232 1,
233 1000,
234 500,
235 100,
236 cong_control_type,
237 "Test TCP Linux Reno without ABE"),
240 1,
241 1000,
242 700,
243 100,
244 cong_control_type,
245 "Test TCP Linux Reno with ABE"),
247
248 cong_control_type = TcpNewReno::GetTypeId();
250 1,
251 1000,
252 500,
253 1000,
254 cong_control_type,
255 "Test TCP New Reno without ABE"),
258 1,
259 1000,
260 700,
261 1000,
262 cong_control_type,
263 "Test TCP New Reno with ABE"),
265 }
266};
267
268static TcpAbeTestSuite g_tcpAbeTestSuite; //!< static var for test initialization
269
270} // 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
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
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
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
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