Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
ecn_tracker.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include "frame_types.h"
8
9#include <chrono>
10#include <cstdint>
11
13{
14
19enum class ecn_result
20{
21 none,
24};
25
29[[nodiscard]] auto ecn_result_to_string(ecn_result result) noexcept -> const char*;
30
35enum class ecn_marking : uint8_t
36{
37 not_ect = 0x00,
38 ect1 = 0x01,
39 ect0 = 0x02,
40 ecn_ce = 0x03,
41};
42
52{
53public:
61
77 [[nodiscard]] auto process_ecn_counts(const ecn_counts& counts,
78 uint64_t packets_acked,
79 std::chrono::steady_clock::time_point sent_time)
80 -> ecn_result;
81
91 [[nodiscard]] auto is_ecn_capable() const noexcept -> bool
92 {
93 return state_.capable && !state_.testing;
94 }
95
100 [[nodiscard]] auto is_testing() const noexcept -> bool
101 {
102 return state_.testing;
103 }
104
109 [[nodiscard]] auto has_failed() const noexcept -> bool
110 {
111 return state_.failed;
112 }
113
124 [[nodiscard]] auto get_ecn_marking() const noexcept -> ecn_marking
125 {
126 if (state_.failed)
127 {
129 }
130 return ecn_marking::ect0;
131 }
132
140 auto on_packets_sent(uint64_t packet_count) noexcept -> void;
141
148 [[nodiscard]] auto last_congestion_sent_time() const noexcept
149 -> std::chrono::steady_clock::time_point
150 {
152 }
153
158 [[nodiscard]] auto current_counts() const noexcept -> const ecn_counts&
159 {
160 return state_.counts;
161 }
162
169 auto reset() noexcept -> void;
170
177 auto disable() noexcept -> void;
178
179private:
185 {
187 bool capable{false};
188
190 bool testing{true};
191
193 bool failed{false};
194
196 ecn_counts counts{};
197
199 uint64_t packets_sent_with_ect{0};
200
202 std::chrono::steady_clock::time_point last_congestion_sent_time{};
203
205 static constexpr uint64_t kValidationThreshold = 10;
206 };
207
219 [[nodiscard]] auto validate_ecn(const ecn_counts& counts,
220 uint64_t packets_acked) -> bool;
221
224};
225
226} // namespace kcenon::network::protocols::quic
ECN (Explicit Congestion Notification) tracker (RFC 9000 Section 13.4, RFC 9002 Section 7....
Definition ecn_tracker.h:52
auto validate_ecn(const ecn_counts &counts, uint64_t packets_acked) -> bool
Validate ECN capability based on received counts.
validation_state state_
ECN validation state.
auto get_ecn_marking() const noexcept -> ecn_marking
Get ECN marking to use for outgoing packets.
auto current_counts() const noexcept -> const ecn_counts &
Get current ECN counts.
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 reset() noexcept -> void
Reset ECN tracker to initial state.
auto is_ecn_capable() const noexcept -> bool
Check if ECN is validated for use.
Definition ecn_tracker.h:91
auto has_failed() const noexcept -> bool
Check if ECN has failed validation.
auto is_testing() const noexcept -> bool
Check if ECN is currently in testing phase.
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 on_packets_sent(uint64_t packet_count) noexcept -> void
Record packets sent with ECN marking.
auto disable() noexcept -> void
Disable ECN tracking.
auto ecn_result_to_string(ecn_result result) noexcept -> const char *
Convert ecn_result to string.
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)
ecn_marking
ECN marking values for IP header (RFC 3168)
Definition ecn_tracker.h:36
ECN counts for ACK_ECN frames.
bool capable
True if ECN capability has been validated.
ecn_counts counts
Current ECN counts (last received)
std::chrono::steady_clock::time_point last_congestion_sent_time
Sent time of the packet that triggered the last congestion signal.