Skip to main content

linkprobe_core/
measurement.rs

1use serde::{Deserialize, Serialize};
2
3/// Throughput in bits per second.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Throughput {
6    /// Bits per second.
7    pub bps: f64,
8}
9
10impl Throughput {
11    /// Construct from a raw bit rate.
12    pub fn from_bps(bps: f64) -> Self {
13        Self { bps }
14    }
15
16    /// Convert to megabits per second (decimal `1_000_000` bps per Mbps).
17    pub fn mbps(self) -> f64 {
18        self.bps / 1_000_000.0
19    }
20}
21
22/// Result of one link measurement against a server.
23///
24/// Fields are optional when the backend does not report them (for example packet loss is only
25/// filled for iperf3 UDP runs).
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct Measurement {
28    /// Round-trip latency in milliseconds.
29    pub latency_ms: Option<f64>,
30    /// Jitter in milliseconds.
31    pub jitter_ms: Option<f64>,
32    /// Download throughput when measured.
33    pub download: Option<Throughput>,
34    /// Upload throughput when measured.
35    pub upload: Option<Throughput>,
36    /// Packet loss as a fraction in \[0.0, 1.0\] when known.
37    pub packet_loss: Option<f64>,
38}