Skip to main content

sedsnet/
diagnostics.rs

1use alloc::{string::String, vec::Vec};
2
3use crate::{DataType, RouteSelectionMode};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct RuntimeTypeStats {
7    pub data_type: DataType,
8    pub tx_packets: u64,
9    pub tx_bytes: u64,
10    pub rx_packets: u64,
11    pub rx_bytes: u64,
12    pub relayed_tx_packets: u64,
13    pub relayed_tx_bytes: u64,
14    pub relayed_rx_packets: u64,
15    pub relayed_rx_bytes: u64,
16    pub tx_retries: u64,
17    pub handler_failures: u64,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct AdaptiveLinkStats {
22    pub auto_balancing_enabled: bool,
23    pub estimated_capacity_bps: u64,
24    pub peak_capacity_bps: u64,
25    pub current_usage_bps: u64,
26    pub peak_usage_bps: u64,
27    pub available_headroom_bps: u64,
28    pub effective_weight: u64,
29    pub last_observed_ms: u64,
30    pub sample_count: u64,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct RuntimeSideStats {
35    pub side_id: usize,
36    pub side_name: String,
37    pub reliable_enabled: bool,
38    pub link_local_enabled: bool,
39    pub header_template_enabled: bool,
40    pub max_frame_bytes: usize,
41    pub compact_header_target_bytes: usize,
42    pub side_transport_profile: &'static str,
43    pub ingress_enabled: bool,
44    pub egress_enabled: bool,
45    pub tx_packets: u64,
46    pub tx_bytes: u64,
47    pub rx_packets: u64,
48    pub rx_bytes: u64,
49    pub relayed_tx_packets: u64,
50    pub relayed_tx_bytes: u64,
51    pub relayed_rx_packets: u64,
52    pub relayed_rx_bytes: u64,
53    pub local_delivery_packets: u64,
54    pub tx_retries: u64,
55    pub tx_handler_failures: u64,
56    pub local_handler_failures: u64,
57    pub total_handler_retries: u64,
58    pub side_transport_full_frames: u64,
59    pub side_transport_compact_frames: u64,
60    pub side_transport_compact_delta_frames: u64,
61    pub side_transport_compact_omitted_timestamp_frames: u64,
62    pub side_transport_chunk_frames: u64,
63    /// Incomplete transfers reclaimed under pressure, expiry or the per-link cap.
64    pub side_transport_chunk_reclaims: u64,
65    pub side_transport_raw_bytes: u64,
66    pub side_transport_wire_bytes: u64,
67    pub side_transport_bytes_saved: u64,
68    pub side_transport_min_compact_overhead_bytes: Option<usize>,
69    pub side_transport_max_compact_overhead_bytes: Option<usize>,
70    pub side_transport_compact_target_misses: u64,
71    pub side_transport_template_evictions: u64,
72    pub side_transport_tx_template_count: usize,
73    pub side_transport_rx_template_count: usize,
74    pub max_side_transport_templates: usize,
75    pub adaptive: AdaptiveLinkStats,
76    pub data_types: Vec<RuntimeTypeStats>,
77}
78
79#[derive(Debug, Clone, PartialEq, Eq)]
80pub struct RouteModeStats {
81    pub src_side_id: Option<usize>,
82    pub selection_mode: Option<RouteSelectionMode>,
83    pub cursor: u64,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
87pub struct RouteOverrideStats {
88    pub src_side_id: Option<usize>,
89    pub dst_side_id: usize,
90    pub enabled: bool,
91}
92
93#[derive(Debug, Clone, PartialEq, Eq)]
94pub struct TypedRouteOverrideStats {
95    pub src_side_id: Option<usize>,
96    pub data_type: DataType,
97    pub dst_side_id: usize,
98    pub enabled: bool,
99}
100
101#[derive(Debug, Clone, PartialEq, Eq)]
102pub struct RouteWeightStats {
103    pub src_side_id: Option<usize>,
104    pub dst_side_id: usize,
105    pub weight: u32,
106}
107
108#[derive(Debug, Clone, PartialEq, Eq)]
109pub struct RoutePriorityStats {
110    pub src_side_id: Option<usize>,
111    pub dst_side_id: usize,
112    pub priority: u32,
113}
114
115#[derive(Debug, Clone, PartialEq, Eq)]
116pub struct QueueRuntimeStats {
117    pub rx_len: usize,
118    pub rx_bytes: usize,
119    pub tx_len: usize,
120    pub tx_bytes: usize,
121    pub replay_len: usize,
122    pub replay_bytes: usize,
123    pub recent_rx_len: usize,
124    pub recent_rx_bytes: usize,
125    pub reliable_rx_buffered_len: usize,
126    pub reliable_rx_buffered_bytes: usize,
127    pub shared_queue_bytes_used: usize,
128}
129
130#[derive(Debug, Clone, PartialEq, Eq)]
131pub struct ReliableRuntimeStats {
132    pub reliable_return_route_count: usize,
133    pub end_to_end_pending_count: usize,
134    pub end_to_end_pending_destination_count: usize,
135    pub end_to_end_acked_cache_count: usize,
136}
137
138/// Fixed-size, allocation-free pending-delivery summary for constrained diagnostics.
139/// `pending_owners` contains at most four hashes; `pending_count` is the total.
140/// Flags: bit 0 queued, bit 1 waiting for predecessor, bit 2 proxy contract,
141/// bit 3 tracks explicit destination owners. Unused rows/owners are zeroed.
142#[repr(C)]
143#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
144pub struct ReliablePendingRow {
145    pub packet_id: u64,
146    pub last_send_ms: u64,
147    pub data_type: u32,
148    pub pending_count: u32,
149    pub retries: u32,
150    pub flags: u32,
151    pub pending_owners: [u64; 4],
152}
153
154/// On-demand metadata for an outstanding reliable transmission. Payloads are
155/// neither decoded nor copied; destination identifiers are sender hashes.
156#[derive(Debug, Clone, PartialEq, Eq)]
157pub struct ReliablePendingStats {
158    pub packet_id: u64,
159    pub data_type: DataType,
160    pub pending_destinations: Vec<u64>,
161    pub retries: u32,
162    pub queued: bool,
163    pub waiting_for_predecessor: bool,
164    pub last_send_ms: u64,
165}
166
167#[derive(Debug, Clone, PartialEq, Eq)]
168pub struct DiscoveryRuntimeStats {
169    pub route_count: usize,
170    pub announcer_count: usize,
171    pub current_announce_interval_ms: Option<u64>,
172    pub next_announce_ms: Option<u64>,
173}
174
175#[derive(Debug, Clone, PartialEq, Eq)]
176pub struct RuntimeStatsSnapshot {
177    pub sides: Vec<RuntimeSideStats>,
178    pub route_modes: Vec<RouteModeStats>,
179    pub route_overrides: Vec<RouteOverrideStats>,
180    pub typed_route_overrides: Vec<TypedRouteOverrideStats>,
181    pub route_weights: Vec<RouteWeightStats>,
182    pub route_priorities: Vec<RoutePriorityStats>,
183    pub queues: QueueRuntimeStats,
184    pub reliable: ReliableRuntimeStats,
185    pub discovery: DiscoveryRuntimeStats,
186    pub total_handler_failures: u64,
187    pub total_handler_retries: u64,
188}