Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::quic::ecn_tracker Class Reference

ECN (Explicit Congestion Notification) tracker (RFC 9000 Section 13.4, RFC 9002 Section 7.1) More...

#include <ecn_tracker.h>

Collaboration diagram for kcenon::network::protocols::quic::ecn_tracker:
Collaboration graph

Classes

struct  validation_state
 Internal ECN validation state. More...
 

Public Member Functions

 ecn_tracker ()
 Default constructor.
 
auto process_ecn_counts (const ecn_counts &counts, uint64_t packets_acked, std::chrono::steady_clock::time_point sent_time) -> ecn_result
 Process received ECN counts from an ACK_ECN frame.
 
auto is_ecn_capable () const noexcept -> bool
 Check if ECN is validated for use.
 
auto is_testing () const noexcept -> bool
 Check if ECN is currently in testing phase.
 
auto has_failed () const noexcept -> bool
 Check if ECN has failed validation.
 
auto get_ecn_marking () const noexcept -> ecn_marking
 Get ECN marking to use for outgoing packets.
 
auto on_packets_sent (uint64_t packet_count) noexcept -> void
 Record packets sent with ECN marking.
 
auto last_congestion_sent_time () const noexcept -> std::chrono::steady_clock::time_point
 Get the sent time when the last ECN-CE congestion was detected.
 
auto current_counts () const noexcept -> const ecn_counts &
 Get current ECN counts.
 
auto reset () noexcept -> void
 Reset ECN tracker to initial state.
 
auto disable () noexcept -> void
 Disable ECN tracking.
 

Private Member Functions

auto validate_ecn (const ecn_counts &counts, uint64_t packets_acked) -> bool
 Validate ECN capability based on received counts.
 

Private Attributes

validation_state state_
 ECN validation state.
 

Detailed Description

ECN (Explicit Congestion Notification) tracker (RFC 9000 Section 13.4, RFC 9002 Section 7.1)

Tracks ECN feedback from ACK_ECN frames and validates ECN capability. ECN-CE marks indicate congestion without packet loss, providing more responsive congestion detection than loss-based methods.

Definition at line 51 of file ecn_tracker.h.

Constructor & Destructor Documentation

◆ ecn_tracker()

kcenon::network::protocols::quic::ecn_tracker::ecn_tracker ( )

Default constructor.

Starts in ECN testing mode. ECN capability will be validated when the first ACK with ECN counts is received.

Definition at line 25 of file ecn_tracker.cpp.

26 : state_{}
27{
28 // Start in testing mode
29 state_.testing = true;
30 state_.capable = false;
31 state_.failed = false;
32}
validation_state state_
ECN validation state.
bool capable
True if ECN capability has been validated.

References kcenon::network::protocols::quic::ecn_tracker::validation_state::capable, kcenon::network::protocols::quic::ecn_tracker::validation_state::failed, state_, and kcenon::network::protocols::quic::ecn_tracker::validation_state::testing.

Member Function Documentation

◆ current_counts()

auto kcenon::network::protocols::quic::ecn_tracker::current_counts ( ) const -> const ecn_counts&
inlinenodiscardnoexcept

Get current ECN counts.

Returns
Reference to current ECN counts

Definition at line 158 of file ecn_tracker.h.

159 {
160 return state_.counts;
161 }
ecn_counts counts
Current ECN counts (last received)

References kcenon::network::protocols::quic::ecn_tracker::validation_state::counts, and state_.

◆ disable()

auto kcenon::network::protocols::quic::ecn_tracker::disable ( ) -> void
noexcept

Disable ECN tracking.

Called when ECN should be permanently disabled for this connection. After calling this, get_ecn_marking() will return not_ect.

Definition at line 133 of file ecn_tracker.cpp.

134{
135 state_.failed = true;
136 state_.testing = false;
137 state_.capable = false;
138}

References kcenon::network::protocols::quic::ecn_tracker::validation_state::capable, kcenon::network::protocols::quic::ecn_tracker::validation_state::failed, state_, and kcenon::network::protocols::quic::ecn_tracker::validation_state::testing.

◆ get_ecn_marking()

auto kcenon::network::protocols::quic::ecn_tracker::get_ecn_marking ( ) const -> ecn_marking
inlinenodiscardnoexcept

