diff --git a/src/lqos.example b/src/lqos.example index c3f67847..58821275 100644 --- a/src/lqos.example +++ b/src/lqos.example @@ -70,6 +70,10 @@ netflow_enabled = false # netflow_version = 9 do_not_track_subnets = [ "192.168.66.0/24" ] +[byte_counters] +# Optional cumulative byte counters for nodes and circuits, exposed by lqos_api. +enabled = false + [integration_common] circuit_name_as_address = false queue_refresh_interval_mins = 30 diff --git a/src/rust/lqos_config/src/etc/v15/byte_counters.rs b/src/rust/lqos_config/src/etc/v15/byte_counters.rs new file mode 100644 index 00000000..73c96fc2 --- /dev/null +++ b/src/rust/lqos_config/src/etc/v15/byte_counters.rs @@ -0,0 +1,38 @@ +//! Configuration for optional cumulative byte counters. +//! +//! When enabled, `lqosd` accumulates per-circuit byte totals from the +//! one-second throughput tracker and exposes cumulative per-circuit and +//! per-node counters on the local bus. + +use allocative::Allocative; +use serde::{Deserialize, Serialize}; + +/// Configuration for optional cumulative byte counters. +#[derive(Clone, Default, Serialize, Deserialize, Debug, PartialEq, Allocative)] +pub struct ByteCountersConfig { + /// Enables cumulative per-circuit and per-node byte counters. + /// + /// Defaults to `false` when the `[byte_counters]` section is absent so + /// existing configuration files keep their current behavior. + #[serde(default)] + pub enabled: bool, +} + +#[cfg(test)] +mod tests { + use super::ByteCountersConfig; + + #[test] + fn absent_section_defaults_to_disabled() { + let config: ByteCountersConfig = + toml::from_str("").expect("empty byte_counters section should parse"); + assert!(!config.enabled); + } + + #[test] + fn section_parses_enabled_flag() { + let config: ByteCountersConfig = + toml::from_str("enabled = true").expect("enabled flag should parse"); + assert!(config.enabled); + } +} diff --git a/src/rust/lqos_config/src/etc/v15/example.toml b/src/rust/lqos_config/src/etc/v15/example.toml index d440f448..3abdc404 100644 --- a/src/rust/lqos_config/src/etc/v15/example.toml +++ b/src/rust/lqos_config/src/etc/v15/example.toml @@ -102,6 +102,10 @@ collation_period_seconds = 10 license_key = "(data)" uisp_reporting_interval_seconds = 300 +[byte_counters] +# Optional cumulative byte counters for nodes and circuits, exposed by lqos_api. +enabled = false + [local_api] bearer_token = "" diff --git a/src/rust/lqos_config/src/etc/v15/mod.rs b/src/rust/lqos_config/src/etc/v15/mod.rs index b5ab63a3..baeef38c 100644 --- a/src/rust/lqos_config/src/etc/v15/mod.rs +++ b/src/rust/lqos_config/src/etc/v15/mod.rs @@ -5,6 +5,7 @@ pub use top_config::Config; pub use top_config::RttThresholds; pub use top_config::{SslConfig, normalize_external_hostname}; mod bridge; +mod byte_counters; mod dynamic_circuits; mod flows; pub mod influxdb; diff --git a/src/rust/lqos_config/src/etc/v15/top_config.rs b/src/rust/lqos_config/src/etc/v15/top_config.rs index cfc98f59..9d9feefb 100644 --- a/src/rust/lqos_config/src/etc/v15/top_config.rs +++ b/src/rust/lqos_config/src/etc/v15/top_config.rs @@ -277,6 +277,13 @@ pub struct Config { /// Enable per-ASN TemporalHeatmap collection. #[serde(default = "default_true")] pub enable_asn_heatmaps: bool, + + /// Optional cumulative byte counters for nodes and circuits. + /// + /// The section is optional so older configuration files keep working + /// unchanged; counters are disabled when it is absent. + #[serde(default)] + pub byte_counters: super::byte_counters::ByteCountersConfig, } impl Config { @@ -482,6 +489,7 @@ impl Default for Config { enable_circuit_heatmaps: true, enable_site_heatmaps: true, enable_asn_heatmaps: true, + byte_counters: super::byte_counters::ByteCountersConfig::default(), } } } -- knotmirror 0.0.1 From d52e3a6dbbdad9d84470fc6c26dd9ee7e806c7ab Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 12:29:22 -0500 Subject: [PATCH 2/9] Feat: add byte counters bus request and response Adds GetByteCounters with cumulative per-node and per-circuit byte counter payloads. The request is read-only, so it fails fast on timeout and needs no daemon-side mutation. --- src/rust/lqos_bus/src/bus/request.rs | 5 ++++ src/rust/lqos_bus/src/bus/response.rs | 40 +++++++++++++++++++++++++++ src/rust/lqos_bus/src/lib.rs | 16 +++++------ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/rust/lqos_bus/src/bus/request.rs b/src/rust/lqos_bus/src/bus/request.rs index ac2b9093..af77a416 100644 --- a/src/rust/lqos_bus/src/bus/request.rs +++ b/src/rust/lqos_bus/src/bus/request.rs @@ -633,6 +633,9 @@ pub enum BusRequest { /// Retrieve queue marks/drops totals GetQueueStatsTotal, + /// Retrieve cumulative byte counters for nodes and circuits. + GetByteCounters, + /// Retrieve current top-level QoO history. GetQoo, @@ -783,6 +786,7 @@ impl BusRequest { Self::GetProtocolFlowTimeline { .. } => "GetProtocolFlowTimeline", Self::GetSchedulerDetails => "GetSchedulerDetails", Self::GetQueueStatsTotal => "GetQueueStatsTotal", + Self::GetByteCounters => "GetByteCounters", Self::GetCircuitCapacity => "GetCircuitCapacity", Self::GetTreeCapacity => "GetTreeCapacity", Self::GetRetransmitSummary => "GetRetransmitSummary", @@ -862,6 +866,7 @@ impl BusRequest { | Self::GetProtocolFlowTimeline { .. } | Self::GetSchedulerDetails | Self::GetQueueStatsTotal + | Self::GetByteCounters | Self::GetCircuitCapacity | Self::GetTreeCapacity | Self::GetRetransmitSummary diff --git a/src/rust/lqos_bus/src/bus/response.rs b/src/rust/lqos_bus/src/bus/response.rs index ceb83bc9..ea6d0b1b 100644 --- a/src/rust/lqos_bus/src/bus/response.rs +++ b/src/rust/lqos_bus/src/bus/response.rs @@ -538,6 +538,43 @@ pub struct QueueStatsTotal { pub drops: DownUpOrder, } +/// Cumulative byte counter for one network node. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Allocative)] +pub struct NodeByteCounters { + /// Optional stable node identifier from `network.json` metadata. + pub node_id: Option, + /// Node name as it appears in `network.json`. + pub name: String, + /// Cumulative bytes (down/up) since `lqosd` started tracking. + /// + /// Node totals include traffic from descendant nodes. + pub bytes: DownUpOrder, +} + +/// Cumulative byte counter for one circuit. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Allocative)] +pub struct CircuitByteCounters { + /// Circuit ID from `ShapedDevices.csv` or a dynamic circuit. + pub circuit_id: String, + /// Circuit name from `ShapedDevices.csv` or a dynamic circuit. + pub circuit_name: String, + /// Effective parent node for this circuit. + pub parent_node: String, + /// Cumulative bytes (down/up) since `lqosd` started tracking. + pub bytes: DownUpOrder, +} + +/// Cumulative byte counters for network nodes and circuits. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Allocative)] +pub struct ByteCountersSnapshot { + /// Whether byte counters are enabled in configuration. + pub enabled: bool, + /// Cumulative counters for every node in the runtime network tree. + pub nodes: Vec, + /// Cumulative counters for circuits with recorded traffic. + pub circuits: Vec, +} + /// Circuit capacity utilization row #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Allocative)] pub struct CircuitCapacityRow { @@ -867,6 +904,9 @@ pub enum BusResponse { /// Queue stats totals (marks/drops) QueueStatsTotal(QueueStatsTotal), + /// Cumulative byte counters for nodes and circuits. + ByteCounters(ByteCountersSnapshot), + /// Current QoO data. Qoo(Option), diff --git a/src/rust/lqos_bus/src/lib.rs b/src/rust/lqos_bus/src/lib.rs index f8860b03..7a208a14 100644 --- a/src/rust/lqos_bus/src/lib.rs +++ b/src/rust/lqos_bus/src/lib.rs @@ -29,14 +29,14 @@ pub use ip_stats::{ }; mod tc_handle; pub use bus::response::{ - AsnHeatmapData, AsnListEntry, BakeryStatsSnapshot, CircuitCapacityRow, CircuitCount, - CircuitHeatmapData, CircuitRollup, CountryListEntry, DeviceCounts, ExecutiveSummaryHeader, - FlowMapPoint, FlowTimelineEntry, InsightLicenseSummary, LtsCapabilitiesSummary, NodeCapacity, - OverrideMutationResult, ProtocolListEntry, QooData, QueueStatsTotal, RetransmitSummary, - SchedulerDetails, SearchResultEntry, SiteHeatmapData, StormguardDebugDirection, - StormguardDebugEntry, StormguardRuntimeSettings, StormguardRuntimeStatus, - TreeGuardRuntimeNodeBranchSnapshot, TreeGuardRuntimeNodeOperationSnapshot, UrgentIssue, - WarningLevel, + AsnHeatmapData, AsnListEntry, BakeryStatsSnapshot, ByteCountersSnapshot, CircuitByteCounters, + CircuitCapacityRow, CircuitCount, CircuitHeatmapData, CircuitRollup, CountryListEntry, + DeviceCounts, ExecutiveSummaryHeader, FlowMapPoint, FlowTimelineEntry, InsightLicenseSummary, + LtsCapabilitiesSummary, NodeByteCounters, NodeCapacity, OverrideMutationResult, + ProtocolListEntry, QooData, QueueStatsTotal, RetransmitSummary, SchedulerDetails, + SearchResultEntry, SiteHeatmapData, StormguardDebugDirection, StormguardDebugEntry, + StormguardRuntimeSettings, StormguardRuntimeStatus, TreeGuardRuntimeNodeBranchSnapshot, + TreeGuardRuntimeNodeOperationSnapshot, UrgentIssue, WarningLevel, }; pub use bus::{ BUS_SOCKET_PATH, BakeryCapacityReportInterface, BlackboardSystem, BusClientError, BusReply, -- knotmirror 0.0.1 From ff596549916ee60b4b0632f57e61ca11e783dd1b Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 12:29:22 -0500 Subject: [PATCH 3/9] Feat: accumulate and expose cumulative circuit byte counters When [byte_counters] enabled = true, the one-second throughput tracker batches each circuit's actual-byte deltas into a cumulative counter map. Node totals are rolled up through the runtime network tree when the bus is queried, so node values include descendants. Counters are in-memory and reset when lqosd restarts. --- src/rust/lqosd/src/byte_counters.rs | 266 ++++++++++++++++++ src/rust/lqosd/src/main.rs | 3 + .../src/throughput_tracker/tracking_data.rs | 34 ++- 3 files changed, 293 insertions(+), 10 deletions(-) create mode 100644 src/rust/lqosd/src/byte_counters.rs diff --git a/src/rust/lqosd/src/byte_counters.rs b/src/rust/lqosd/src/byte_counters.rs new file mode 100644 index 00000000..12a4b99b --- /dev/null +++ b/src/rust/lqosd/src/byte_counters.rs @@ -0,0 +1,266 @@ +//! Optional cumulative byte counters for circuits and network nodes. +//! +//! When `[byte_counters] enabled = true` is set in `/etc/lqos.conf`, the +//! one-second throughput tracker feeds per-circuit byte deltas into this +//! module. Counters are cumulative since `lqosd` started and are not +//! persisted across restarts. +//! +//! Only per-circuit totals are stored. Node totals are derived when a +//! snapshot is requested by walking each circuit's effective parent node +//! through the runtime network tree, so node totals include descendants. + +use fxhash::FxHashMap; +use lqos_bus::{ByteCountersSnapshot, CircuitByteCounters, NodeByteCounters}; +use lqos_config::NetworkJson; +use lqos_utils::units::DownUpOrder; +use once_cell::sync::Lazy; +use parking_lot::RwLock; +use std::sync::atomic::{AtomicBool, Ordering}; + +/// Cumulative bytes keyed by circuit hash. +static CIRCUIT_BYTES: Lazy>>> = + Lazy::new(|| RwLock::new(FxHashMap::default())); + +/// Whether byte counter collection is enabled. +static ENABLED: AtomicBool = AtomicBool::new(false); + +/// Enables or disables byte counter collection. +/// +/// Side effects: updates the global collection flag. Counters recorded before +/// a disable are kept until the process restarts. +pub(crate) fn set_enabled(enabled: bool) { + ENABLED.store(enabled, Ordering::Relaxed); +} + +/// Returns true when byte counter collection is enabled. +pub(crate) fn is_enabled() -> bool { + ENABLED.load(Ordering::Relaxed) +} + +/// Adds one cycle of per-circuit byte deltas to the cumulative counters. +/// +/// Side effects: mutates the shared cumulative counter map. +pub(crate) fn add_batch(deltas: FxHashMap>) { + if deltas.is_empty() { + return; + } + merge(&mut CIRCUIT_BYTES.write(), deltas); +} + +/// Merges per-circuit deltas into a cumulative counter map. +fn merge( + counters: &mut FxHashMap>, + deltas: FxHashMap>, +) { + for (circuit_hash, bytes) in deltas { + counters.entry(circuit_hash).or_default().checked_add(bytes); + } +} + +/// Builds a cumulative byte counter snapshot for the bus. +/// +/// Side effects: acquires the counter read lock and the runtime network tree +/// read lock. +pub(crate) fn snapshot() -> ByteCountersSnapshot { + if !is_enabled() { + return ByteCountersSnapshot { + enabled: false, + nodes: Vec::new(), + circuits: Vec::new(), + }; + } + + let circuit_bytes: Vec<(i64, DownUpOrder)> = CIRCUIT_BYTES + .read() + .iter() + .map(|(circuit_hash, bytes)| (*circuit_hash, *bytes)) + .collect(); + + let catalog = lqos_network_devices::network_devices_catalog(); + lqos_network_devices::with_network_json_read(|tree| { + rollup(tree, &circuit_bytes, |circuit_hash| { + let device = catalog.device_by_hashes(None, Some(circuit_hash))?; + Some(CircuitDescriptor { + circuit_id: device.circuit_id.clone(), + circuit_name: device.circuit_name.clone(), + parent_node: device.parent_node.clone(), + }) + }) + }) +} + +/// Identity fields for one circuit, resolved from the shaped-devices catalog. +struct CircuitDescriptor { + circuit_id: String, + circuit_name: String, + parent_node: String, +} + +/// Rolls circuit totals up the network tree and formats a bus snapshot. +/// +/// Node totals include every descendant circuit. Circuits whose device or +/// parent node cannot be resolved are omitted from both lists. +fn rollup( + tree: &NetworkJson, + circuits: &[(i64, DownUpOrder)], + mut lookup: impl FnMut(i64) -> Option, +) -> ByteCountersSnapshot { + let mut node_totals = vec![DownUpOrder::zeroed(); tree.nodes.len()]; + let mut node_index: FxHashMap<&str, usize> = FxHashMap::default(); + for (index, node) in tree.nodes.iter().enumerate() { + node_index.entry(node.name.as_str()).or_insert(index); + } + + let mut circuit_rows = Vec::new(); + for (circuit_hash, bytes) in circuits { + let Some(descriptor) = lookup(*circuit_hash) else { + continue; + }; + let Some(&parent_index) = node_index.get(descriptor.parent_node.as_str()) else { + continue; + }; + for &index in &tree.nodes[parent_index].parents { + if let Some(total) = node_totals.get_mut(index) { + total.checked_add(*bytes); + } + } + circuit_rows.push(CircuitByteCounters { + circuit_id: descriptor.circuit_id, + circuit_name: descriptor.circuit_name, + parent_node: descriptor.parent_node, + bytes: *bytes, + }); + } + circuit_rows.sort_by(|a, b| a.circuit_id.cmp(&b.circuit_id)); + + let nodes = tree + .nodes + .iter() + .enumerate() + .map(|(index, node)| NodeByteCounters { + node_id: node.id.clone(), + name: node.name.clone(), + bytes: node_totals[index], + }) + .collect(); + + ByteCountersSnapshot { + enabled: true, + nodes, + circuits: circuit_rows, + } +} + +#[cfg(test)] +mod tests { + use super::*; + use lqos_config::NetworkJsonNode; + use lqos_utils::rtt::RttBuffer; + + fn node( + name: &str, + id: Option<&str>, + parents: Vec, + immediate_parent: Option, + ) -> NetworkJsonNode { + NetworkJsonNode { + name: name.to_string(), + id: id.map(str::to_string), + virtual_node: false, + max_throughput: (0.0, 0.0), + current_throughput: DownUpOrder::zeroed(), + current_packets: DownUpOrder::zeroed(), + current_tcp_packets: DownUpOrder::zeroed(), + current_udp_packets: DownUpOrder::zeroed(), + current_icmp_packets: DownUpOrder::zeroed(), + current_tcp_retransmits: DownUpOrder::zeroed(), + current_tcp_retransmit_packets: DownUpOrder::zeroed(), + current_rtt_flows: DownUpOrder::zeroed(), + current_marks: DownUpOrder::zeroed(), + current_drops: DownUpOrder::zeroed(), + rtt_buffer: RttBuffer::default(), + parents, + immediate_parent, + node_type: None, + latitude: None, + longitude: None, + active_attachment_name: None, + heatmap: None, + qoq_heatmap: None, + } + } + + fn descriptor(circuit_id: &str, parent_node: &str) -> Option { + Some(CircuitDescriptor { + circuit_id: circuit_id.to_string(), + circuit_name: format!("{circuit_id} name"), + parent_node: parent_node.to_string(), + }) + } + + fn test_tree() -> NetworkJson { + NetworkJson { + nodes: vec![ + node("Root", None, vec![0], None), + node("Site A", Some("site-a"), vec![0, 1], Some(0)), + node("Site A1", None, vec![0, 1, 2], Some(1)), + node("Site B", None, vec![0, 3], Some(0)), + ], + } + } + + #[test] + fn merge_accumulates_repeated_circuit_deltas() { + let mut counters = FxHashMap::default(); + merge( + &mut counters, + FxHashMap::from_iter([(7, DownUpOrder::new(100, 40))]), + ); + merge( + &mut counters, + FxHashMap::from_iter([(7, DownUpOrder::new(10, 5))]), + ); + + assert_eq!(counters.get(&7), Some(&DownUpOrder::new(110, 45))); + } + + #[test] + fn rollup_includes_descendant_bytes_in_ancestor_totals() { + let circuits = vec![(1, DownUpOrder::new(100, 0)), (2, DownUpOrder::new(0, 50))]; + let snapshot = rollup(&test_tree(), &circuits, |circuit_hash| match circuit_hash { + 1 => descriptor("circuit-1", "Site A1"), + 2 => descriptor("circuit-2", "Site A"), + _ => None, + }); + + assert!(snapshot.enabled); + assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(100, 50)); + assert_eq!(snapshot.nodes[1].bytes, DownUpOrder::new(100, 50)); + assert_eq!(snapshot.nodes[2].bytes, DownUpOrder::new(100, 0)); + assert_eq!(snapshot.nodes[3].bytes, DownUpOrder::new(0, 0)); + assert_eq!(snapshot.nodes[1].node_id.as_deref(), Some("site-a")); + assert_eq!(snapshot.circuits.len(), 2); + assert_eq!(snapshot.circuits[0].circuit_id, "circuit-1"); + assert_eq!(snapshot.circuits[0].parent_node, "Site A1"); + assert_eq!(snapshot.circuits[1].bytes, DownUpOrder::new(0, 50)); + } + + #[test] + fn rollup_skips_unresolved_circuits_and_parents() { + let circuits = vec![ + (1, DownUpOrder::new(100, 0)), + (2, DownUpOrder::new(10, 10)), + (3, DownUpOrder::new(5, 5)), + ]; + let snapshot = rollup(&test_tree(), &circuits, |circuit_hash| match circuit_hash { + 1 => descriptor("circuit-1", "Site B"), + 2 => None, + _ => descriptor("circuit-3", "Missing Node"), + }); + + assert_eq!(snapshot.circuits.len(), 1); + assert_eq!(snapshot.circuits[0].circuit_id, "circuit-1"); + assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(100, 0)); + assert_eq!(snapshot.nodes[3].bytes, DownUpOrder::new(100, 0)); + } +} diff --git a/src/rust/lqosd/src/main.rs b/src/rust/lqosd/src/main.rs index 1676fab6..29fe5ac0 100644 --- a/src/rust/lqosd/src/main.rs +++ b/src/rust/lqosd/src/main.rs @@ -4,6 +4,7 @@ #![deny(clippy::unwrap_used)] mod blackboard; +mod byte_counters; mod dynamic_circuits; mod file_lock; mod ip_mapping; @@ -216,6 +217,7 @@ fn main() -> Result<()> { // Load config let config = lqos_config::load_config()?; + byte_counters::set_enabled(config.byte_counters.enabled); let web_config = config.clone(); let radius_accounting_config = config.radius_accounting.clone(); shaping_runtime::mark_starting("LibreQoS is starting shaping services."); @@ -1209,6 +1211,7 @@ fn handle_bus_requests(requests: &[BusRequest], responses: &mut Vec let totals = queue_stats_total_data(); BusResponse::QueueStatsTotal(totals) } + BusRequest::GetByteCounters => BusResponse::ByteCounters(byte_counters::snapshot()), BusRequest::GetQoo => { let data = node_manager::local_api::executive::qoo_global(); BusResponse::Qoo(Some(data)) diff --git a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs index d94cca13..364c4956 100644 --- a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs +++ b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs @@ -661,6 +661,9 @@ impl ThroughputTracker { let mut changed_circuits = HashSet::new(); + let byte_counters_enabled = crate::byte_counters::is_enabled(); + let mut byte_counter_deltas: FxHashMap> = FxHashMap::default(); + let self_cycle = self.cycle.load(std::sync::atomic::Ordering::Relaxed); let catalog = lqos_network_devices::network_devices_catalog(); let mut raw_data = self.raw_data.lock(); @@ -768,9 +771,25 @@ impl ThroughputTracker { } if entry.packets != entry.prev_packets { entry.most_recent_cycle = self_cycle; + let actual_bytes_delta = DownUpOrder::new( + entry + .actual_bytes + .down + .saturating_sub(entry.prev_actual_bytes.down), + entry + .actual_bytes + .up + .saturating_sub(entry.prev_actual_bytes.up), + ); // Call to Bakery Update for existing traffic if let Some(circuit_hash) = entry.circuit_hash { changed_circuits.insert(circuit_hash); + if byte_counters_enabled { + byte_counter_deltas + .entry(circuit_hash) + .or_default() + .checked_add(actual_bytes_delta); + } } record_dynamic_observation( @@ -795,16 +814,7 @@ impl ThroughputTracker { if let Some(parents) = &entry.network_json_parents { net_json_calc.add_throughput_cycle( parents, - ( - entry - .actual_bytes - .down - .saturating_sub(entry.prev_actual_bytes.down), - entry - .actual_bytes - .up - .saturating_sub(entry.prev_actual_bytes.up), - ), + (actual_bytes_delta.down, actual_bytes_delta.up), ( entry.packets.down.saturating_sub(entry.prev_packets.down), entry.packets.up.saturating_sub(entry.prev_packets.up), @@ -934,6 +944,10 @@ impl ThroughputTracker { } }); + if byte_counters_enabled { + crate::byte_counters::add_batch(byte_counter_deltas); + } + if !observations.is_empty() { lqos_network_devices::report_observations(&observations); } -- knotmirror 0.0.1 From 94ed100feab368468f48ebfb0c3f9b191f09005b Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 12:29:26 -0500 Subject: [PATCH 4/9] Docs: document byte counters configuration and API endpoint Documents the optional [byte_counters] section, counter reset semantics, subtree-inclusive node totals, and the GET /byte_counters endpoint in English and Spanish. --- docs-es/v2.0/api-es.md | 3 +++ docs-es/v2.0/configuration-advanced-es.md | 17 +++++++++++++++++ docs/v2.0/api.md | 3 +++ docs/v2.0/configuration-advanced.md | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/docs-es/v2.0/api-es.md b/docs-es/v2.0/api-es.md index 9bb97dd7..65600d8c 100644 --- a/docs-es/v2.0/api-es.md +++ b/docs-es/v2.0/api-es.md @@ -121,9 +121,12 @@ Endpoints representativos: - `GET /search` - `GET /current_throughput` - `GET /queue_stats_total` +- `GET /byte_counters` - `GET /warnings` - `GET /urgent`, `GET /urgent/status` +`GET /byte_counters` devuelve contadores de bytes acumulados por nodo y por circuito cuando `[byte_counters] enabled = true` está configurado en `/etc/lqos.conf`. Los valores son acumulados desde que `lqosd` inició, incluyen el tráfico descendiente en los nodos y se reinician cuando `lqosd` se reinicia. Consulte [Configuración avanzada](configuration-advanced-es.md). + ### 5) Operaciones de control y reload Disparar acciones de control operativo cuando sea necesario. diff --git a/docs-es/v2.0/configuration-advanced-es.md b/docs-es/v2.0/configuration-advanced-es.md index 0df8da6a..88c44f46 100644 --- a/docs-es/v2.0/configuration-advanced-es.md +++ b/docs-es/v2.0/configuration-advanced-es.md @@ -62,6 +62,23 @@ netflow_version = 5 do_not_track_subnets = ["192.168.0.0/16"] ``` +### Contadores de bytes (opcional) + +LibreQoS puede mantener contadores de bytes acumulados por circuito y por nodo de red para la contabilidad de uso de datos, y exponerlos a través de `lqos_api`. La función está deshabilitada por defecto. Para habilitarla, agregue la siguiente sección a `/etc/lqos.conf` y reinicie `lqosd`: + +```toml +[byte_counters] +enabled = true +``` + +- Los contadores acumulan el tráfico medido por el rastreador de throughput de un segundo. +- Los valores son bytes realmente transmitidos, no bytes descartados por el shaping. +- Los valores son acumulados desde que `lqosd` inició y se reinician cuando `lqosd` se reinicia. +- Los valores de un nodo incluyen el tráfico de todos sus nodos descendientes. +- Solo se listan los circuitos con tráfico registrado. + +Con los contadores habilitados, `GET /byte_counters` en la API del nodo devuelve los valores actuales. Consulte [API del nodo LibreQoS](api-es.md). + ### Contabilidad RADIUS (opcional) LibreQoS acepta una sección opcional `[radius_accounting]` para definir clientes NAS de confianza. Cuando está habilitada, `lqosd` inicia un servicio de contabilidad RADIUS, verifica paquetes de los clientes configurados, envía paquetes Accounting-Response para solicitudes aceptadas y mantiene el estado de sesión decodificado en memoria. Cuando `radius_accounting.dynamic_circuit_application.enabled` y la opción global `dynamic_circuits.enabled` están habilitadas, las sesiones Start e Interim-Update aptas se envían a la ruta de circuitos dinámicos. diff --git a/docs/v2.0/api.md b/docs/v2.0/api.md index 3f564200..dfc33982 100644 --- a/docs/v2.0/api.md +++ b/docs/v2.0/api.md @@ -121,9 +121,12 @@ Representative endpoints: - `GET /search` - `GET /current_throughput` - `GET /queue_stats_total` +- `GET /byte_counters` - `GET /warnings` - `GET /urgent`, `GET /urgent/status` +`GET /byte_counters` returns cumulative per-node and per-circuit byte counters when `[byte_counters] enabled = true` is set in `/etc/lqos.conf`. Values are cumulative since `lqosd` started, include descendant traffic for nodes, and reset when `lqosd` restarts. See [Advanced Configuration](configuration-advanced.md). + ### 5) Control and Reload Operations Trigger operational control actions when needed. diff --git a/docs/v2.0/configuration-advanced.md b/docs/v2.0/configuration-advanced.md index 7672585e..2c075db4 100644 --- a/docs/v2.0/configuration-advanced.md +++ b/docs/v2.0/configuration-advanced.md @@ -64,6 +64,23 @@ netflow_version = 5 do_not_track_subnets = ["192.168.0.0/16"] ``` +#### Byte counters (optional) + +LibreQoS can keep cumulative byte counters per circuit and per network node for data-usage accounting, and expose them through `lqos_api`. The feature is disabled by default. To enable it, add the following section to `/etc/lqos.conf` and restart `lqosd`: + +```toml +[byte_counters] +enabled = true +``` + +- Counters accumulate the traffic measured by the one-second throughput tracker. +- Values are actual transmitted bytes, not bytes dropped by shaping. +- Values are cumulative since `lqosd` started and reset when `lqosd` restarts. +- Node values include traffic from all descendant nodes. +- Only circuits with recorded traffic are listed. + +With the counters enabled, `GET /byte_counters` on the Node API returns the current values. See [LibreQoS Node API](api.md). + #### On-a-stick mode queue mapping (single interface) When running on-a-stick mode, LibreQoS splits available TX queues in half: -- knotmirror 0.0.1 From b19bf9ec14e557403d570516fdcfd5f6f27285f4 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 12:49:28 -0500 Subject: [PATCH 5/9] Fix: keep byte counter identity across configuration changes Captures circuit identity and parent when a counter first receives traffic, so circuits removed from configuration keep contributing to their last known parent instead of dropping out of node totals. Resolves parent nodes by stable id before name, fills descriptors at read time, skips zero-byte deltas, and documents the counter lock ordering. Expands tests for the absent config section, disabled snapshots, root-attached circuits, id-preferred node resolution, and stable circuit ordering. --- docs-es/v2.0/configuration-advanced-es.md | 4 +- docs/v2.0/configuration-advanced.md | 4 +- .../lqos_config/src/etc/v15/byte_counters.rs | 2 +- .../lqos_config/src/etc/v15/top_config.rs | 10 + .../src/combined_catalog.rs | 13 + src/rust/lqosd/src/byte_counters.rs | 301 +++++++++++++----- .../src/throughput_tracker/tracking_data.rs | 16 +- 7 files changed, 257 insertions(+), 93 deletions(-) diff --git a/docs-es/v2.0/configuration-advanced-es.md b/docs-es/v2.0/configuration-advanced-es.md index 88c44f46..6f26f0ab 100644 --- a/docs-es/v2.0/configuration-advanced-es.md +++ b/docs-es/v2.0/configuration-advanced-es.md @@ -71,11 +71,11 @@ LibreQoS puede mantener contadores de bytes acumulados por circuito y por nodo d enabled = true ``` -- Los contadores acumulan el tráfico medido por el rastreador de throughput de un segundo. - Los valores son bytes realmente transmitidos, no bytes descartados por el shaping. -- Los valores son acumulados desde que `lqosd` inició y se reinician cuando `lqosd` se reinicia. +- Los valores se acumulan mientras `lqosd` se ejecuta y se reinician cuando `lqosd` se reinicia. - Los valores de un nodo incluyen el tráfico de todos sus nodos descendientes. - Solo se listan los circuitos con tráfico registrado. +- Los circuitos eliminados de `ShapedDevices.csv` siguen aportando sus bytes acumulados a su último nodo principal conocido mientras `lqosd` se ejecuta. Con los contadores habilitados, `GET /byte_counters` en la API del nodo devuelve los valores actuales. Consulte [API del nodo LibreQoS](api-es.md). diff --git a/docs/v2.0/configuration-advanced.md b/docs/v2.0/configuration-advanced.md index 2c075db4..02508517 100644 --- a/docs/v2.0/configuration-advanced.md +++ b/docs/v2.0/configuration-advanced.md @@ -73,11 +73,11 @@ LibreQoS can keep cumulative byte counters per circuit and per network node for enabled = true ``` -- Counters accumulate the traffic measured by the one-second throughput tracker. - Values are actual transmitted bytes, not bytes dropped by shaping. -- Values are cumulative since `lqosd` started and reset when `lqosd` restarts. +- Values accumulate while `lqosd` runs and reset when `lqosd` restarts. - Node values include traffic from all descendant nodes. - Only circuits with recorded traffic are listed. +- Circuits removed from `ShapedDevices.csv` keep contributing their accumulated bytes to their last known parent while `lqosd` runs. With the counters enabled, `GET /byte_counters` on the Node API returns the current values. See [LibreQoS Node API](api.md). diff --git a/src/rust/lqos_config/src/etc/v15/byte_counters.rs b/src/rust/lqos_config/src/etc/v15/byte_counters.rs index 73c96fc2..6c6677c5 100644 --- a/src/rust/lqos_config/src/etc/v15/byte_counters.rs +++ b/src/rust/lqos_config/src/etc/v15/byte_counters.rs @@ -23,7 +23,7 @@ mod tests { use super::ByteCountersConfig; #[test] - fn absent_section_defaults_to_disabled() { + fn empty_section_defaults_to_disabled() { let config: ByteCountersConfig = toml::from_str("").expect("empty byte_counters section should parse"); assert!(!config.enabled); diff --git a/src/rust/lqos_config/src/etc/v15/top_config.rs b/src/rust/lqos_config/src/etc/v15/top_config.rs index 9d9feefb..6cb4294d 100644 --- a/src/rust/lqos_config/src/etc/v15/top_config.rs +++ b/src/rust/lqos_config/src/etc/v15/top_config.rs @@ -722,6 +722,16 @@ mod test { assert_eq!(config.local_api, Default::default()); } + #[test] + fn byte_counters_config_defaults_when_section_is_absent() { + let legacy = remove_sections(include_str!("example.toml"), &["byte_counters"]); + let config = + Config::load_from_string(&legacy).expect("Cannot read config without byte_counters"); + + assert_eq!(config.byte_counters, Default::default()); + assert!(!config.byte_counters.enabled); + } + #[test] fn load_example_legacy_spylnx() { let legacy = include_str!("example.toml") diff --git a/src/rust/lqos_network_devices/src/combined_catalog.rs b/src/rust/lqos_network_devices/src/combined_catalog.rs index 83c92660..62688327 100644 --- a/src/rust/lqos_network_devices/src/combined_catalog.rs +++ b/src/rust/lqos_network_devices/src/combined_catalog.rs @@ -225,6 +225,19 @@ mod tests { ); } + #[test] + fn device_by_hashes_falls_back_to_dynamic_circuit() { + let mut dynamic = device(42); + dynamic.circuit_id = "dyn-circuit".to_string(); + + let catalog = catalog(vec![], vec![dynamic]); + let resolved = catalog + .device_by_hashes(None, Some(42)) + .expect("dynamic circuit should resolve by circuit hash"); + + assert_eq!(resolved.circuit_id, "dyn-circuit"); + } + #[test] fn mapped_circuit_count_ignores_unmapped_rows_and_counts_ipv6() { let mut unmapped = device(20); diff --git a/src/rust/lqosd/src/byte_counters.rs b/src/rust/lqosd/src/byte_counters.rs index 12a4b99b..347fbbf7 100644 --- a/src/rust/lqosd/src/byte_counters.rs +++ b/src/rust/lqosd/src/byte_counters.rs @@ -5,20 +5,24 @@ //! module. Counters are cumulative since `lqosd` started and are not //! persisted across restarts. //! -//! Only per-circuit totals are stored. Node totals are derived when a -//! snapshot is requested by walking each circuit's effective parent node -//! through the runtime network tree, so node totals include descendants. +//! Only per-circuit totals and their last-known identity are stored. Node +//! totals are derived when a snapshot is requested by walking each circuit's +//! parent node through the runtime network tree, so node totals include +//! descendants. Circuit identity is captured when a counter first receives +//! traffic, so circuits removed from configuration keep contributing their +//! accumulated bytes to their last known parent while `lqosd` runs. use fxhash::FxHashMap; use lqos_bus::{ByteCountersSnapshot, CircuitByteCounters, NodeByteCounters}; use lqos_config::NetworkJson; +use lqos_network_devices::NetworkDevicesCatalog; use lqos_utils::units::DownUpOrder; use once_cell::sync::Lazy; use parking_lot::RwLock; use std::sync::atomic::{AtomicBool, Ordering}; -/// Cumulative bytes keyed by circuit hash. -static CIRCUIT_BYTES: Lazy>>> = +/// Cumulative bytes and last-known identity keyed by circuit hash. +static CIRCUIT_BYTES: Lazy>> = Lazy::new(|| RwLock::new(FxHashMap::default())); /// Whether byte counter collection is enabled. @@ -39,28 +43,76 @@ pub(crate) fn is_enabled() -> bool { /// Adds one cycle of per-circuit byte deltas to the cumulative counters. /// +/// New circuits capture their identity from `catalog` on first sight. +/// /// Side effects: mutates the shared cumulative counter map. -pub(crate) fn add_batch(deltas: FxHashMap>) { +pub(crate) fn add_batch(deltas: FxHashMap>, catalog: &NetworkDevicesCatalog) { if deltas.is_empty() { return; } - merge(&mut CIRCUIT_BYTES.write(), deltas); + apply_deltas(&mut CIRCUIT_BYTES.write(), deltas, |circuit_hash| { + describe_circuit(catalog, circuit_hash) + }); } -/// Merges per-circuit deltas into a cumulative counter map. -fn merge( - counters: &mut FxHashMap>, +/// Merges per-circuit deltas into a cumulative counter map, capturing identity +/// through `describe` when a circuit is first seen. +fn apply_deltas( + counters: &mut FxHashMap, deltas: FxHashMap>, + describe: impl Fn(i64) -> Option, ) { for (circuit_hash, bytes) in deltas { - counters.entry(circuit_hash).or_default().checked_add(bytes); + let counter = counters.entry(circuit_hash).or_default(); + if counter.descriptor.is_none() { + counter.descriptor = describe(circuit_hash); + } + counter.bytes.checked_add(bytes); } } +/// Fills descriptors for counters that could not resolve identity when they +/// were first recorded, for example because the catalog snapshot was stale. +/// +/// Side effects: mutates the shared cumulative counter map. +fn fill_missing_descriptors() { + if CIRCUIT_BYTES + .read() + .values() + .all(|counter| counter.descriptor.is_some()) + { + return; + } + + let catalog = lqos_network_devices::network_devices_catalog(); + let mut counters = CIRCUIT_BYTES.write(); + for (circuit_hash, counter) in counters.iter_mut() { + if counter.descriptor.is_none() { + counter.descriptor = describe_circuit(&catalog, *circuit_hash); + } + } +} + +/// Resolves one circuit's identity fields from the combined device catalog. +fn describe_circuit( + catalog: &NetworkDevicesCatalog, + circuit_hash: i64, +) -> Option { + let device = catalog.device_by_hashes(None, Some(circuit_hash))?; + Some(CircuitDescriptor { + circuit_id: device.circuit_id.clone(), + circuit_name: device.circuit_name.clone(), + parent_node: device.parent_node.clone(), + parent_node_id: device.parent_node_id.clone(), + }) +} + /// Builds a cumulative byte counter snapshot for the bus. /// -/// Side effects: acquires the counter read lock and the runtime network tree -/// read lock. +/// Side effects: acquires the counter lock and the runtime network tree read +/// lock. Descriptors are resolved before the tree lock is taken so the lock +/// order stays `CIRCUIT_BYTES` then `NETWORK_JSON`, matching the tracker's +/// `NETWORK_JSON` write followed by `CIRCUIT_BYTES` write. pub(crate) fn snapshot() -> ByteCountersSnapshot { if !is_enabled() { return ByteCountersSnapshot { @@ -70,65 +122,70 @@ pub(crate) fn snapshot() -> ByteCountersSnapshot { }; } - let circuit_bytes: Vec<(i64, DownUpOrder)> = CIRCUIT_BYTES - .read() - .iter() - .map(|(circuit_hash, bytes)| (*circuit_hash, *bytes)) - .collect(); + fill_missing_descriptors(); - let catalog = lqos_network_devices::network_devices_catalog(); - lqos_network_devices::with_network_json_read(|tree| { - rollup(tree, &circuit_bytes, |circuit_hash| { - let device = catalog.device_by_hashes(None, Some(circuit_hash))?; - Some(CircuitDescriptor { - circuit_id: device.circuit_id.clone(), - circuit_name: device.circuit_name.clone(), - parent_node: device.parent_node.clone(), - }) - }) - }) + let counters: Vec = CIRCUIT_BYTES.read().values().cloned().collect(); + + lqos_network_devices::with_network_json_read(|tree| rollup(tree, &counters)) +} + +/// Cumulative bytes plus the identity captured when the circuit was first seen. +#[derive(Clone, Default)] +struct CircuitCounter { + bytes: DownUpOrder, + descriptor: Option, } -/// Identity fields for one circuit, resolved from the shaped-devices catalog. +/// Identity fields for one circuit, captured from the device catalog. +#[derive(Clone)] struct CircuitDescriptor { circuit_id: String, circuit_name: String, parent_node: String, + parent_node_id: Option, } /// Rolls circuit totals up the network tree and formats a bus snapshot. /// -/// Node totals include every descendant circuit. Circuits whose device or -/// parent node cannot be resolved are omitted from both lists. -fn rollup( - tree: &NetworkJson, - circuits: &[(i64, DownUpOrder)], - mut lookup: impl FnMut(i64) -> Option, -) -> ByteCountersSnapshot { +/// Node totals include every descendant circuit. Circuits keep a row even when +/// their parent node can no longer be resolved, but those bytes contribute to +/// no node total until the parent resolves again. +fn rollup(tree: &NetworkJson, counters: &[CircuitCounter]) -> ByteCountersSnapshot { let mut node_totals = vec![DownUpOrder::zeroed(); tree.nodes.len()]; - let mut node_index: FxHashMap<&str, usize> = FxHashMap::default(); + let mut node_by_name: FxHashMap<&str, usize> = FxHashMap::default(); + let mut node_by_id: FxHashMap<&str, usize> = FxHashMap::default(); for (index, node) in tree.nodes.iter().enumerate() { - node_index.entry(node.name.as_str()).or_insert(index); + node_by_name.entry(node.name.as_str()).or_insert(index); + if let Some(id) = node.id.as_deref() { + node_by_id.entry(id).or_insert(index); + } } let mut circuit_rows = Vec::new(); - for (circuit_hash, bytes) in circuits { - let Some(descriptor) = lookup(*circuit_hash) else { + for counter in counters { + let Some(descriptor) = counter.descriptor.as_ref() else { continue; }; - let Some(&parent_index) = node_index.get(descriptor.parent_node.as_str()) else { - continue; - }; - for &index in &tree.nodes[parent_index].parents { - if let Some(total) = node_totals.get_mut(index) { - total.checked_add(*bytes); + if let Some(parent_index) = resolve_parent_node(descriptor, &node_by_id, &node_by_name) { + let parent_node = &tree.nodes[parent_index]; + if parent_node.parents.is_empty() { + // The root node carries no parent list, so add its own traffic. + if let Some(total) = node_totals.get_mut(parent_index) { + total.checked_add(counter.bytes); + } + } else { + for &index in &parent_node.parents { + if let Some(total) = node_totals.get_mut(index) { + total.checked_add(counter.bytes); + } + } } } circuit_rows.push(CircuitByteCounters { - circuit_id: descriptor.circuit_id, - circuit_name: descriptor.circuit_name, - parent_node: descriptor.parent_node, - bytes: *bytes, + circuit_id: descriptor.circuit_id.clone(), + circuit_name: descriptor.circuit_name.clone(), + parent_node: descriptor.parent_node.clone(), + bytes: counter.bytes, }); } circuit_rows.sort_by(|a, b| a.circuit_id.cmp(&b.circuit_id)); @@ -151,6 +208,19 @@ fn rollup( } } +/// Resolves a circuit's parent node, preferring the stable node identifier. +fn resolve_parent_node( + descriptor: &CircuitDescriptor, + node_by_id: &FxHashMap<&str, usize>, + node_by_name: &FxHashMap<&str, usize>, +) -> Option { + descriptor + .parent_node_id + .as_deref() + .and_then(|id| node_by_id.get(id).copied()) + .or_else(|| node_by_name.get(descriptor.parent_node.as_str()).copied()) +} + #[cfg(test)] mod tests { use super::*; @@ -190,18 +260,26 @@ mod tests { } } - fn descriptor(circuit_id: &str, parent_node: &str) -> Option { - Some(CircuitDescriptor { + fn descriptor(circuit_id: &str, parent_node: &str) -> CircuitDescriptor { + CircuitDescriptor { circuit_id: circuit_id.to_string(), circuit_name: format!("{circuit_id} name"), parent_node: parent_node.to_string(), - }) + parent_node_id: None, + } + } + + fn counter(descriptor: CircuitDescriptor, bytes: DownUpOrder) -> CircuitCounter { + CircuitCounter { + bytes, + descriptor: Some(descriptor), + } } fn test_tree() -> NetworkJson { NetworkJson { nodes: vec![ - node("Root", None, vec![0], None), + node("Root", None, vec![], None), node("Site A", Some("site-a"), vec![0, 1], Some(0)), node("Site A1", None, vec![0, 1, 2], Some(1)), node("Site B", None, vec![0, 3], Some(0)), @@ -210,28 +288,34 @@ mod tests { } #[test] - fn merge_accumulates_repeated_circuit_deltas() { + fn apply_deltas_accumulates_repeated_circuit_deltas() { let mut counters = FxHashMap::default(); - merge( + apply_deltas( &mut counters, FxHashMap::from_iter([(7, DownUpOrder::new(100, 40))]), + |_| Some(descriptor("circuit-7", "Site A")), ); - merge( + apply_deltas( &mut counters, FxHashMap::from_iter([(7, DownUpOrder::new(10, 5))]), + |_| None, ); - assert_eq!(counters.get(&7), Some(&DownUpOrder::new(110, 45))); + let counter = counters.get(&7).expect("counter should exist"); + assert_eq!(counter.bytes, DownUpOrder::new(110, 45)); + assert_eq!( + counter.descriptor.as_ref().map(|d| d.circuit_id.as_str()), + Some("circuit-7") + ); } #[test] fn rollup_includes_descendant_bytes_in_ancestor_totals() { - let circuits = vec![(1, DownUpOrder::new(100, 0)), (2, DownUpOrder::new(0, 50))]; - let snapshot = rollup(&test_tree(), &circuits, |circuit_hash| match circuit_hash { - 1 => descriptor("circuit-1", "Site A1"), - 2 => descriptor("circuit-2", "Site A"), - _ => None, - }); + let counters = vec![ + counter(descriptor("circuit-1", "Site A1"), DownUpOrder::new(100, 0)), + counter(descriptor("circuit-2", "Site A"), DownUpOrder::new(0, 50)), + ]; + let snapshot = rollup(&test_tree(), &counters); assert!(snapshot.enabled); assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(100, 50)); @@ -246,21 +330,86 @@ mod tests { } #[test] - fn rollup_skips_unresolved_circuits_and_parents() { - let circuits = vec![ - (1, DownUpOrder::new(100, 0)), - (2, DownUpOrder::new(10, 10)), - (3, DownUpOrder::new(5, 5)), + fn rollup_keeps_circuit_rows_when_the_parent_node_is_missing() { + let counters = vec![ + counter(descriptor("circuit-1", "Site B"), DownUpOrder::new(100, 0)), + counter( + descriptor("circuit-2", "Missing Node"), + DownUpOrder::new(10, 10), + ), ]; - let snapshot = rollup(&test_tree(), &circuits, |circuit_hash| match circuit_hash { - 1 => descriptor("circuit-1", "Site B"), - 2 => None, - _ => descriptor("circuit-3", "Missing Node"), - }); + let snapshot = rollup(&test_tree(), &counters); - assert_eq!(snapshot.circuits.len(), 1); + assert_eq!(snapshot.circuits.len(), 2); assert_eq!(snapshot.circuits[0].circuit_id, "circuit-1"); + assert_eq!(snapshot.circuits[1].circuit_id, "circuit-2"); assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(100, 0)); assert_eq!(snapshot.nodes[3].bytes, DownUpOrder::new(100, 0)); } + + #[test] + fn rollup_skips_counters_without_identity() { + let counters = vec![ + counter(descriptor("circuit-1", "Site B"), DownUpOrder::new(100, 0)), + CircuitCounter::default(), + ]; + let snapshot = rollup(&test_tree(), &counters); + + assert_eq!(snapshot.circuits.len(), 1); + assert_eq!(snapshot.circuits[0].circuit_id, "circuit-1"); + } + + #[test] + fn rollup_prefers_stable_node_ids_over_names() { + let mut tree = test_tree(); + tree.nodes + .push(node("Site B", Some("site-b-2"), vec![0, 4], Some(0))); + let mut identified = descriptor("circuit-1", "Site B"); + identified.parent_node_id = Some("site-b-2".to_string()); + + let snapshot = rollup(&tree, &[counter(identified, DownUpOrder::new(5, 5))]); + + assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(5, 5)); + assert_eq!(snapshot.nodes[3].bytes, DownUpOrder::new(0, 0)); + assert_eq!(snapshot.nodes[4].bytes, DownUpOrder::new(5, 5)); + } + + #[test] + fn rollup_counts_circuits_attached_to_root() { + let counters = vec![counter( + descriptor("circuit-1", "Root"), + DownUpOrder::new(7, 3), + )]; + let snapshot = rollup(&test_tree(), &counters); + + assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(7, 3)); + } + + #[test] + fn rollup_sorts_circuit_rows_by_circuit_id() { + let counters = vec![ + counter(descriptor("circuit-b", "Site A"), DownUpOrder::new(1, 0)), + counter(descriptor("circuit-a", "Site A"), DownUpOrder::new(1, 0)), + ]; + let snapshot = rollup(&test_tree(), &counters); + + let ids: Vec<&str> = snapshot + .circuits + .iter() + .map(|row| row.circuit_id.as_str()) + .collect(); + assert_eq!(ids, vec!["circuit-a", "circuit-b"]); + } + + #[test] + fn disabled_snapshot_reports_empty_lists() { + let previous = is_enabled(); + set_enabled(false); + let snapshot = snapshot(); + set_enabled(previous); + + assert!(!snapshot.enabled); + assert!(snapshot.nodes.is_empty()); + assert!(snapshot.circuits.is_empty()); + } } diff --git a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs index 364c4956..96cd76be 100644 --- a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs +++ b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs @@ -771,20 +771,12 @@ impl ThroughputTracker { } if entry.packets != entry.prev_packets { entry.most_recent_cycle = self_cycle; - let actual_bytes_delta = DownUpOrder::new( - entry - .actual_bytes - .down - .saturating_sub(entry.prev_actual_bytes.down), - entry - .actual_bytes - .up - .saturating_sub(entry.prev_actual_bytes.up), - ); + let actual_bytes_delta = + entry.actual_bytes.checked_sub_or_zero(entry.prev_actual_bytes); // Call to Bakery Update for existing traffic if let Some(circuit_hash) = entry.circuit_hash { changed_circuits.insert(circuit_hash); - if byte_counters_enabled { + if byte_counters_enabled && actual_bytes_delta.not_zero() { byte_counter_deltas .entry(circuit_hash) .or_default() @@ -945,7 +937,7 @@ impl ThroughputTracker { }); if byte_counters_enabled { - crate::byte_counters::add_batch(byte_counter_deltas); + crate::byte_counters::add_batch(byte_counter_deltas, &catalog); } if !observations.is_empty() { -- knotmirror 0.0.1 From 2a022c0e0613f6540a6dca389694a8b58b36ed28 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 13:00:57 -0500 Subject: [PATCH 6/9] Fix: resolve byte counter parents through the canonical topology lookup Reuses ParentNodeLookup so node attribution follows the same id, name, and attachment-alias precedence as the rest of the runtime, and prefers the published effective parent when capturing circuit identity. Adds an alias-resolution test and clarifies the snapshot lock-order comment. --- src/rust/lqosd/src/byte_counters.rs | 78 ++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/src/rust/lqosd/src/byte_counters.rs b/src/rust/lqosd/src/byte_counters.rs index 347fbbf7..42bd5edb 100644 --- a/src/rust/lqosd/src/byte_counters.rs +++ b/src/rust/lqosd/src/byte_counters.rs @@ -15,7 +15,7 @@ use fxhash::FxHashMap; use lqos_bus::{ByteCountersSnapshot, CircuitByteCounters, NodeByteCounters}; use lqos_config::NetworkJson; -use lqos_network_devices::NetworkDevicesCatalog; +use lqos_network_devices::{NetworkDevicesCatalog, ParentNodeLookup}; use lqos_utils::units::DownUpOrder; use once_cell::sync::Lazy; use parking_lot::RwLock; @@ -64,13 +64,23 @@ fn apply_deltas( ) { for (circuit_hash, bytes) in deltas { let counter = counters.entry(circuit_hash).or_default(); - if counter.descriptor.is_none() { - counter.descriptor = describe(circuit_hash); - } + ensure_descriptor(counter, circuit_hash, &describe); counter.bytes.checked_add(bytes); } } +/// Captures a counter's identity on first sight or when it could not be +/// resolved previously. +fn ensure_descriptor( + counter: &mut CircuitCounter, + circuit_hash: i64, + describe: &impl Fn(i64) -> Option, +) { + if counter.descriptor.is_none() { + counter.descriptor = describe(circuit_hash); + } +} + /// Fills descriptors for counters that could not resolve identity when they /// were first recorded, for example because the catalog snapshot was stale. /// @@ -87,32 +97,40 @@ fn fill_missing_descriptors() { let catalog = lqos_network_devices::network_devices_catalog(); let mut counters = CIRCUIT_BYTES.write(); for (circuit_hash, counter) in counters.iter_mut() { - if counter.descriptor.is_none() { - counter.descriptor = describe_circuit(&catalog, *circuit_hash); - } + ensure_descriptor(counter, *circuit_hash, &|circuit_hash| { + describe_circuit(&catalog, circuit_hash) + }); } } /// Resolves one circuit's identity fields from the combined device catalog. +/// +/// The runtime effective parent wins when one is published, so accounting +/// follows the same tree as the rest of the runtime. fn describe_circuit( catalog: &NetworkDevicesCatalog, circuit_hash: i64, ) -> Option { let device = catalog.device_by_hashes(None, Some(circuit_hash))?; + let (parent_node, parent_node_id) = + match crate::shaped_devices_tracker::effective_parent_for_circuit(&device.circuit_id) { + Some(parent) => (parent.name, parent.id), + None => (device.parent_node.clone(), device.parent_node_id.clone()), + }; Some(CircuitDescriptor { circuit_id: device.circuit_id.clone(), circuit_name: device.circuit_name.clone(), - parent_node: device.parent_node.clone(), - parent_node_id: device.parent_node_id.clone(), + parent_node, + parent_node_id, }) } /// Builds a cumulative byte counter snapshot for the bus. /// /// Side effects: acquires the counter lock and the runtime network tree read -/// lock. Descriptors are resolved before the tree lock is taken so the lock -/// order stays `CIRCUIT_BYTES` then `NETWORK_JSON`, matching the tracker's -/// `NETWORK_JSON` write followed by `CIRCUIT_BYTES` write. +/// lock. Descriptors are resolved and the counter lock is released before the +/// tree lock is taken, so the two locks are never held at the same time and +/// cannot invert the tracker's `NETWORK_JSON` then `CIRCUIT_BYTES` order. pub(crate) fn snapshot() -> ByteCountersSnapshot { if !is_enabled() { return ByteCountersSnapshot { @@ -160,13 +178,16 @@ fn rollup(tree: &NetworkJson, counters: &[CircuitCounter]) -> ByteCountersSnapsh node_by_id.entry(id).or_insert(index); } } + let parent_lookup = ParentNodeLookup::from_nodes(&tree.nodes); let mut circuit_rows = Vec::new(); for counter in counters { let Some(descriptor) = counter.descriptor.as_ref() else { continue; }; - if let Some(parent_index) = resolve_parent_node(descriptor, &node_by_id, &node_by_name) { + if let Some(parent_index) = + resolve_parent_index(&parent_lookup, descriptor, &node_by_id, &node_by_name) + { let parent_node = &tree.nodes[parent_index]; if parent_node.parents.is_empty() { // The root node carries no parent list, so add its own traffic. @@ -208,17 +229,23 @@ fn rollup(tree: &NetworkJson, counters: &[CircuitCounter]) -> ByteCountersSnapsh } } -/// Resolves a circuit's parent node, preferring the stable node identifier. -fn resolve_parent_node( +/// Resolves a circuit's parent node with the canonical id, name, and alias +/// precedence used by the rest of the runtime. +fn resolve_parent_index( + parent_lookup: &ParentNodeLookup<'_>, descriptor: &CircuitDescriptor, node_by_id: &FxHashMap<&str, usize>, node_by_name: &FxHashMap<&str, usize>, ) -> Option { - descriptor - .parent_node_id + let parent = parent_lookup.resolve( + &descriptor.parent_node, + descriptor.parent_node_id.as_deref(), + )?; + parent + .id .as_deref() .and_then(|id| node_by_id.get(id).copied()) - .or_else(|| node_by_name.get(descriptor.parent_node.as_str()).copied()) + .or_else(|| node_by_name.get(parent.name.as_str()).copied()) } #[cfg(test)] @@ -374,6 +401,21 @@ mod tests { assert_eq!(snapshot.nodes[4].bytes, DownUpOrder::new(5, 5)); } + #[test] + fn rollup_resolves_parent_aliases() { + let mut tree = test_tree(); + tree.nodes[2].active_attachment_name = Some("Site A1 Alias".to_string()); + let counters = vec![counter( + descriptor("circuit-1", "Site A1 Alias"), + DownUpOrder::new(4, 2), + )]; + let snapshot = rollup(&tree, &counters); + + assert_eq!(snapshot.nodes[0].bytes, DownUpOrder::new(4, 2)); + assert_eq!(snapshot.nodes[1].bytes, DownUpOrder::new(4, 2)); + assert_eq!(snapshot.nodes[2].bytes, DownUpOrder::new(4, 2)); + } + #[test] fn rollup_counts_circuits_attached_to_root() { let counters = vec![counter( -- knotmirror 0.0.1 From 3f00f1059391f9914800e648dde2684de965a95d Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 13:20:03 -0500 Subject: [PATCH 7/9] Fix: refresh byte counter identity for configured circuits Live circuits now follow renames and re-parenting because descriptors refresh from the catalog on each snapshot, while circuits removed from configuration keep their last-known descriptor and continue contributing to their last known parent. Documents the tracker-side lock constraint, releases the throughput table lock before the counter merge, adds a first-miss descriptor recovery test, and applies rustfmt to the new hunk. --- src/rust/lqosd/src/byte_counters.rs | 56 +++++++++++++------ .../src/throughput_tracker/tracking_data.rs | 7 ++- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/rust/lqosd/src/byte_counters.rs b/src/rust/lqosd/src/byte_counters.rs index 42bd5edb..570f1844 100644 --- a/src/rust/lqosd/src/byte_counters.rs +++ b/src/rust/lqosd/src/byte_counters.rs @@ -45,7 +45,9 @@ pub(crate) fn is_enabled() -> bool { /// /// New circuits capture their identity from `catalog` on first sight. /// -/// Side effects: mutates the shared cumulative counter map. +/// Side effects: mutates the shared cumulative counter map. Callers may +/// already hold the network tree write lock, so this function must never +/// acquire a network tree lock. pub(crate) fn add_batch(deltas: FxHashMap>, catalog: &NetworkDevicesCatalog) { if deltas.is_empty() { return; @@ -81,32 +83,28 @@ fn ensure_descriptor( } } -/// Fills descriptors for counters that could not resolve identity when they -/// were first recorded, for example because the catalog snapshot was stale. +/// Refreshes descriptors for circuits that still resolve in the device +/// catalog, so live circuits follow renames and re-parenting. Circuits that no +/// longer resolve keep their last-known descriptor and continue contributing +/// to their last known parent. /// /// Side effects: mutates the shared cumulative counter map. -fn fill_missing_descriptors() { - if CIRCUIT_BYTES - .read() - .values() - .all(|counter| counter.descriptor.is_some()) - { - return; - } - +fn refresh_descriptors() { let catalog = lqos_network_devices::network_devices_catalog(); let mut counters = CIRCUIT_BYTES.write(); for (circuit_hash, counter) in counters.iter_mut() { - ensure_descriptor(counter, *circuit_hash, &|circuit_hash| { - describe_circuit(&catalog, circuit_hash) - }); + if let Some(descriptor) = describe_circuit(&catalog, *circuit_hash) { + counter.descriptor = Some(descriptor); + } } } /// Resolves one circuit's identity fields from the combined device catalog. /// /// The runtime effective parent wins when one is published, so accounting -/// follows the same tree as the rest of the runtime. +/// follows the same tree as the rest of the runtime. This function must never +/// acquire a network tree lock, because callers may already hold the tree +/// write lock. fn describe_circuit( catalog: &NetworkDevicesCatalog, circuit_hash: i64, @@ -128,7 +126,7 @@ fn describe_circuit( /// Builds a cumulative byte counter snapshot for the bus. /// /// Side effects: acquires the counter lock and the runtime network tree read -/// lock. Descriptors are resolved and the counter lock is released before the +/// lock. Descriptors are refreshed and the counter lock is released before the /// tree lock is taken, so the two locks are never held at the same time and /// cannot invert the tracker's `NETWORK_JSON` then `CIRCUIT_BYTES` order. pub(crate) fn snapshot() -> ByteCountersSnapshot { @@ -140,7 +138,7 @@ pub(crate) fn snapshot() -> ByteCountersSnapshot { }; } - fill_missing_descriptors(); + refresh_descriptors(); let counters: Vec = CIRCUIT_BYTES.read().values().cloned().collect(); @@ -336,6 +334,28 @@ mod tests { ); } + #[test] + fn apply_deltas_fills_descriptor_when_first_lookup_missed() { + let mut counters = FxHashMap::default(); + apply_deltas( + &mut counters, + FxHashMap::from_iter([(7, DownUpOrder::new(1, 0))]), + |_| None, + ); + apply_deltas( + &mut counters, + FxHashMap::from_iter([(7, DownUpOrder::new(2, 0))]), + |_| Some(descriptor("circuit-7", "Site A")), + ); + + let counter = counters.get(&7).expect("counter should exist"); + assert_eq!(counter.bytes, DownUpOrder::new(3, 0)); + assert_eq!( + counter.descriptor.as_ref().map(|d| d.circuit_id.as_str()), + Some("circuit-7") + ); + } + #[test] fn rollup_includes_descendant_bytes_in_ancestor_totals() { let counters = vec![ diff --git a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs index 96cd76be..cab6cc4c 100644 --- a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs +++ b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs @@ -771,8 +771,9 @@ impl ThroughputTracker { } if entry.packets != entry.prev_packets { entry.most_recent_cycle = self_cycle; - let actual_bytes_delta = - entry.actual_bytes.checked_sub_or_zero(entry.prev_actual_bytes); + let actual_bytes_delta = entry + .actual_bytes + .checked_sub_or_zero(entry.prev_actual_bytes); // Call to Bakery Update for existing traffic if let Some(circuit_hash) = entry.circuit_hash { changed_circuits.insert(circuit_hash); @@ -936,6 +937,8 @@ impl ThroughputTracker { } }); + drop(raw_data); + if byte_counters_enabled { crate::byte_counters::add_batch(byte_counter_deltas, &catalog); } -- knotmirror 0.0.1 From 18cde06b3583b10c324115f50d5390a13b0f51bd Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 13:35:08 -0500 Subject: [PATCH 8/9] Fix: index the device catalog once per byte counter refresh Builds a circuit-hash index from the combined catalog before refreshing descriptors, so dynamic and removed circuits cannot trigger per-circuit fallback scans while the counter lock is held. Clarifies the module documentation and fixes the Spanish parent-node wording. --- docs-es/v2.0/configuration-advanced-es.md | 2 +- src/rust/lqosd/src/byte_counters.rs | 50 +++++++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/docs-es/v2.0/configuration-advanced-es.md b/docs-es/v2.0/configuration-advanced-es.md index 6f26f0ab..1ad43dbd 100644 --- a/docs-es/v2.0/configuration-advanced-es.md +++ b/docs-es/v2.0/configuration-advanced-es.md @@ -75,7 +75,7 @@ enabled = true - Los valores se acumulan mientras `lqosd` se ejecuta y se reinician cuando `lqosd` se reinicia. - Los valores de un nodo incluyen el tráfico de todos sus nodos descendientes. - Solo se listan los circuitos con tráfico registrado. -- Los circuitos eliminados de `ShapedDevices.csv` siguen aportando sus bytes acumulados a su último nodo principal conocido mientras `lqosd` se ejecuta. +- Los circuitos eliminados de `ShapedDevices.csv` siguen aportando sus bytes acumulados a su último nodo padre conocido mientras `lqosd` se ejecuta. Con los contadores habilitados, `GET /byte_counters` en la API del nodo devuelve los valores actuales. Consulte [API del nodo LibreQoS](api-es.md). diff --git a/src/rust/lqosd/src/byte_counters.rs b/src/rust/lqosd/src/byte_counters.rs index 570f1844..66108e82 100644 --- a/src/rust/lqosd/src/byte_counters.rs +++ b/src/rust/lqosd/src/byte_counters.rs @@ -5,16 +5,16 @@ //! module. Counters are cumulative since `lqosd` started and are not //! persisted across restarts. //! -//! Only per-circuit totals and their last-known identity are stored. Node -//! totals are derived when a snapshot is requested by walking each circuit's -//! parent node through the runtime network tree, so node totals include -//! descendants. Circuit identity is captured when a counter first receives -//! traffic, so circuits removed from configuration keep contributing their -//! accumulated bytes to their last known parent while `lqosd` runs. +//! Only per-circuit totals and their identity are stored. Node totals are +//! derived when a snapshot is requested by walking each circuit's parent node +//! through the runtime network tree, so node totals include descendants. +//! Configured circuits follow the current device catalog, and circuits removed +//! from configuration keep their last known identity, so their accumulated +//! bytes continue to contribute to their last known parent while `lqosd` runs. use fxhash::FxHashMap; use lqos_bus::{ByteCountersSnapshot, CircuitByteCounters, NodeByteCounters}; -use lqos_config::NetworkJson; +use lqos_config::{NetworkJson, ShapedDevice}; use lqos_network_devices::{NetworkDevicesCatalog, ParentNodeLookup}; use lqos_utils::units::DownUpOrder; use once_cell::sync::Lazy; @@ -58,7 +58,7 @@ pub(crate) fn add_batch(deltas: FxHashMap>, catalog: &Netw } /// Merges per-circuit deltas into a cumulative counter map, capturing identity -/// through `describe` when a circuit is first seen. +/// through `describe` when a circuit is first seen or has none captured yet. fn apply_deltas( counters: &mut FxHashMap, deltas: FxHashMap>, @@ -88,39 +88,57 @@ fn ensure_descriptor( /// longer resolve keep their last-known descriptor and continue contributing /// to their last known parent. /// +/// The catalog is indexed once per refresh so circuits missing from +/// `ShapedDevices.csv` cannot trigger per-circuit fallback scans. +/// /// Side effects: mutates the shared cumulative counter map. fn refresh_descriptors() { let catalog = lqos_network_devices::network_devices_catalog(); + let mut devices_by_circuit_hash: FxHashMap = FxHashMap::default(); + for device in catalog.iter_all_devices() { + devices_by_circuit_hash + .entry(device.circuit_hash) + .or_insert(device); + } + let mut counters = CIRCUIT_BYTES.write(); for (circuit_hash, counter) in counters.iter_mut() { - if let Some(descriptor) = describe_circuit(&catalog, *circuit_hash) { - counter.descriptor = Some(descriptor); + if let Some(device) = devices_by_circuit_hash.get(circuit_hash) { + counter.descriptor = Some(describe_device(device)); } } } /// Resolves one circuit's identity fields from the combined device catalog. /// -/// The runtime effective parent wins when one is published, so accounting -/// follows the same tree as the rest of the runtime. This function must never -/// acquire a network tree lock, because callers may already hold the tree -/// write lock. +/// This function must never acquire a network tree lock, because callers may +/// already hold the tree write lock. fn describe_circuit( catalog: &NetworkDevicesCatalog, circuit_hash: i64, ) -> Option { let device = catalog.device_by_hashes(None, Some(circuit_hash))?; + Some(describe_device(device)) +} + +/// Builds identity fields for one device. +/// +/// The runtime effective parent wins when one is published, so accounting +/// follows the same tree as the rest of the runtime. This function must never +/// acquire a network tree lock, because callers may already hold the tree +/// write lock. +fn describe_device(device: &ShapedDevice) -> CircuitDescriptor { let (parent_node, parent_node_id) = match crate::shaped_devices_tracker::effective_parent_for_circuit(&device.circuit_id) { Some(parent) => (parent.name, parent.id), None => (device.parent_node.clone(), device.parent_node_id.clone()), }; - Some(CircuitDescriptor { + CircuitDescriptor { circuit_id: device.circuit_id.clone(), circuit_name: device.circuit_name.clone(), parent_node, parent_node_id, - }) + } } /// Builds a cumulative byte counter snapshot for the bus. -- knotmirror 0.0.1 From 49024d065caa7da082c14caf6c4638acbd77529e Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 7 Oct 2026 13:43:48 -0500 Subject: [PATCH 9/9] Docs: tighten byte counters API wording Uses active phrasing in the Spanish API note and aligns the English wording with the configuration page. --- docs-es/v2.0/api-es.md | 2 +- docs/v2.0/api.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs-es/v2.0/api-es.md b/docs-es/v2.0/api-es.md index 65600d8c..80fbef84 100644 --- a/docs-es/v2.0/api-es.md +++ b/docs-es/v2.0/api-es.md @@ -125,7 +125,7 @@ Endpoints representativos: - `GET /warnings` - `GET /urgent`, `GET /urgent/status` -`GET /byte_counters` devuelve contadores de bytes acumulados por nodo y por circuito cuando `[byte_counters] enabled = true` está configurado en `/etc/lqos.conf`. Los valores son acumulados desde que `lqosd` inició, incluyen el tráfico descendiente en los nodos y se reinician cuando `lqosd` se reinicia. Consulte [Configuración avanzada](configuration-advanced-es.md). +`GET /byte_counters` devuelve contadores de bytes acumulados por nodo y por circuito cuando `[byte_counters] enabled = true` está configurado en `/etc/lqos.conf`. Los valores se acumulan desde que `lqosd` inició, incluyen el tráfico de los nodos descendientes y se reinician cuando `lqosd` se reinicia. Consulte [Configuración avanzada](configuration-advanced-es.md). ### 5) Operaciones de control y reload diff --git a/docs/v2.0/api.md b/docs/v2.0/api.md index dfc33982..10638acd 100644 --- a/docs/v2.0/api.md +++ b/docs/v2.0/api.md @@ -125,7 +125,7 @@ Representative endpoints: - `GET /warnings` - `GET /urgent`, `GET /urgent/status` -`GET /byte_counters` returns cumulative per-node and per-circuit byte counters when `[byte_counters] enabled = true` is set in `/etc/lqos.conf`. Values are cumulative since `lqosd` started, include descendant traffic for nodes, and reset when `lqosd` restarts. See [Advanced Configuration](configuration-advanced.md). +`GET /byte_counters` returns cumulative per-node and per-circuit byte counters when `[byte_counters] enabled = true` is set in `/etc/lqos.conf`. Values accumulate since `lqosd` started, node values include traffic from descendant nodes, and values reset when `lqosd` restarts. See [Advanced Configuration](configuration-advanced.md). ### 5) Control and Reload Operations