A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
14
using namespace
ns3
;
15
16
NS_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
*/
38
class
TcpDctcpLossSsThreshTest
:
public
TestCase
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
*/
49
TcpDctcpLossSsThreshTest
(
uint32_t
cWnd,
50
uint32_t
segmentSize
,
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
62
TcpDctcpLossSsThreshTest::TcpDctcpLossSsThreshTest
(
uint32_t
cWnd,
63
uint32_t
segmentSize
,
64
uint32_t
bytesInFlight,
65
const
std::string& name)
66
:
TestCase
(name),
67
m_cWnd
(cWnd),
68
m_segmentSize
(
segmentSize
),
69
m_bytesInFlight
(bytesInFlight)
70
{
71
}
72
73
void
74
TcpDctcpLossSsThreshTest::DoRun
()
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.
79
Ptr<TcpSocketState>
state =
CreateObject<TcpSocketState>
();
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
87
Ptr<TcpDctcp>
cong =
CreateObject<TcpDctcp>
();
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}).
108
NS_TEST_ASSERT_MSG_EQ_TOL
(
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
*/
125
class
TcpDctcpLossTestSuite
:
public
TestSuite
126
{
127
public
:
128
TcpDctcpLossTestSuite
()
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.
133
AddTestCase
(
new
TcpDctcpLossSsThreshTest
(20 * 1446,
134
1446,
135
20 * 1446,
136
"DCTCP backs off to ~BytesInFlight * 0.5 on "
137
"packet loss with alpha=0"
),
138
TestCase::Duration::QUICK
);
139
}
140
};
141
142
static
TcpDctcpLossTestSuite
g_tcpDctcpLossTestSuite
;
//!< Static instance for test registration
TcpDctcpLossSsThreshTest
Regression test for Issue 1012.
Definition
tcp-dctcp-loss-test-suite.cc:39
TcpDctcpLossSsThreshTest::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition
tcp-dctcp-loss-test-suite.cc:58
TcpDctcpLossSsThreshTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-dctcp-loss-test-suite.cc:74
TcpDctcpLossSsThreshTest::m_bytesInFlight
uint32_t m_bytesInFlight
Bytes in flight passed to GetSsThresh.
Definition
tcp-dctcp-loss-test-suite.cc:59
TcpDctcpLossSsThreshTest::TcpDctcpLossSsThreshTest
TcpDctcpLossSsThreshTest(uint32_t cWnd, uint32_t segmentSize, uint32_t bytesInFlight, const std::string &name)
Constructor.
Definition
tcp-dctcp-loss-test-suite.cc:62
TcpDctcpLossSsThreshTest::m_cWnd
uint32_t m_cWnd
Congestion window at loss time.
Definition
tcp-dctcp-loss-test-suite.cc:57
TcpDctcpLossTestSuite
TCP DCTCP non-ECN loss back-off TestSuite (regression for Issue 1012).
Definition
tcp-dctcp-loss-test-suite.cc:126
TcpDctcpLossTestSuite::TcpDctcpLossTestSuite
TcpDctcpLossTestSuite()
Definition
tcp-dctcp-loss-test-suite.cc:128
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
ns3::TcpSocketState::CA_LOSS
@ CA_LOSS
CWND was reduced due to RTO timeout or SACK reneging.
Definition
tcp-socket-state.h:79
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:296
ns3::TestCase::Duration::QUICK
@ QUICK
Fast test.
Definition
test.h:1057
ns3::TestCase::TestCase
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1271
ns3::TestSuite::Type::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition
test.h:1273
ns3::TestSuite::TestSuite
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition
test.cc:494
uint32_t
segmentSize
uint32_t segmentSize
Definition
tcp-linux-reno.cc:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:201
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:274
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:627
NS_TEST_ASSERT_MSG_EQ_TOL
#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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
g_tcpDctcpLossTestSuite
static TcpDctcpLossTestSuite g_tcpDctcpLossTestSuite
Static instance for test registration.
Definition
tcp-dctcp-loss-test-suite.cc:142
src
internet
test
tcp-dctcp-loss-test-suite.cc
Generated on
for ns-3 by
1.16.1