Skip to main content

reachability_core/telemetry/processors/
mod.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub mod interface_aware_logger;
6pub mod link_properties_state;
7
8use fidl_fuchsia_net_interfaces_ext::PortClass;
9
10// TODO(https://fxbug.dev/432299715): Share this definition with netcfg.
11//
12// The classification of the interface. This is not necessarily the same
13// as the PortClass of the interface.
14#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
15pub enum InterfaceType {
16    Ethernet,
17    WlanClient,
18    WlanAp,
19    Blackhole,
20    Bluetooth,
21    Virtual,
22}
23
24impl std::fmt::Display for InterfaceType {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        let name = format!("{:?}", self);
27        write!(f, "{}", name.to_lowercase())
28    }
29}
30
31// TODO(https://fxbug.dev/432301507): Read this from shared configuration.
32// TODO(https://fxbug.dev/432298588): Add Id and Name as alternate groupings.
33//
34// The specifier for how the time series are initialized. For example, if Type
35// is specified with Ethernet and WlanClient, then there will be a separate
36// time series for Ethernet and WlanClient updates, further broken down by
37// v4 and v6 protocols.
38pub enum InterfaceTimeSeriesGrouping {
39    Type(Vec<InterfaceType>),
40}
41
42// TODO(https://fxbug.dev/432298588): Add Id and Name as alternate groupings.
43//
44// The identifier for the interface. Used to determine which time series should
45// have updates applied.
46#[derive(Clone, Debug, Eq, Hash, PartialEq)]
47pub enum InterfaceIdentifier {
48    // An interface is expected to only have a single type.
49    Type(InterfaceType),
50}
51
52impl std::fmt::Display for InterfaceIdentifier {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        let name = match self {
55            Self::Type(ty) => format!("TYPE_{ty}"),
56        };
57        write!(f, "{}", name)
58    }
59}
60
61pub fn identifiers_from_port_class(port_class: PortClass) -> Vec<InterfaceIdentifier> {
62    match port_class {
63        PortClass::Ethernet => vec![InterfaceType::Ethernet],
64        PortClass::WlanClient => vec![InterfaceType::WlanClient],
65        PortClass::WlanAp => vec![InterfaceType::WlanAp],
66        PortClass::Blackhole => vec![InterfaceType::Blackhole],
67        PortClass::Loopback => vec![InterfaceType::Bluetooth, InterfaceType::Virtual],
68        PortClass::Virtual | PortClass::Ppp | PortClass::Bridge | PortClass::Lowpan => {
69            vec![InterfaceType::Virtual]
70        }
71    }
72    .into_iter()
73    .map(|port_class| InterfaceIdentifier::Type(port_class))
74    .collect()
75}