asterust_junos/interfaces/
forwarding_class_accounting.rs1use crate::{arg_of, child_block};
11use asterust::config::ConfigLine;
12
13#[derive(Clone, Debug, PartialEq, Eq)]
15#[non_exhaustive]
16pub struct EnhancedForwardingClassAccounting {
17 pub overhead_bytes: Option<String>,
19 pub traffic_type: Option<String>,
21 pub family: Option<String>,
23 pub direction: Option<String>,
25}
26
27#[derive(Clone, Debug, PartialEq, Eq)]
29#[non_exhaustive]
30pub struct ForwardingClassAccounting {
31 pub direction: Option<String>,
33 pub enhanced: Option<EnhancedForwardingClassAccounting>,
34}
35
36pub(super) fn parse_forwarding_class_accounting(accounting: &ConfigLine) -> ForwardingClassAccounting {
37 ForwardingClassAccounting {
38 direction: arg_of(accounting, "direction").map(str::to_string),
39 enhanced: child_block(accounting, "enhanced").map(|enhanced| EnhancedForwardingClassAccounting {
40 overhead_bytes: arg_of(enhanced, "overhead-bytes").map(str::to_string),
41 traffic_type: arg_of(enhanced, "traffic-type").map(str::to_string),
42 family: arg_of(enhanced, "family").map(str::to_string),
43 direction: arg_of(enhanced, "direction").map(str::to_string),
44 }),
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use crate::interfaces::interfaces;
51 use asterust::config::juniper;
52
53 #[test]
55 fn extracts_forwarding_class_accounting() {
56 let ifaces = interfaces(&juniper::parse_braces(
57 r#"
58interfaces {
59 xe-0/0/0 {
60 forwarding-class-accounting {
61 direction both;
62 enhanced {
63 overhead-bytes 20;
64 traffic-type ucast;
65 family ipv4;
66 direction egress;
67 }
68 }
69 }
70 xe-0/0/1 {
71 forwarding-class-accounting;
72 }
73 xe-0/0/2 {
74 disable;
75 }
76}
77"#,
78 ));
79 let first = ifaces[0].forwarding_class_accounting.as_ref().unwrap();
80 assert_eq!(first.direction.as_deref(), Some("both"));
81 let enhanced = first.enhanced.as_ref().unwrap();
82 assert_eq!(enhanced.overhead_bytes.as_deref(), Some("20"));
83 assert_eq!(enhanced.traffic_type.as_deref(), Some("ucast"));
84 assert_eq!(enhanced.family.as_deref(), Some("ipv4"));
85 assert_eq!(enhanced.direction.as_deref(), Some("egress"));
86 let bare = ifaces[1].forwarding_class_accounting.as_ref().unwrap();
87 assert!(bare.direction.is_none() && bare.enhanced.is_none());
88 assert!(ifaces[2].forwarding_class_accounting.is_none());
89 }
90}