Skip to content

Commit 5431185

Browse files
committed
Fix uplink filters + add test.
While we did log that the uplink was discarded, it was not actually discarded as we did not return.
1 parent 7c7c4c1 commit 5431185

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

src/backend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ async fn handle_event_msg(
303303
debug!(
304304
"Discarding uplink because of dev_addr and join_eui filters, uplink_id: {}",
305305
rx_info.uplink_id
306-
)
306+
);
307+
return Ok(());
307308
}
308309

309310
info!("Frame received - {}", helpers::format_uplink(v)?);

tests/common/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::sync::OnceLock;
21
use std::time::Duration;
2+
use std::{str::FromStr, sync::OnceLock};
33

44
use tokio::fs::remove_file;
55
use tokio::sync::Mutex;
@@ -44,6 +44,12 @@ pub fn get_config(border_gateway: bool) -> Configuration {
4444
command_bind: "ipc:///tmp/gateway_mesh_command".into(),
4545
},
4646
max_hop_count: 3,
47+
filters: config::Filters {
48+
dev_addr_prefixes: vec![
49+
lrwn_filters::DevAddrPrefix::from_str("00000000/8").unwrap(),
50+
],
51+
..Default::default()
52+
},
4753
..Default::default()
4854
},
4955
backend: config::Backend {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)