Add uplink meta-data logging.

This commit is contained in:
Orne Brocaar 2022-11-02 14:42:25 +00:00
parent 937f12d4e8
commit 0d14bb1ac7
3 changed files with 67 additions and 8 deletions

View File

@ -186,6 +186,21 @@ impl FromProto<Aggregation> for common::Aggregation {
}
}
impl ToProto<common::MType> for lrwn::MType {
fn to_proto(self) -> common::MType {
match self {
lrwn::MType::JoinRequest => common::MType::JoinRequest,
lrwn::MType::JoinAccept => common::MType::JoinAccept,
lrwn::MType::UnconfirmedDataUp => common::MType::UnconfirmedDataUp,
lrwn::MType::UnconfirmedDataDown => common::MType::UnconfirmedDataDown,
lrwn::MType::ConfirmedDataUp => common::MType::ConfirmedDataUp,
lrwn::MType::ConfirmedDataDown => common::MType::ConfirmedDataDown,
lrwn::MType::RejoinRequest => common::MType::RejoinRequest,
lrwn::MType::Proprietary => common::MType::Proprietary,
}
}
}
pub fn datetime_to_prost_timestamp(dt: &DateTime<Utc>) -> prost_types::Timestamp {
let ts = dt.timestamp_nanos();

View File

@ -6,14 +6,15 @@ use tracing::{debug, error, info, span, trace, warn, Instrument, Level};
use super::error::Error;
use super::{data_fns, filter_rx_info_by_tenant_id, helpers, UplinkFrameSet};
use crate::api::helpers::ToProto;
use crate::backend::roaming;
use crate::storage::error::Error as StorageError;
use crate::storage::{
application, device, device_gateway, device_profile, device_queue, device_session, fields,
metrics, tenant,
};
use crate::{codec, config, downlink, framelog, integration, maccommand};
use chirpstack_api::{api, common, integration as integration_pb, internal};
use crate::{codec, config, downlink, framelog, integration, maccommand, metalog};
use chirpstack_api::{api, common, integration as integration_pb, internal, meta};
use lrwn::AES128Key;
pub struct Data {
@ -28,7 +29,6 @@ pub struct Data {
device_profile: Option<device_profile::DeviceProfile>,
application: Option<application::Application>,
device_info: Option<integration_pb::DeviceInfo>,
mac_payload: Option<lrwn::MACPayload>,
uplink_event: Option<integration_pb::UplinkEvent>,
must_send_downlink: bool,
downlink_mac_commands: Vec<lrwn::MACCommandSet>,
@ -63,7 +63,6 @@ impl Data {
device_profile: None,
application: None,
device_info: None,
mac_payload: None,
uplink_event: None,
must_send_downlink: false,
downlink_mac_commands: Vec::new(),
@ -93,8 +92,7 @@ impl Data {
ctx.set_adr()?;
ctx.set_uplink_data_rate().await?;
ctx.set_enabled_class().await?;
// ctx.send_uplink_meta_data_to_network_controller()?;
ctx.log_uplink_meta().await?;
ctx.handle_mac_commands().await?;
if !ctx._is_roaming() {
ctx.save_device_gateway_rx_info().await?;
@ -500,6 +498,52 @@ impl Data {
Ok(())
}
async fn log_uplink_meta(&self) -> Result<()> {
trace!("Logging uplink meta");
if let lrwn::Payload::MACPayload(mac_pl) = &self.uplink_frame_set.phy_payload.payload {
let um = meta::UplinkMeta {
dev_eui: self.device.as_ref().unwrap().dev_eui.to_string(),
tx_info: Some(self.uplink_frame_set.tx_info.clone()),
rx_info: self.uplink_frame_set.rx_info_set.clone(),
phy_payload_byte_count: self.uplink_frame_set.phy_payload.to_vec()?.len() as u32,
mac_command_byte_count: {
if mac_pl.f_port == Some(0) {
if let Some(lrwn::FRMPayload::MACCommandSet(v)) = &mac_pl.frm_payload {
v.size()?
} else {
0
}
} else {
mac_pl.fhdr.f_opts.size()?
}
} as u32,
application_payload_byte_count: {
if mac_pl.f_port.unwrap_or_default() > 0 {
if let Some(lrwn::FRMPayload::Raw(b)) = &mac_pl.frm_payload {
b.len()
} else {
0
}
} else {
0
}
} as u32,
message_type: self
.uplink_frame_set
.phy_payload
.mhdr
.m_type
.to_proto()
.into(),
};
metalog::log_uplink(&um).await?;
}
Ok(())
}
async fn handle_mac_commands(&mut self) -> Result<()> {
trace!("Handling uplink mac-commands");

View File

@ -583,7 +583,7 @@ impl JoinRequest {
async fn log_uplink_meta(&self) -> Result<()> {
trace!("Logging uplink meta");
let req = meta::UplinkMeta {
let um = meta::UplinkMeta {
dev_eui: self.device.as_ref().unwrap().dev_eui.to_string(),
tx_info: Some(self.uplink_frame_set.tx_info.clone()),
rx_info: self.uplink_frame_set.rx_info_set.clone(),
@ -592,7 +592,7 @@ impl JoinRequest {
..Default::default()
};
metalog::log_uplink(&req).await?;
metalog::log_uplink(&um).await?;
Ok(())
}