ndn_strategy/
cross_layer.rs

1use ndn_transport::FaceId;
2use smallvec::SmallVec;
3
4/// Per-face link quality snapshot inserted into `StrategyContext::extensions`.
5///
6/// Access from a strategy: `ctx.extensions.get::<LinkQualitySnapshot>()`.
7///
8/// Populated by a `ContextEnricher` in `ndn-engine` that reads from
9/// `RadioTable`, `FlowTable`, or other data sources.
10#[derive(Clone, Debug)]
11pub struct LinkQualitySnapshot {
12    /// Link quality entries, one per known face.
13    pub per_face: SmallVec<[FaceLinkQuality; 4]>,
14}
15
16impl LinkQualitySnapshot {
17    /// Look up link quality for a specific face.
18    pub fn for_face(&self, face_id: FaceId) -> Option<&FaceLinkQuality> {
19        self.per_face.iter().find(|f| f.face_id == face_id)
20    }
21}
22
23/// Link quality metrics for a single face.
24///
25/// All fields are `Option` so that:
26/// - Missing data sources simply leave fields as `None`.
27/// - New metrics can be added without breaking existing strategies.
28#[derive(Clone, Debug)]
29pub struct FaceLinkQuality {
30    /// The face these metrics belong to.
31    pub face_id: FaceId,
32    /// RSSI in dBm (from RadioTable / nl80211). Typical range: -90 to -20.
33    pub rssi_dbm: Option<i8>,
34    /// MAC-layer retransmit rate (0.0 = no retransmits, 1.0 = every frame retransmitted).
35    pub retransmit_rate: Option<f32>,
36    /// Observed RTT in milliseconds (from FlowTable or MeasurementsTable).
37    pub observed_rtt_ms: Option<f64>,
38    /// Observed throughput in bytes/sec (from FlowTable).
39    pub observed_tput: Option<f64>,
40}