reachability_core/telemetry/
convert.rs

1// Copyright 2023 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
5use network_policy_metrics_registry as metrics;
6
7use crate::{IpVersions, State};
8
9pub(crate) fn convert_yes_no_dim(
10    b: bool,
11) -> metrics::ReachabilityGlobalSnapshotDurationMetricDimensionInternetAvailable {
12    if b {
13        metrics::ReachabilityGlobalSnapshotDurationMetricDimensionInternetAvailable::Yes
14    } else {
15        metrics::ReachabilityGlobalSnapshotDurationMetricDimensionInternetAvailable::No
16    }
17}
18
19pub(crate) fn convert_route_config(
20    global_system_state: &IpVersions<Option<State>>,
21) -> Option<metrics::ReachabilityGlobalSnapshotDurationMetricDimensionRouteConfig> {
22    match (global_system_state.ipv4.is_some(), global_system_state.ipv6.is_some()) {
23        (true, true) => {
24            Some(metrics::ReachabilityGlobalSnapshotDurationMetricDimensionRouteConfig::Ipv4Ipv6)
25        }
26        (true, false) => {
27            Some(metrics::ReachabilityGlobalSnapshotDurationMetricDimensionRouteConfig::Ipv4Only)
28        }
29        (false, true) => {
30            Some(metrics::ReachabilityGlobalSnapshotDurationMetricDimensionRouteConfig::Ipv6Only)
31        }
32        (false, false) => None,
33    }
34}
35
36pub(crate) fn convert_default_route(
37    has_ipv4: bool,
38    has_ipv6: bool,
39) -> Option<metrics::ReachabilityGlobalDefaultRouteDurationMetricDimensionDefaultRoute> {
40    match (has_ipv4, has_ipv6) {
41        (true, true) => Some(
42            metrics::ReachabilityGlobalDefaultRouteDurationMetricDimensionDefaultRoute::Ipv4Ipv6,
43        ),
44        (true, false) => Some(
45            metrics::ReachabilityGlobalDefaultRouteDurationMetricDimensionDefaultRoute::Ipv4Only,
46        ),
47        (false, true) => Some(
48            metrics::ReachabilityGlobalDefaultRouteDurationMetricDimensionDefaultRoute::Ipv6Only,
49        ),
50        (false, false) => None,
51    }
52}