1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! Layer enum and Layers struct
use std::str::FromStr;

#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
/// Layer enum
pub enum Layer {
    /// Physical layer
    PHY,

    /// Medium Access Control layer
    MAC,

    /// Radio Link Control layer
    RLC,

    /// Packet Data Convergence Protocol layer
    PDCP,

    /// Radio Resource Control layer
    RRC,

    /// Non Access Stratum layer
    NAS,

    /// S1 Application Protocol layer
    S1AP,

    /// Next Generation Application Protocol layer
    NGAP,

    /// X2 Application Protocol layer
    X2AP,

    /// Xn Application Protocol layer
    XNAP,

    /// M2 Application Protocol layer
    M2AP,

    /// LTE Positioning Protocol A layer
    LPPA,

    /// NR Positioning Protocol A layer
    NRPPA,

    /// GTPU layer
    GTPU,

    /// Special layer of amarisoft
    PROD,
}

impl FromStr for Layer {
    type Err = ();

    fn from_str(input: &str) -> Result<Layer, Self::Err> {
        match input {
            "PHY" => Ok(Layer::PHY),
            "MAC" => Ok(Layer::MAC),
            "RLC" => Ok(Layer::RLC),
            "PDCP" => Ok(Layer::PDCP),
            "RRC" => Ok(Layer::RRC),
            "NAS" => Ok(Layer::NAS),
            "S1AP" => Ok(Layer::S1AP),
            "NGAP" => Ok(Layer::NGAP),
            "X2AP" => Ok(Layer::X2AP),
            "XNAP" => Ok(Layer::XNAP),
            "M2AP" => Ok(Layer::M2AP),
            "LPPA" => Ok(Layer::LPPA),
            "NRPPA" => Ok(Layer::NRPPA),
            "GTPU" => Ok(Layer::GTPU),
            _ => Err(()),
        }
    }
}

#[derive(Debug, serde::Deserialize, Clone, Default)]
/// LayerLogLevel enum
pub enum LayerLogLevel {
    /// Debug log level
    Debug,

    #[default]
    /// Warn log level
    Warn,
}

impl serde::Serialize for LayerLogLevel {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        match *self {
            LayerLogLevel::Debug => serializer.serialize_str("debug"),
            LayerLogLevel::Warn => serializer.serialize_str("warn"),
        }
    }
}

impl ToString for LayerLogLevel {
    fn to_string(&self) -> String {
        match self {
            LayerLogLevel::Debug => "debug".to_string(),
            LayerLogLevel::Warn => "warn".to_string(),
        }
    }
}

#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
/// Layers struct
pub struct Layers {
    #[serde(rename(serialize = "PHY"))]
    /// Physical layer
    pub phy: LayerLogLevel,

    #[serde(rename(serialize = "MAC"))]
    /// Medium Access Control layer
    pub mac: LayerLogLevel,

    #[serde(rename(serialize = "RLC"))]
    /// Radio Link Control layer
    pub rlc: LayerLogLevel,

    #[serde(rename(serialize = "PDCP"))]
    /// Packet Data Convergence Protocol layer
    pub pdcp: LayerLogLevel,

    #[serde(rename(serialize = "RRC"))]
    /// Radio Resource Control layer
    pub rrc: LayerLogLevel,

    #[serde(rename(serialize = "NAS"))]
    /// Non Access Stratum layer
    pub nas: LayerLogLevel,

    #[serde(rename(serialize = "S72"))]
    /// S1 Application Protocol layer
    pub s72: LayerLogLevel,

    #[serde(rename(serialize = "S1AP"))]
    /// S1 Application Protocol layer
    pub s1ap: LayerLogLevel,

    #[serde(rename(serialize = "NGAP"))]
    /// Next Generation Application Protocol layer
    pub ngap: LayerLogLevel,

    #[serde(rename(serialize = "GTPU"))]
    /// GTPU layer
    pub gtpu: LayerLogLevel,

    #[serde(rename(serialize = "X2AP"))]
    /// X2 Application Protocol layer
    pub x2ap: LayerLogLevel,

    #[serde(rename(serialize = "XnAP"))]
    /// Xn Application Protocol layer
    pub xnap: LayerLogLevel,

    #[serde(rename(serialize = "M2AP"))]
    /// M2 Application Protocol layer
    pub m2ap: LayerLogLevel,

    #[serde(rename(serialize = "LPPa"))]
    /// LTE Positioning Protocol A layer
    pub lppa: LayerLogLevel,

    #[serde(rename(serialize = "NRPPa"))]
    /// NR Positioning Protocol A layer
    pub nrppa: LayerLogLevel,

    #[serde(rename(serialize = "TRX"))]
    /// TRX layer
    pub trx: LayerLogLevel,
}

impl Layers {
    /// Create new Layers struct
    pub fn new() -> Self {
        Self::default()
    }

    /// Create new Layers but in an optiniated way
    pub fn new_optiniated() -> Self {
        let mut layers = Layers::new();
        layers.rrc = LayerLogLevel::Debug;
        layers
    }

    /// Create new Layers struct with all debug
    pub fn all_debug() -> Self {
        Self {
            phy: LayerLogLevel::Debug,
            mac: LayerLogLevel::Debug,
            rlc: LayerLogLevel::Debug,
            pdcp: LayerLogLevel::Debug,
            rrc: LayerLogLevel::Debug,
            nas: LayerLogLevel::Debug,
            s72: LayerLogLevel::Debug,
            s1ap: LayerLogLevel::Debug,
            ngap: LayerLogLevel::Debug,
            gtpu: LayerLogLevel::Debug,
            x2ap: LayerLogLevel::Debug,
            xnap: LayerLogLevel::Debug,
            m2ap: LayerLogLevel::Debug,
            lppa: LayerLogLevel::Debug,
            nrppa: LayerLogLevel::Debug,
            trx: LayerLogLevel::Debug,
        }
    }
}