feat(measurement): implement ICMP measurement engine
This commit is contained in:
5 files changed
+611
-3
No files matched your search
@@ -6,6 +6,7 @@ use std::{
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct MeasurementStreamId(pub u64);
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum MeasurementSource {
|
||||
IcmpEcho,
|
||||
@@ -22,17 +23,54 @@ pub struct MeasurementStream {
|
||||
pub source: MeasurementSource,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum OneWayClock {
|
||||
Uncalibrated,
|
||||
Calibrated,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ProbeSchedule {
|
||||
pub period: Duration,
|
||||
pub offset: Duration,
|
||||
}
|
||||
|
||||
impl ProbeSchedule {
|
||||
pub(crate) fn next_probe_at(&self, origin: Instant, now: Instant) -> Instant {
|
||||
const NANOS_PER_SEC: u128 = 1_000_000_000;
|
||||
|
||||
let first = origin + self.offset;
|
||||
|
||||
if now < first {
|
||||
return first;
|
||||
}
|
||||
|
||||
let elapsed_ns = now.duration_since(first).as_nanos();
|
||||
let period_ns = self.period.as_nanos();
|
||||
let remainder = elapsed_ns % period_ns;
|
||||
|
||||
let until_next = if remainder == 0 {
|
||||
period_ns
|
||||
} else {
|
||||
period_ns - remainder
|
||||
};
|
||||
|
||||
let until_next = Duration::new(
|
||||
(until_next / NANOS_PER_SEC) as u64,
|
||||
(until_next % NANOS_PER_SEC) as u32,
|
||||
);
|
||||
|
||||
now + until_next
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct SignedDuration {
|
||||
nanos: i64,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl SignedDuration {
|
||||
pub const fn from_nanos(nanos: i64) -> Self {
|
||||
Self { nanos }
|
||||
@@ -60,6 +98,7 @@ pub struct OneWayLatency {
|
||||
pub clock: OneWayClock,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct MeasurementObservation {
|
||||
pub stream: MeasurementStream,
|
||||
@@ -74,6 +113,7 @@ pub struct MeasurementObservation {
|
||||
pub one_way: Option<OneWayLatency>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl MeasurementObservation {
|
||||
pub fn rtt(&self) -> Duration {
|
||||
self.observed_at.duration_since(self.started_at)
|
||||
@@ -84,12 +124,14 @@ impl MeasurementObservation {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct MeasurementLoss {
|
||||
pub stream: MeasurementStream,
|
||||
pub started_at: Instant,
|
||||
pub detected_at: Instant,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum MeasurementEvent {
|
||||
Observation(MeasurementObservation),
|
||||
Loss(MeasurementLoss),
|
||||
|
||||
Reference in new issue
Block a user