|
| 1 | +#[macro_use] |
| 2 | +extern crate anyhow; |
| 3 | + |
| 4 | +use std::time::Duration; |
| 5 | + |
| 6 | +use chirpstack_api::gw; |
| 7 | +use chirpstack_api::prost::Message; |
| 8 | +use tokio::time::{sleep, timeout}; |
| 9 | +use zeromq::{SocketRecv, SocketSend}; |
| 10 | + |
| 11 | +mod common; |
| 12 | + |
| 13 | +/* |
| 14 | + This tests the scenario when the Relay Gateway receives an uplink LoRaWAN |
| 15 | + frame. As the uplink DevAddr does not match the configured filters, it is |
| 16 | + not forwarded. |
| 17 | +*/ |
| 18 | +#[tokio::test] |
| 19 | +async fn test_relay_gateway_uplink_lora() { |
| 20 | + common::setup(false).await; |
| 21 | + |
| 22 | + let up = gw::UplinkFrame { |
| 23 | + phy_payload: vec![0x02 << 5, 1, 2, 3, 4], |
| 24 | + tx_info: Some(gw::UplinkTxInfo { |
| 25 | + frequency: 868300000, |
| 26 | + modulation: Some(gw::Modulation { |
| 27 | + parameters: Some(gw::modulation::Parameters::Lora(gw::LoraModulationInfo { |
| 28 | + bandwidth: 125000, |
| 29 | + spreading_factor: 12, |
| 30 | + code_rate: gw::CodeRate::Cr45.into(), |
| 31 | + ..Default::default() |
| 32 | + })), |
| 33 | + }), |
| 34 | + }), |
| 35 | + rx_info: Some(gw::UplinkRxInfo { |
| 36 | + gateway_id: "0101010101010101".to_string(), |
| 37 | + crc_status: gw::CrcStatus::CrcOk.into(), |
| 38 | + rssi: -60, |
| 39 | + snr: 12.0, |
| 40 | + ..Default::default() |
| 41 | + }), |
| 42 | + ..Default::default() |
| 43 | + }; |
| 44 | + |
| 45 | + // Publish uplink event. |
| 46 | + { |
| 47 | + let mut event_sock = common::BACKEND_EVENT_SOCK.get().unwrap().lock().await; |
| 48 | + let event = gw::Event { |
| 49 | + event: Some(gw::event::Event::UplinkFrame(up.clone())), |
| 50 | + }; |
| 51 | + event_sock |
| 52 | + .send( |
| 53 | + vec![bytes::Bytes::from(event.encode_to_vec())] |
| 54 | + .try_into() |
| 55 | + .unwrap(), |
| 56 | + ) |
| 57 | + .await |
| 58 | + .unwrap(); |
| 59 | + } |
| 60 | + |
| 61 | + // Wait a little bit. |
| 62 | + sleep(Duration::from_millis(200)).await; |
| 63 | + |
| 64 | + let mut cmd_sock = common::MESH_BACKEND_COMMAND_SOCK |
| 65 | + .get() |
| 66 | + .unwrap() |
| 67 | + .lock() |
| 68 | + .await; |
| 69 | + |
| 70 | + let res = timeout(Duration::from_millis(100), cmd_sock.recv()).await; |
| 71 | + assert!(res.is_err()); |
| 72 | +} |
0 commit comments