A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-dctcp-loss-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
7 */
8
9#include "ns3/log.h"
10#include "ns3/tcp-dctcp.h"
11#include "ns3/tcp-socket-state.h"
12#include "ns3/test.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpDctcpLossTestSuite");
17
18/**
19 * @ingroup internet-test
20 * @ingroup tests
21 *
22 * @brief Regression test for @issueid{1012}.
23 *
24 * @issueid{1012}: "DcTcp behaves incorrectly with non-ECN routers".
25 *
26 * @RFC{8257} Section 3.5 ("Handling of Packet Loss") mandates that a DCTCP
27 * sender MUST react to a loss episode (loss inferred, not signalled by ECN)
28 * in the same way a conventional TCP would, i.e. it MUST reduce cwnd and
29 * ssthresh as @RFC{5681} does (roughly halving them based on BytesInFlight).
30 *
31 * Without ECN-marking routers, @c m_alpha decays toward 0 (because
32 * @c m_ackedBytesEcn stays 0), so the alpha-based reduction alone would leave
33 * ssthresh at approximately @c m_cWnd on a packet loss.
34 *
35 * This test exercises GetSsThresh directly on a crafted TcpSocketState with
36 * alpha == 0 (the non-ECN steady state) and asserts the @RFC{5681} behaviour.
37 */
39{
40 public:
41 /**
42 * @brief Constructor.
43 *
44 * @param cWnd Congestion window (bytes) at the time of the loss event.
45 * @param segmentSize Segment size in bytes.
46 * @param bytesInFlight Bytes in flight reported to GetSsThresh.
47 * @param name Name of the test.
48 */
51 uint32_t bytesInFlight,
52 const std::string& name);
53
54 private:
55 void DoRun() override;
56
57 uint32_t m_cWnd; //!< Congestion window at loss time
58 uint32_t m_segmentSize; //!< Segment size
59 uint32_t m_bytesInFlight; //!< Bytes in flight passed to GetSsThresh
60};
61
64 uint32_t bytesInFlight,
65 const std::string& name)
66 : TestCase(name),
67 m_cWnd(cWnd),
69 m_bytesInFlight(bytesInFlight)
70{
71}
72
73void
75{
76 // Craft a sender state representing the moment a packet loss is
77 // detected. With non-ECN routers the DCTCP congestion estimate alpha has
78 // decayed to (approximately) zero.
80 state->m_cWnd = m_cWnd;
81 state->m_segmentSize = m_segmentSize;
82 state->m_ssThresh = m_cWnd;
83 // Mark this as a packet loss event (as opposed to an ECN-CE reduction), so a
84 // correct DCTCP implementation applies @RFC{5681} loss-based backoff here.
85 state->m_congState = TcpSocketState::CA_LOSS;
86
88 // Force alpha to its non-ECN steady state of 0. DctcpAlphaOnInit must be
89 // set before Init()/use; the default initial alpha is 1.0.
90 cong->SetAttribute("DctcpAlphaOnInit", DoubleValue(0.0));
91
92 // GetSsThresh() is invoked on entering CWR following a congestion event.
93 // For a packet loss, @RFC{8257} Section 3.5 requires the same
94 // reduction as @RFC{5681}: ssthresh = max(BytesInFlight / 2, 2 * SMSS).
95 uint32_t newSsThresh = cong->GetSsThresh(state, m_bytesInFlight);
96
97 // @RFC{5681} loss-based expectation.
98 uint32_t expectedSsThresh = std::max(m_bytesInFlight / 2, 2 * m_segmentSize);
99
100 // Allow a tolerance of one segment to accommodate rounding.
101 uint32_t tolerance = m_segmentSize;
102
103 NS_LOG_INFO("cWnd=" << m_cWnd << " bytesInFlight=" << m_bytesInFlight << " GetSsThresh="
104 << newSsThresh << " expected(~half)=" << expectedSsThresh);
105
106 // With alpha == 0, @RFC{5681} loss-based backoff must yield
107 // ~bytesInFlight/2 (@issueid{1012}).
109 newSsThresh,
110 expectedSsThresh,
111 tolerance,
112 "DCTCP did not apply RFC-5681 loss-based backoff on a packet "
113 "loss: ssthresh should be ~BytesInFlight/2 but is ~cwnd (issue #1012)");
114}
115
116/**
117 * @ingroup internet-test
118 * @ingroup tests
119 *
120 * @brief TCP DCTCP non-ECN loss back-off TestSuite (regression for @issueid{1012}).
121 *
122 * Checks that DCTCP performs @RFC{5681} loss-based congestion-window reduction
123 * on a packet loss. See TcpDctcpLossSsThreshTest.
124 */
126{
127 public:
129 : TestSuite("tcp-dctcp-loss", Type::UNIT)
130 {
131 // cWnd = 20 segments, bytesInFlight = 20 segments. Loss-based recovery
132 // should drop ssthresh to ~10 segments; the bug leaves it at ~20.
134 1446,
135 20 * 1446,
136 "DCTCP backs off to ~BytesInFlight * 0.5 on "
137 "packet loss with alpha=0"),
139 }
140};
141
142static TcpDctcpLossTestSuite g_tcpDctcpLossTestSuite; //!< Static instance for test registration
Regression test for Issue 1012.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_bytesInFlight
Bytes in flight passed to GetSsThresh.
TcpDctcpLossSsThreshTest(uint32_t cWnd, uint32_t segmentSize, uint32_t bytesInFlight, const std::string &name)
Constructor.
uint32_t m_cWnd
Congestion window at loss time.
TCP DCTCP non-ECN loss back-off TestSuite (regression for Issue 1012).
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
@ CA_LOSS
CWND was reduced due to RTO timeout or SACK reneging.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#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:326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpDctcpLossTestSuite g_tcpDctcpLossTestSuite
Static instance for test registration.