Skip to main content

rustflexstack/management/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2024 Fundació Privada Internet i Innovació Digital a Catalunya (i2CAT)
3
4//! # Management Layer
5//!
6//! Decentralized Congestion Control (DCC) algorithms and transmission management
7//! as specified in ETSI TS 102 687 V1.2.1 (2018-04).
8//!
9//! This module provides:
10//! - Reactive DCC algorithm ([`dcc_reactive`]) per clause 5.3 and Annex A.
11//! - Adaptive DCC algorithm (LIMERIC) and Gate Keeper admission control ([`dcc_adaptive`])
12//!   per clause 5.4 and Annex B.
13//! - Channel Busy Ratio sources from the access layer ([`cbr`]).
14//! - The DCC entity ([`dcc_entity`]) that evaluates the selected algorithm every
15//!   200 ms and provides `T_GenCam_DCC` to the CA basic service.
16
17pub mod cbr;
18pub mod dcc_adaptive;
19pub mod dcc_entity;
20pub mod dcc_reactive;
21
22pub use cbr::{
23    cbr_from_samples, parse_survey_dump, CbrProvider, Nl80211SurveyCbr, SharedCbr, SurveySample,
24};
25pub use dcc_adaptive::{DccAdaptive, DccAdaptiveParameters, GateKeeper};
26pub use dcc_entity::{
27    clamp_t_gen_cam_dcc, DccEntity, DccEntityHandle, DccEntityOutput, DccMode,
28    DCC_EVALUATION_PERIOD_MS, T_GEN_CAM_DCC_MAX_MS, T_GEN_CAM_DCC_MIN_MS,
29};
30pub use dcc_reactive::{DccReactive, DccReactiveOutput, DccState, DccStateConfig};
31
32/// Errors encountered during DCC calculations and validation.
33#[derive(Debug, Clone, PartialEq)]
34pub enum DccError {
35    /// Channel Busy Ratio (CBR) measurement was outside the permitted `[0.0, 1.0]` range.
36    InvalidCbr { name: &'static str, value: f64 },
37    /// Packet transmission duration `t_on` was not positive.
38    InvalidTon(f64),
39    /// Duty-cycle fraction `delta` was not positive.
40    InvalidDelta(f64),
41}
42
43impl std::fmt::Display for DccError {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        match self {
46            DccError::InvalidCbr { name, value } => {
47                write!(f, "{name} must be in [0.0, 1.0], got {value}")
48            }
49            DccError::InvalidTon(val) => {
50                write!(f, "t_on must be positive, got {val}")
51            }
52            DccError::InvalidDelta(val) => {
53                write!(f, "delta must be positive, got {val}")
54            }
55        }
56    }
57}
58
59impl std::error::Error for DccError {}