use std::str::FromStr;
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub enum Layer {
PHY,
MAC,
RLC,
PDCP,
RRC,
NAS,
S1AP,
NGAP,
X2AP,
XNAP,
M2AP,
LPPA,
NRPPA,
GTPU,
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)]
pub enum LayerLogLevel {
Debug,
#[default]
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)]
pub struct Layers {
#[serde(rename(serialize = "PHY"))]
pub phy: LayerLogLevel,
#[serde(rename(serialize = "MAC"))]
pub mac: LayerLogLevel,
#[serde(rename(serialize = "RLC"))]
pub rlc: LayerLogLevel,
#[serde(rename(serialize = "PDCP"))]
pub pdcp: LayerLogLevel,
#[serde(rename(serialize = "RRC"))]
pub rrc: LayerLogLevel,
#[serde(rename(serialize = "NAS"))]
pub nas: LayerLogLevel,
#[serde(rename(serialize = "S72"))]
pub s72: LayerLogLevel,
#[serde(rename(serialize = "S1AP"))]
pub s1ap: LayerLogLevel,
#[serde(rename(serialize = "NGAP"))]
pub ngap: LayerLogLevel,
#[serde(rename(serialize = "GTPU"))]
pub gtpu: LayerLogLevel,
#[serde(rename(serialize = "X2AP"))]
pub x2ap: LayerLogLevel,
#[serde(rename(serialize = "XnAP"))]
pub xnap: LayerLogLevel,
#[serde(rename(serialize = "M2AP"))]
pub m2ap: LayerLogLevel,
#[serde(rename(serialize = "LPPa"))]
pub lppa: LayerLogLevel,
#[serde(rename(serialize = "NRPPa"))]
pub nrppa: LayerLogLevel,
#[serde(rename(serialize = "TRX"))]
pub trx: LayerLogLevel,
}
impl Layers {
pub fn new() -> Self {
Self::default()
}
pub fn new_optiniated() -> Self {
let mut layers = Layers::new();
layers.rrc = LayerLogLevel::Debug;
layers
}
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,
}
}
}