tramex_tools/interface/
layer.rs

1//! Layer enum and Layers struct
2use std::fmt;
3use std::fmt::Display;
4use std::fmt::Formatter;
5use std::str::FromStr;
6
7#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
8/// Layer enum
9pub enum Layer {
10    /// Physical layer
11    PHY,
12
13    /// Medium Access Control layer
14    MAC,
15
16    /// Radio Link Control layer
17    RLC,
18
19    /// Packet Data Convergence Protocol layer
20    PDCP,
21
22    /// Radio Resource Control layer
23    RRC,
24
25    /// Non Access Stratum layer
26    NAS,
27
28    /// S1 Application Protocol layer
29    S1AP,
30
31    /// Next Generation Application Protocol layer
32    NGAP,
33
34    /// X2 Application Protocol layer
35    X2AP,
36
37    /// Xn Application Protocol layer
38    XNAP,
39
40    /// M2 Application Protocol layer
41    M2AP,
42
43    /// LTE Positioning Protocol A layer
44    LPPA,
45
46    /// NR Positioning Protocol A layer
47    NRPPA,
48
49    /// GTPU layer
50    GTPU,
51
52    /// Special layer of amarisoft
53    PROD,
54}
55
56impl FromStr for Layer {
57    type Err = ();
58
59    fn from_str(input: &str) -> Result<Layer, Self::Err> {
60        match input {
61            "PHY" => Ok(Layer::PHY),
62            "MAC" => Ok(Layer::MAC),
63            "RLC" => Ok(Layer::RLC),
64            "PDCP" => Ok(Layer::PDCP),
65            "RRC" => Ok(Layer::RRC),
66            "NAS" => Ok(Layer::NAS),
67            "S1AP" => Ok(Layer::S1AP),
68            "NGAP" => Ok(Layer::NGAP),
69            "X2AP" => Ok(Layer::X2AP),
70            "XNAP" => Ok(Layer::XNAP),
71            "M2AP" => Ok(Layer::M2AP),
72            "LPPA" => Ok(Layer::LPPA),
73            "NRPPA" => Ok(Layer::NRPPA),
74            "GTPU" => Ok(Layer::GTPU),
75            _ => Err(()),
76        }
77    }
78}
79
80#[derive(Debug, serde::Deserialize, Clone, Default)]
81/// LayerLogLevel enum
82pub enum LayerLogLevel {
83    /// Debug log level
84    Debug,
85
86    #[default]
87    /// Warn log level
88    Warn,
89}
90
91impl serde::Serialize for LayerLogLevel {
92    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
93    where
94        S: serde::Serializer,
95    {
96        match *self {
97            LayerLogLevel::Debug => serializer.serialize_str("debug"),
98            LayerLogLevel::Warn => serializer.serialize_str("warn"),
99        }
100    }
101}
102
103impl Display for LayerLogLevel {
104    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
105        match self {
106            LayerLogLevel::Debug => write!(f, "debug"),
107            LayerLogLevel::Warn => write!(f, "warn"),
108        }
109    }
110}
111
112#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
113/// Layers struct
114pub struct Layers {
115    #[serde(rename(serialize = "PHY"))]
116    /// Physical layer
117    pub phy: LayerLogLevel,
118
119    #[serde(rename(serialize = "MAC"))]
120    /// Medium Access Control layer
121    pub mac: LayerLogLevel,
122
123    #[serde(rename(serialize = "RLC"))]
124    /// Radio Link Control layer
125    pub rlc: LayerLogLevel,
126
127    #[serde(rename(serialize = "PDCP"))]
128    /// Packet Data Convergence Protocol layer
129    pub pdcp: LayerLogLevel,
130
131    #[serde(rename(serialize = "RRC"))]
132    /// Radio Resource Control layer
133    pub rrc: LayerLogLevel,
134
135    #[serde(rename(serialize = "NAS"))]
136    /// Non Access Stratum layer
137    pub nas: LayerLogLevel,
138
139    #[serde(rename(serialize = "S72"))]
140    /// S1 Application Protocol layer
141    pub s72: LayerLogLevel,
142
143    #[serde(rename(serialize = "S1AP"))]
144    /// S1 Application Protocol layer
145    pub s1ap: LayerLogLevel,
146
147    #[serde(rename(serialize = "NGAP"))]
148    /// Next Generation Application Protocol layer
149    pub ngap: LayerLogLevel,
150
151    #[serde(rename(serialize = "GTPU"))]
152    /// GTPU layer
153    pub gtpu: LayerLogLevel,
154
155    #[serde(rename(serialize = "X2AP"))]
156    /// X2 Application Protocol layer
157    pub x2ap: LayerLogLevel,
158
159    #[serde(rename(serialize = "XnAP"))]
160    /// Xn Application Protocol layer
161    pub xnap: LayerLogLevel,
162
163    #[serde(rename(serialize = "M2AP"))]
164    /// M2 Application Protocol layer
165    pub m2ap: LayerLogLevel,
166
167    #[serde(rename(serialize = "LPPa"))]
168    /// LTE Positioning Protocol A layer
169    pub lppa: LayerLogLevel,
170
171    #[serde(rename(serialize = "NRPPa"))]
172    /// NR Positioning Protocol A layer
173    pub nrppa: LayerLogLevel,
174
175    #[serde(rename(serialize = "TRX"))]
176    /// TRX layer
177    pub trx: LayerLogLevel,
178}
179
180impl Layers {
181    /// Create new Layers struct
182    pub fn new() -> Self {
183        Self::default()
184    }
185
186    /// Create new Layers but in an optiniated way
187    pub fn new_optiniated() -> Self {
188        let mut layers = Layers::new();
189        layers.rrc = LayerLogLevel::Debug;
190        layers
191    }
192
193    /// Create new Layers struct with all debug
194    pub fn all_debug() -> Self {
195        Self {
196            phy: LayerLogLevel::Debug,
197            mac: LayerLogLevel::Debug,
198            rlc: LayerLogLevel::Debug,
199            pdcp: LayerLogLevel::Debug,
200            rrc: LayerLogLevel::Debug,
201            nas: LayerLogLevel::Debug,
202            s72: LayerLogLevel::Debug,
203            s1ap: LayerLogLevel::Debug,
204            ngap: LayerLogLevel::Debug,
205            gtpu: LayerLogLevel::Debug,
206            x2ap: LayerLogLevel::Debug,
207            xnap: LayerLogLevel::Debug,
208            m2ap: LayerLogLevel::Debug,
209            lppa: LayerLogLevel::Debug,
210            nrppa: LayerLogLevel::Debug,
211            trx: LayerLogLevel::Debug,
212        }
213    }
214}