use crate::{arg_of, child_block};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct EnhancedForwardingClassAccounting {
pub overhead_bytes: Option<String>,
pub traffic_type: Option<String>,
pub family: Option<String>,
pub direction: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ForwardingClassAccounting {
pub direction: Option<String>,
pub enhanced: Option<EnhancedForwardingClassAccounting>,
}
pub(super) fn parse_forwarding_class_accounting(accounting: &ConfigLine) -> ForwardingClassAccounting {
ForwardingClassAccounting {
direction: arg_of(accounting, "direction").map(str::to_string),
enhanced: child_block(accounting, "enhanced").map(|enhanced| EnhancedForwardingClassAccounting {
overhead_bytes: arg_of(enhanced, "overhead-bytes").map(str::to_string),
traffic_type: arg_of(enhanced, "traffic-type").map(str::to_string),
family: arg_of(enhanced, "family").map(str::to_string),
direction: arg_of(enhanced, "direction").map(str::to_string),
}),
}
}
#[cfg(test)]
mod tests {
use crate::interfaces::interfaces;
use asterust::config::juniper;
#[test]
fn extracts_forwarding_class_accounting() {
let ifaces = interfaces(&juniper::parse_braces(
r#"
interfaces {
xe-0/0/0 {
forwarding-class-accounting {
direction both;
enhanced {
overhead-bytes 20;
traffic-type ucast;
family ipv4;
direction egress;
}
}
}
xe-0/0/1 {
forwarding-class-accounting;
}
xe-0/0/2 {
disable;
}
}
"#,
));
let first = ifaces[0].forwarding_class_accounting.as_ref().unwrap();
assert_eq!(first.direction.as_deref(), Some("both"));
let enhanced = first.enhanced.as_ref().unwrap();
assert_eq!(enhanced.overhead_bytes.as_deref(), Some("20"));
assert_eq!(enhanced.traffic_type.as_deref(), Some("ucast"));
assert_eq!(enhanced.family.as_deref(), Some("ipv4"));
assert_eq!(enhanced.direction.as_deref(), Some("egress"));
let bare = ifaces[1].forwarding_class_accounting.as_ref().unwrap();
assert!(bare.direction.is_none() && bare.enhanced.is_none());
assert!(ifaces[2].forwarding_class_accounting.is_none());
}
}