Get ECN marking to use for outgoing packets.

Returns
ECN marking value to set in IP header

Returns ECT(0) when ECN is capable or testing, returns Not-ECT when ECN has failed.

RFC 9000 Section 13.4.1: ECN-capable QUIC endpoints SHOULD use ECT(0) codepoint.

Definition at line 124 of file ecn_tracker.h.

125 {
126 if (state_.failed)
127 {
129 }
130 return ecn_marking::ect0;
131 }

References kcenon::network::protocols::quic::ect0, kcenon::network::protocols::quic::ecn_tracker::validation_state::failed, kcenon::network::protocols::quic::not_ect, and state_.

◆ has_failed()

auto kcenon::network::protocols::quic::ecn_tracker::has_failed ( ) const -> bool
inlinenodiscardnoexcept

Check if ECN has failed validation.

Returns
True if ECN validation has failed

Definition at line 109 of file ecn_tracker.h.

110 {
111 return state_.failed;
112 }

References kcenon::network::protocols::quic::ecn_tracker::validation_state::failed, and state_.

◆ is_ecn_capable()

auto kcenon::network::protocols::quic::ecn_tracker::is_ecn_capable ( ) const -> bool
inlinenodiscardnoexcept

Check if ECN is validated for use.

Returns
True if ECN capability has been successfully validated

ECN is considered capable when:

  • Testing phase is complete
  • ECN counts have been successfully validated
  • No ECN failure has been detected

Definition at line 91 of file ecn_tracker.h.

92 {
93 return state_.capable && !state_.testing;
94 }

References kcenon::network::protocols::quic::ecn_tracker::validation_state::capable, state_, and kcenon::network::protocols::quic::ecn_tracker::validation_state::testing.

◆ is_testing()

auto kcenon::network::protocols::quic::ecn_tracker::is_testing ( ) const -> bool
inlinenodiscardnoexcept

Check if ECN is currently in testing phase.

Returns
True if still testing ECN capability

Definition at line 100 of file ecn_tracker.h.

101 {
102 return state_.testing;
103 }

References state_, and kcenon::network::protocols::quic::ecn_tracker::validation_state::testing.

◆ last_congestion_sent_time()

auto kcenon::network::protocols::quic::ecn_tracker::last_congestion_sent_time ( ) const -> std::chrono::steady_clock::time_point
inlinenodiscardnoexcept

Get the sent time when the last ECN-CE congestion was detected.

Returns
Time point of the packet that triggered the congestion signal

Used by the congestion controller to determine if we're in recovery.

Definition at line 148 of file ecn_tracker.h.

150 {
152 }
std::chrono::steady_clock::time_point last_congestion_sent_time
Sent time of the packet that triggered the last congestion signal.

References kcenon::network::protocols::quic::ecn_tracker::validation_state::last_congestion_sent_time, and state_.

◆ on_packets_sent()

auto kcenon::network::protocols::quic::ecn_tracker::on_packets_sent ( uint64_t packet_count) -> void
noexcept

Record packets sent with ECN marking.

Parameters
packet_countNumber of packets sent with ECN marking

Used for ECN validation to track how many ECN-marked packets have been sent.

Definition at line 119 of file ecn_tracker.cpp.

120{
121 if (!state_.failed)
122 {
123 state_.packets_sent_with_ect += packet_count;
124 }
125}
uint64_t packets_sent_with_ect
Number of ECT-marked packets sent.

◆ process_ecn_counts()

auto kcenon::network::protocols::quic::ecn_tracker::process_ecn_counts ( const ecn_counts & counts,
uint64_t packets_acked,
std::chrono::steady_clock::time_point sent_time ) -> ecn_result
nodiscard

Process received ECN counts from an ACK_ECN frame.

Parameters
countsECN counts from the ACK frame
packets_ackedNumber of packets acknowledged in this ACK
sent_timeSent time of the oldest acknowledged packet (for recovery tracking)
Returns
ECN processing result (congestion signal, failure, or none)

This method should be called for every ACK_ECN frame received. It compares the new counts against previously recorded counts to detect ECN-CE increases (congestion signals).

RFC 9000 Section 13.4.2.1: Processing ECN Information

  • If ECN-CE count increased, signal congestion to congestion controller
  • If ECN counts decreased or don't match expectations, ECN has failed

