fix(ratecontroller): use egress interface for traffic stats

Read both RX and TX byte counters from the configured upload/egress
interface. Remove the obsolete per-direction stats selection and related
plumbing now that download load uses RX and upload load uses TX from the
same interface.
This commit is contained in:
Nils Andreas Svee committed 2026-08-13 14:19:53 +07:00
1 parent 1ad47eaeb0
commit 6a90446b56
2 files changed
+5 -60

No files matched your search

+1 -18
View File
@@ -26,7 +26,7 @@ use crate::pinger::{InFlightProbeCache, PingListener, PingSender};
use crate::pinger_icmp::{PingerICMPEchoListener, PingerICMPEchoSender}; use crate::pinger_icmp::{PingerICMPEchoListener, PingerICMPEchoSender};
use crate::pinger_icmp_ts::{PingerICMPTimestampListener, PingerICMPTimestampSender}; use crate::pinger_icmp_ts::{PingerICMPTimestampListener, PingerICMPTimestampSender};
use crate::platform::{TrafficControlBackend, traffic_control_backend, warn_platform_limitations}; use crate::platform::{TrafficControlBackend, traffic_control_backend, warn_platform_limitations};
use crate::ratecontroller::{Ratecontroller, StatsDirection}; use crate::ratecontroller::Ratecontroller;
use crate::reflector_selector::ReflectorSelector; use crate::reflector_selector::ReflectorSelector;
use crate::settings::MeasurementType; use crate::settings::MeasurementType;
use crate::settings::Settings; use crate::settings::Settings;
@@ -155,10 +155,6 @@ fn install_signal_handlers() {
} }
} }
fn interface_stats_directions(_: &Settings) -> (StatsDirection, StatsDirection) {
(StatsDirection::RX, StatsDirection::TX)
}
fn probe_identifier() -> u16 { fn probe_identifier() -> u16 {
// The ICMP identifier is only two bytes. // The ICMP identifier is only two bytes.
(process::id() & 0xffff) as u16 (process::id() & 0xffff) as u16
@@ -415,24 +411,11 @@ fn run(settings: &Settings) -> anyhow::Result<()> {
// Give the baseliner time to collect initial samples before adjusting rates. // Give the baseliner time to collect initial samples before adjusting rates.
sleep(Duration::from_secs(10)); sleep(Duration::from_secs(10));
let (dl_direction, ul_direction) = interface_stats_directions(settings);
debug!(
"Download direction: {}:{:?}",
settings.network.download_interface, dl_direction
);
debug!(
"Upload direction: {}:{:?}",
settings.network.upload_interface, ul_direction
);
let mut ratecontroller = Ratecontroller::new( let mut ratecontroller = Ratecontroller::new(
settings.clone(), settings.clone(),
control_snapshot_rx, control_snapshot_rx,
reflector_peers, reflector_peers,
reselect_tx, reselect_tx,
dl_direction,
ul_direction,
rate_metrics, rate_metrics,
)?; )?;
+4 -42
View File
@@ -31,12 +31,6 @@ enum Direction {
Up, Up,
} }
#[derive(Copy, Clone, Debug)]
pub enum StatsDirection {
RX,
TX,
}
fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec<f64> { fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec<f64> {
let mut rates = Vec::new(); let mut rates = Vec::new();
@@ -49,25 +43,11 @@ fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec<f64> {
fn get_interface_stats<S: InterfaceStatsProvider>( fn get_interface_stats<S: InterfaceStatsProvider>(
stats_provider: &mut S, stats_provider: &mut S,
download_interface: &str,
upload_interface: &str, upload_interface: &str,
down_direction: StatsDirection,
up_direction: StatsDirection,
) -> Result<(i128, i128), S::Error> { ) -> Result<(i128, i128), S::Error> {
let down = stats_provider.read_stats(download_interface)?; let stats = stats_provider.read_stats(upload_interface)?;
let up = stats_provider.read_stats(upload_interface)?;
let rx_bytes = match down_direction { Ok((stats.rx_bytes.into(), stats.tx_bytes.into()))
StatsDirection::RX => down.rx_bytes,
StatsDirection::TX => down.tx_bytes,
};
let tx_bytes = match up_direction {
StatsDirection::RX => up.rx_bytes,
StatsDirection::TX => up.tx_bytes,
};
Ok((rx_bytes.into(), tx_bytes.into()))
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@@ -160,14 +140,12 @@ pub struct Ratecontroller<S: InterfaceStatsProvider, T: TrafficControlBackend> {
settings: Settings, settings: Settings,
control_snapshot: Option<ControlSnapshot>, control_snapshot: Option<ControlSnapshot>,
control_snapshot_rx: Receiver<ControlSnapshot>, control_snapshot_rx: Receiver<ControlSnapshot>,
down_direction: StatsDirection,
reflectors_lock: ArcRwLock<Vec<IpAddr>>, reflectors_lock: ArcRwLock<Vec<IpAddr>>,
reselect_trigger: Sender<bool>, reselect_trigger: Sender<bool>,
state_dl: State<T::Handle>, state_dl: State<T::Handle>,
state_ul: State<T::Handle>, state_ul: State<T::Handle>,
stats_provider: S, stats_provider: S,
traffic_control: T, traffic_control: T,
up_direction: StatsDirection,
metrics: MetricsSender, metrics: MetricsSender,
} }
@@ -177,8 +155,6 @@ impl<S: InterfaceStatsProvider, T: TrafficControlBackend> Ratecontroller<S, T> {
control_snapshot_rx: Receiver<ControlSnapshot>, control_snapshot_rx: Receiver<ControlSnapshot>,
reflectors_lock: ArcRwLock<Vec<IpAddr>>, reflectors_lock: ArcRwLock<Vec<IpAddr>>,
reselect_trigger: Sender<bool>, reselect_trigger: Sender<bool>,
down_direction: StatsDirection,
up_direction: StatsDirection,
metrics: MetricsSender, metrics: MetricsSender,
mut stats_provider: S, mut stats_provider: S,
mut traffic_control: T, mut traffic_control: T,
@@ -195,26 +171,19 @@ impl<S: InterfaceStatsProvider, T: TrafficControlBackend> Ratecontroller<S, T> {
settings.advanced_settings.speed_hist_size, settings.advanced_settings.speed_hist_size,
); );
let (cur_rx, cur_tx) = get_interface_stats( let (cur_rx, cur_tx) =
&mut stats_provider, get_interface_stats(&mut stats_provider, &settings.network.upload_interface)?;
&settings.network.download_interface,
&settings.network.upload_interface,
down_direction,
up_direction,
)?;
Ok(Self { Ok(Self {
settings, settings,
control_snapshot: None, control_snapshot: None,
control_snapshot_rx, control_snapshot_rx,
down_direction,
reflectors_lock, reflectors_lock,
reselect_trigger, reselect_trigger,
state_dl: State::new(dl_shaper, cur_rx, dl_safe_rates), state_dl: State::new(dl_shaper, cur_rx, dl_safe_rates),
state_ul: State::new(ul_shaper, cur_tx, ul_safe_rates), state_ul: State::new(ul_shaper, cur_tx, ul_safe_rates),
stats_provider, stats_provider,
traffic_control, traffic_control,
up_direction,
metrics, metrics,
}) })
} }
@@ -350,8 +319,6 @@ impl Ratecontroller<PlatformInterfaceStats, PlatformTrafficControl> {
control_snapshot_rx: Receiver<ControlSnapshot>, control_snapshot_rx: Receiver<ControlSnapshot>,
reflectors_lock: ArcRwLock<Vec<IpAddr>>, reflectors_lock: ArcRwLock<Vec<IpAddr>>,
reselect_trigger: Sender<bool>, reselect_trigger: Sender<bool>,
down_direction: StatsDirection,
up_direction: StatsDirection,
metrics: MetricsSender, metrics: MetricsSender,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
Self::new_with_backends( Self::new_with_backends(
@@ -359,8 +326,6 @@ impl Ratecontroller<PlatformInterfaceStats, PlatformTrafficControl> {
control_snapshot_rx, control_snapshot_rx,
reflectors_lock, reflectors_lock,
reselect_trigger, reselect_trigger,
down_direction,
up_direction,
metrics, metrics,
interface_stats_provider(), interface_stats_provider(),
traffic_control_backend(), traffic_control_backend(),
@@ -425,10 +390,7 @@ impl<S: InterfaceStatsProvider, T: TrafficControlBackend> Ratecontroller<S, T> {
(self.state_dl.current_bytes, self.state_ul.current_bytes) = get_interface_stats( (self.state_dl.current_bytes, self.state_ul.current_bytes) = get_interface_stats(
&mut self.stats_provider, &mut self.stats_provider,
&self.settings.network.download_interface,
&self.settings.network.upload_interface, &self.settings.network.upload_interface,
self.down_direction,
self.up_direction,
)?; )?;
self.update_deltas()?; self.update_deltas()?;