1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use crate::devices::chip::ChipIdentifier;
16 use crate::wireless::{WirelessAdaptor, WirelessAdaptorImpl};
17
18 use bytes::Bytes;
19 use netsim_proto::common::ChipKind as ProtoChipKind;
20 use netsim_proto::model::Chip as ProtoChip;
21 use netsim_proto::stats::{netsim_radio_stats, NetsimRadioStats as ProtoRadioStats};
22 use protobuf::EnumOrUnknown;
23
24 /// Parameters for creating Mocked chips
25 pub struct CreateParams {
26 pub chip_kind: ProtoChipKind,
27 }
28
29 /// Mock struct is remained empty.
30 pub struct Mock {
31 chip_kind: ProtoChipKind,
32 }
33
34 impl WirelessAdaptor for Mock {
handle_request(&self, _packet: &Bytes)35 fn handle_request(&self, _packet: &Bytes) {}
36
reset(&self)37 fn reset(&self) {}
38
get(&self) -> ProtoChip39 fn get(&self) -> ProtoChip {
40 let mut proto_chip = ProtoChip::new();
41 proto_chip.kind = EnumOrUnknown::new(self.chip_kind);
42 proto_chip
43 }
44
patch(&self, _chip: &ProtoChip)45 fn patch(&self, _chip: &ProtoChip) {}
46
get_stats(&self, _duration_secs: u64) -> Vec<ProtoRadioStats>47 fn get_stats(&self, _duration_secs: u64) -> Vec<ProtoRadioStats> {
48 let mut stats = ProtoRadioStats::new();
49 stats.kind = Some(EnumOrUnknown::new(match self.chip_kind {
50 ProtoChipKind::UNSPECIFIED => netsim_radio_stats::Kind::UNSPECIFIED,
51 ProtoChipKind::BLUETOOTH => netsim_radio_stats::Kind::BLUETOOTH_LOW_ENERGY,
52 ProtoChipKind::WIFI => netsim_radio_stats::Kind::WIFI,
53 ProtoChipKind::UWB => netsim_radio_stats::Kind::UWB,
54 ProtoChipKind::BLUETOOTH_BEACON => netsim_radio_stats::Kind::BLE_BEACON,
55 }));
56 vec![stats]
57 }
58 }
59
60 /// Create a new MockedChip
new(create_params: &CreateParams, _chip_id: ChipIdentifier) -> WirelessAdaptorImpl61 pub fn new(create_params: &CreateParams, _chip_id: ChipIdentifier) -> WirelessAdaptorImpl {
62 Box::new(Mock { chip_kind: create_params.chip_kind })
63 }
64