wlancfg_lib/client/roaming/roam_monitor/
default_monitor.rs

1// Copyright 2024 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 crate::client::roaming::lib::*;
6use crate::client::roaming::roam_monitor::{RoamMonitorApi, RoamTriggerDataOutcome};
7use anyhow::format_err;
8use log::error;
9
10pub struct DefaultRoamMonitor {}
11
12impl Default for DefaultRoamMonitor {
13    fn default() -> Self {
14        Self::new()
15    }
16}
17
18impl DefaultRoamMonitor {
19    pub fn new() -> Self {
20        Self {}
21    }
22}
23
24use async_trait::async_trait;
25#[async_trait(?Send)]
26impl RoamMonitorApi for DefaultRoamMonitor {
27    async fn handle_roam_trigger_data(
28        &mut self,
29        _data: RoamTriggerData,
30    ) -> Result<RoamTriggerDataOutcome, anyhow::Error> {
31        // Default response to noop. Metrics for default devices can be added here.
32        Ok(RoamTriggerDataOutcome::Noop)
33    }
34    fn should_send_roam_request(&self, request: PolicyRoamRequest) -> Result<bool, anyhow::Error> {
35        Err(format_err!(
36            "Default roam monitor unexpectedly received a roam candidate: {}, roam reasons: {:?}",
37            request.candidate.to_string_without_pii(),
38            request.reasons
39        ))
40    }
41    fn notify_of_roam_attempt(&mut self) {
42        error!("Default roam monitor unexpectedly receieved notification of roam attempt");
43    }
44}
45#[cfg(test)]
46mod test {
47    use super::*;
48    use crate::util::testing::generate_random_scanned_candidate;
49    use assert_matches::assert_matches;
50    use fidl_fuchsia_wlan_internal as fidl_internal;
51
52    #[fuchsia_async::run_singlethreaded(test)]
53    async fn test_handle_roam_trigger_data_always_returns_noop() {
54        let mut monitor = DefaultRoamMonitor::new();
55
56        // Send each type of trigger data and verify the default monitor always returns noop.
57        assert_matches!(
58            monitor
59                .handle_roam_trigger_data(RoamTriggerData::SignalReportInd(
60                    fidl_internal::SignalReportIndication { rssi_dbm: -100, snr_db: 0 },
61                ))
62                .await,
63            Ok(RoamTriggerDataOutcome::Noop)
64        );
65    }
66
67    #[fuchsia_async::run_singlethreaded(test)]
68    async fn test_should_send_roam_request_returns_error() {
69        let monitor = DefaultRoamMonitor::new();
70
71        // Send a candidate and verify an error is returned
72        let candidate = generate_random_scanned_candidate();
73        assert_matches!(
74            monitor.should_send_roam_request(PolicyRoamRequest { candidate, reasons: vec![] }),
75            Err(_)
76        );
77    }
78}