Definition at line 34 of file ecn_tracker.cpp.

38{
39 // If ECN has already failed, don't process further
40 if (state_.failed)
41 {
43 }
44
45 // RFC 9000 Section 13.4.2.1: Verify ECN counts are valid
46 // ECN counts must be monotonically increasing
47 if (counts.ect0 < state_.counts.ect0 ||
48 counts.ect1 < state_.counts.ect1 ||
49 counts.ecn_ce < state_.counts.ecn_ce)
50 {
51 // ECN counts decreased - this is invalid, disable ECN
52 state_.failed = true;
53 state_.testing = false;
54 state_.capable = false;
56 }
57
58 // Validate ECN if still in testing phase
59 if (state_.testing)
60 {
61 if (!validate_ecn(counts, packets_acked))
62 {
63 state_.failed = true;
64 state_.testing = false;
65 state_.capable = false;
67 }
68
69 // Check if we have enough data to complete validation
70 uint64_t total_marks = counts.ect0 + counts.ect1 + counts.ecn_ce;
72 {
73 state_.testing = false;
74 state_.capable = true;
75 }
76 }
77
78 // Check for ECN-CE increase (congestion signal)
79 // RFC 9002 Section 7.1: ECN-CE marks indicate congestion
81 if (counts.ecn_ce > state_.counts.ecn_ce)
82 {
83 // ECN-CE count increased - congestion experienced
86 }
87
88 // Update stored counts
89 state_.counts = counts;
90
91 return result;
92}
auto validate_ecn(const ecn_counts &counts, uint64_t packets_acked) -> bool
Validate ECN capability based on received counts.
ecn_result
Result of ECN counts processing (RFC 9000 Section 13.4)
Definition ecn_tracker.h:20
@ ecn_failure
ECN validation failed, should disable ECN.
@ congestion_signal
ECN-CE increased (congestion experienced)
static constexpr uint64_t kValidationThreshold
Number of packets required to complete validation.

References kcenon::network::protocols::quic::congestion_signal, kcenon::network::protocols::quic::ecn_failure, and kcenon::network::protocols::quic::none.

◆ reset()

auto kcenon::network::protocols::quic::ecn_tracker::reset ( ) -> void
noexcept

Reset ECN tracker to initial state.

Resets all state including ECN counts and validation status. ECN testing will restart.

Definition at line 127 of file ecn_tracker.cpp.

128{
129 state_ = validation_state{};
130 state_.testing = true;
131}

References state_, and kcenon::network::protocols::quic::ecn_tracker::validation_state::testing.

◆ validate_ecn()

auto kcenon::network::protocols::quic::ecn_tracker::validate_ecn ( const ecn_counts & counts,
uint64_t packets_acked ) -> bool
nodiscardprivate

Validate ECN capability based on received counts.

Parameters
countsReceived ECN counts
packets_ackedNumber of packets acknowledged
Returns
True if validation passed

RFC 9000 Section 13.4.2.1:

  • The sum of ECN counts MUST NOT be less than the total number of QUIC packets sent with an ECT codepoint.
  • If ECN counts are less than sent packets, ECN is being stripped.

Definition at line 94 of file ecn_tracker.cpp.

96{
97 // RFC 9000 Section 13.4.2.1:
98 // The total increase in ECT(0), ECT(1), and ECN-CE counts MUST be
99 // at least the number of newly acknowledged packets that were
100 // originally sent with an ECT codepoint.
101
102 uint64_t total_increase =
103 (counts.ect0 - state_.counts.ect0) +
104 (counts.ect1 - state_.counts.ect1) +
105 (counts.ecn_ce - state_.counts.ecn_ce);
106
107 // We sent packets with ECT(0) marking, so we expect the ECN counts
108 // to reflect at least those packets
109 if (total_increase < packets_acked && state_.packets_sent_with_ect > 0)
110 {
111 // ECN counts don't account for all packets - ECN is being stripped
112 // by the network path, or the peer doesn't support ECN properly
113 return false;
114 }
115
116 return true;
117}

Member Data Documentation

◆ state_

validation_state kcenon::network::protocols::quic::ecn_tracker::state_
private

The documentation for this class was generated from the following files: