statime/observability/
current.rs

1use crate::{datastructures::datasets::InternalCurrentDS, filters::FilterEstimate, time::Duration};
2
3/// A concrete implementation of the PTP Current dataset (IEEE1588-2019 section
4/// 8.2.2)
5///
6/// Note that the `meanDelay` field from IEEE1588-2019 section 8.2.2.4 is
7/// missing since this field can be constructed from the portDS.
8#[derive(Debug, Default, Copy, Clone)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct CurrentDS {
11    /// See *IEEE1588-2019 section 8.2.2.2*.
12    pub steps_removed: u16,
13    /// See *IEEE1588-2019 section 8.2.2.3*.
14    pub offset_from_master: Duration,
15    /// See *IEEE1588-2019 section 8.2.2.3*.
16    pub mean_delay: Duration,
17}
18
19impl CurrentDS {
20    pub(crate) fn from_state(
21        current_ds: &InternalCurrentDS,
22        port_contribution: Option<FilterEstimate>,
23    ) -> Self {
24        match port_contribution {
25            Some(port_contribution) => Self {
26                steps_removed: current_ds.steps_removed,
27                offset_from_master: port_contribution.offset_from_master,
28                mean_delay: port_contribution.mean_delay,
29            },
30            None => Self {
31                steps_removed: current_ds.steps_removed,
32                offset_from_master: Duration::ZERO,
33                mean_delay: Duration::ZERO,
34            },
35        }
36    }
37}