use std::time::Duration;
pub mod perf {
use std::time::Duration;
pub const MIN_RTT_THRESHOLD_US: u64 = 1000;
pub const MAX_RTT_THRESHOLD_US: u64 = 10_000_000;
pub const INITIAL_CWND: u64 = 10;
pub const MIN_CWND: u64 = 2;
pub const MAX_CWND: u64 = 0x7fff_ffff;
pub const DEFAULT_MSS: u64 = 1460;
pub const PACING_GAIN_PRECISION: u64 = 1000;
pub const BW_ESTIMATION_WINDOW: usize = 10;
pub const RTT_ALPHA: f64 = 0.125;
pub const RTT_BETA: f64 = 0.25;
pub const MIN_PACING_RATE: u64 = 1000;
pub const MAX_PACING_RATE: u64 = 100_000_000_000;
pub const SWITCH_COOLDOWN: Duration = Duration::from_secs(5);
pub const HIGH_LOSS_THRESHOLD: f64 = 0.05;
pub const HIGH_RTT_CV_THRESHOLD: f64 = 0.3;
pub const LOW_BW_UTIL_THRESHOLD: f64 = 0.7;
pub const ACK_BATCH_SIZE: usize = 32;
pub const CACHE_LINE_SIZE: usize = 64;
pub const MIN_UPDATE_INTERVAL: Duration = Duration::from_millis(1);
pub const BW_PROBE_CYCLE: Duration = Duration::from_secs(10);
pub const RTT_PROBE_DURATION: Duration = Duration::from_millis(200);
}
pub mod bbr {
use std::time::Duration;
pub const PACING_GAIN_CYCLE: [u64; 8] = [1250, 750, 1000, 1000, 1000, 1000, 1000, 1000];
pub const STARTUP_GAIN: u64 = 2885;
pub const DRAIN_GAIN: u64 = 1000;
pub const PROBE_BW_GAIN: u64 = 1000;
pub const PROBE_RTT_GAIN: u64 = 1000;
pub const CWND_GAIN: u64 = 2000;
pub const PROBE_RTT_DURATION: Duration = Duration::from_millis(200);
pub const PROBE_RTT_INTERVAL: Duration = Duration::from_secs(10);
pub const RTT_WINDOW_LENGTH: Duration = Duration::from_secs(10);
pub const BW_WINDOW_LENGTH: Duration = Duration::from_secs(10);
pub const STARTUP_ROUNDS: u32 = 3;
pub const STARTUP_GROWTH_THRESHOLD: u64 = 1250;
pub const FULL_BW_THRESHOLD: u64 = 1250;
pub const FULL_BW_COUNT: u32 = 3;
pub const PROBE_BW_CYCLE_LEN: usize = 8;
pub const EXTRA_ACKED_FILTER_LEN: usize = 10;
pub const BW_FILTER_LEN: usize = 10;
pub const RTT_FILTER_LEN: usize = 10;
pub const PROBE_RTT_CWND_PACKETS: u64 = 4;
pub const BETA: u64 = 717;
pub const PACING_MARGIN_PERCENT: u64 = 1; }
pub mod cubic {
pub const C: f64 = 0.4;
pub const BETA: f64 = 0.7;
pub const FAST_CONVERGENCE_FACTOR: f64 = 0.85;
pub const TCP_FRIENDLINESS: bool = true;
pub const HYSTART_ENABLED: bool = true;
pub const HYSTART_ACK_TRAIN_THRESHOLD: u32 = 2;
pub const HYSTART_DELAY_THRESHOLD_US: u64 = 2000;
pub const HYSTART_MIN_SAMPLES: u32 = 8;
pub const EPOCH_LENGTH_US: u64 = 100_000;
pub const MAX_INCREMENT: f64 = 1.0;
pub const MIN_INCREMENT: f64 = 0.01;
pub const INITIAL_SSTHRESH: u64 = 0x7fff_ffff;
pub const MIN_SSTHRESH: u64 = 2;
pub const CUBIC_ROOT_PRECISION: f64 = 1e-6;
pub const MAX_CUBIC_TIME: f64 = 1000.0;
pub const TIME_SCALE: f64 = 1024.0;
pub const ACK_RATIO: f64 = 1.0;
pub const LOSS_EVENT_THRESHOLD: u32 = 1;
}
pub mod thresholds {
pub const HIGH_LOSS_RATE: f64 = 0.05;
pub const VERY_HIGH_LOSS_RATE: f64 = 0.10;
pub const LOW_LOSS_RATE: f64 = 0.001;
pub const HIGH_RTT_VARIATION: f64 = 0.30;
pub const LOW_RTT_VARIATION: f64 = 0.10;
pub const HIGH_BW_UTILIZATION: f64 = 0.90;
pub const LOW_BW_UTILIZATION: f64 = 0.70;
pub const VERY_LOW_BW_UTILIZATION: f64 = 0.50;
pub const HIGH_RTT_THRESHOLD_US: u64 = 100_000;
pub const LOW_RTT_THRESHOLD_US: u64 = 10_000;
pub const VERY_HIGH_RTT_THRESHOLD_US: u64 = 500_000;
pub const STABLE_NETWORK_SAMPLES: usize = 10;
pub const UNSTABLE_NETWORK_SAMPLES: usize = 3;
}
pub mod memory {
pub const DEFAULT_SOCKET_BUFFER_SIZE: usize = 4 * 1024 * 1024;
pub const MAX_SOCKET_BUFFER_SIZE: usize = 128 * 1024 * 1024;
pub const MIN_SOCKET_BUFFER_SIZE: usize = 64 * 1024;
pub const PACKET_BUFFER_POOL_SIZE: usize = 1024;
pub const MAX_PACKET_SIZE: usize = 9000;
pub const STANDARD_MTU: usize = 1500;
pub const SIMD_ALIGNMENT: usize = 32;
pub const METRICS_RING_BUFFER_SIZE: usize = 256;
}
pub mod timing {
use std::time::Duration;
pub const MIN_TIMER_RESOLUTION: Duration = Duration::from_micros(100);
pub const MAX_TIMER_RESOLUTION: Duration = Duration::from_millis(100);
pub const PACING_TIMER_RESOLUTION: Duration = Duration::from_micros(500);
pub const ACK_TIMEOUT_BASE: Duration = Duration::from_millis(200);
pub const ACK_TIMEOUT_MAX: Duration = Duration::from_secs(60);
pub const RTO_MIN: Duration = Duration::from_millis(200);
pub const RTO_MAX: Duration = Duration::from_secs(60);
pub const DELAYED_ACK_TIMEOUT: Duration = Duration::from_millis(40);
pub const KEEP_ALIVE_INTERVAL: Duration = Duration::from_secs(7200);
pub const IDLE_TIMEOUT: Duration = Duration::from_secs(300); }
pub mod math {
pub const LN_2: f64 = 0.6931471805599453;
pub const SQRT_2: f64 = 1.4142135623730951;
pub const E: f64 = 2.718281828459045;
pub const PHI: f64 = 1.618033988749895;
pub const EPSILON: f64 = 1e-9;
pub const MAX_SAFE_INTEGER: u64 = 0x1f_ffff_ffff_ffff;
pub const FIXED_POINT_SCALE: u64 = 1_000_000;
pub const MAX_SCALED_VALUE: u64 = u64::MAX / FIXED_POINT_SCALE;
}
pub mod features {
#[cfg(feature = "simd")]
pub const SIMD_ENABLED: bool = true;
#[cfg(not(feature = "simd"))]
pub const SIMD_ENABLED: bool = false;
#[cfg(feature = "platform-optimized")]
pub const PLATFORM_OPTIMIZED: bool = true;
#[cfg(not(feature = "platform-optimized"))]
pub const PLATFORM_OPTIMIZED: bool = false;
#[cfg(feature = "bbr")]
pub const BBR_ENABLED: bool = true;
#[cfg(not(feature = "bbr"))]
pub const BBR_ENABLED: bool = false;
#[cfg(feature = "cubic")]
pub const CUBIC_ENABLED: bool = true;
#[cfg(not(feature = "cubic"))]
pub const CUBIC_ENABLED: bool = false;
#[cfg(debug_assertions)]
pub const DEBUG_ENABLED: bool = true;
#[cfg(not(debug_assertions))]
pub const DEBUG_ENABLED: bool = false;
#[cfg(feature = "profiling")]
pub const PROFILING_ENABLED: bool = true;
#[cfg(not(feature = "profiling"))]
pub const PROFILING_ENABLED: bool = false;
}
pub mod utils {
use super::*;
#[inline(always)]
pub const fn us_to_duration(us: u64) -> std::time::Duration {
std::time::Duration::from_micros(us)
}
#[inline(always)]
pub fn duration_to_us(duration: std::time::Duration) -> u64 {
duration.as_micros() as u64
}
#[inline(always)]
pub const fn scale_pacing_gain(gain: u64) -> u64 {
gain * perf::PACING_GAIN_PRECISION
}
#[inline(always)]
pub const fn unscale_pacing_gain(scaled_gain: u64) -> u64 {
scaled_gain / perf::PACING_GAIN_PRECISION
}
#[inline(always)]
pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> T {
if value < min {
min
} else if value > max {
max
} else {
value
}
}
#[inline(always)]
pub fn is_high_loss_rate(loss_rate: f64) -> bool {
loss_rate >= thresholds::HIGH_LOSS_RATE
}
#[inline(always)]
pub fn is_high_rtt_variation(cv: f64) -> bool {
cv >= thresholds::HIGH_RTT_VARIATION
}
#[inline(always)]
pub fn is_low_bandwidth_utilization(utilization: f64) -> bool {
utilization <= thresholds::LOW_BW_UTILIZATION
}
#[inline(always)]
pub const fn next_power_of_2(n: usize) -> usize {
if n == 0 {
1
} else {
1 << (64 - (n - 1).leading_zeros())
}
}
#[inline(always)]
pub const fn align_to_cache_line(size: usize) -> usize {
(size + perf::CACHE_LINE_SIZE - 1) & !(perf::CACHE_LINE_SIZE - 1)
}
}