tramex_tools/interface/
onelog.rs1use std::str::FromStr;
4
5use crate::data::Trace;
6use crate::errors::TramexError;
7use crate::interface::functions::extract_hexe;
8use crate::interface::parser::ParsedHeader;
9
10use crate::interface::{layer::Layer, types::SourceLog};
11use crate::tramex_error;
12
13use super::types::Direction;
14
15#[derive(serde::Deserialize, Debug)]
16pub struct OneLog {
18 pub data: Vec<String>,
20
21 pub timestamp: i64,
23
24 pub layer: Layer,
26
27 pub src: SourceLog,
29
30 pub idx: u64,
32
33 pub dir: Option<String>,
35
36 pub ue_id: Option<u64>,
38
39 pub cell: Option<u64>,
41
42 pub rnti: Option<u64>,
44
45 pub frame: Option<u16>,
47
48 pub slot: Option<u8>,
50
51 pub channel: Option<String>,
53
54 pub level: Option<u8>,
56}
57
58impl OneLog {
59 pub fn extract_hexe(&self) -> Result<Vec<u8>, TramexError> {
63 extract_hexe(&self.data)
64 }
65
66 pub fn extract_canal_msg(&self) -> Option<String> {
68 if let Some(data_line) = self.data.first() {
70 log::debug!("{data_line:?}");
71 return Some(data_line.to_owned());
72 }
73 None
74 }
75
76 fn build_header(&self) -> Result<ParsedHeader, TramexError> {
81 let direction = match &self.dir {
82 Some(opt_dir) => Direction::from_str(opt_dir).unwrap_or(Direction::NA),
83 None => Direction::NA,
84 };
85
86 Ok(ParsedHeader {
87 timestamp: self.timestamp,
88 layer: self.layer.clone(),
89 direction,
90 ue_id: self.ue_id,
91 cell: self.cell,
92 rnti: self.rnti,
93 frame: self.frame,
94 slot: self.slot,
95 channel: self.channel.clone(),
96 connection_info: None,
97 })
98 }
99
100 pub fn extract_data(&self) -> Result<Trace, TramexError> {
104 use crate::interface::parser::LayerParser;
105 use crate::interface::parser::build_trace;
106 use crate::interface::parser::parser_basic::BasicParser;
107 use crate::interface::parser::parser_gtpu::GTPUParser;
108 use crate::interface::parser::parser_nas::NASParser;
109 use crate::interface::parser::parser_ngap::NGAPParser;
110 use crate::interface::parser::parser_phy::PHYParser;
111 use crate::interface::parser::parser_rrc::RRCParser;
112
113 let header = self.build_header()?;
114
115 let additional_infos = match self.layer {
116 Layer::RRC => RRCParser::parse_layer(&header, &self.data),
117 Layer::NAS => NASParser::parse_layer(&header, &self.data),
118 Layer::NGAP => NGAPParser::parse_layer(&header, &self.data),
119 Layer::GTPU => GTPUParser::parse_layer(&header, &self.data),
120 Layer::PHY => PHYParser::parse_layer(&header, &self.data),
121 _ => BasicParser::parse_layer(&header, &self.data),
122 }
123 .map_err(|e| tramex_error!(e.message, crate::errors::ErrorCode::ParsingLayerNotImplemented))?;
124
125 Ok(build_trace(&header, additional_infos, &self.data))
126 }
127}