asterust_junos/interfaces/aggregated_ether_options/
bfd_liveness_detection.rs1use crate::{arg_of, child_block, has_leaf};
4use asterust::config::ConfigLine;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct BfdLivenessDetection {
10 pub local_address: Option<String>,
11 pub neighbor: Option<String>,
12 pub minimum_interval: Option<String>,
14 pub minimum_receive_interval: Option<String>,
15 pub multiplier: Option<String>,
16 pub version: Option<String>,
18 pub holddown_interval: Option<String>,
19 pub no_adaptation: bool,
20 pub detection_time_threshold: Option<String>,
22 pub transmit_interval_minimum: Option<String>,
24 pub transmit_interval_threshold: Option<String>,
26 pub authentication_algorithm: Option<String>,
28 pub authentication_key_chain: Option<String>,
30 pub authentication_loose_check: bool,
31}
32
33pub(super) fn parse_bfd_liveness_detection(bfd: &ConfigLine) -> BfdLivenessDetection {
34 let field = |keyword: &str| arg_of(bfd, keyword).map(str::to_string);
35 let nested = |block: &str, keyword: &str| {
36 child_block(bfd, block)
37 .and_then(|block| arg_of(block, keyword))
38 .map(str::to_string)
39 };
40 let authentication = child_block(bfd, "authentication");
41 BfdLivenessDetection {
42 local_address: field("local-address"),
43 neighbor: field("neighbor"),
44 minimum_interval: field("minimum-interval"),
45 minimum_receive_interval: field("minimum-receive-interval"),
46 multiplier: field("multiplier"),
47 version: field("version"),
48 holddown_interval: field("holddown-interval"),
49 no_adaptation: has_leaf(bfd, "no-adaptation"),
50 detection_time_threshold: nested("detection-time", "threshold"),
51 transmit_interval_minimum: nested("transmit-interval", "minimum-interval"),
52 transmit_interval_threshold: nested("transmit-interval", "threshold"),
53 authentication_algorithm: nested("authentication", "algorithm"),
54 authentication_key_chain: nested("authentication", "key-chain"),
55 authentication_loose_check: authentication.is_some_and(|auth| has_leaf(auth, "loose-check")),
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use crate::interfaces::interfaces;
62 use asterust::config::juniper;
63
64 #[test]
66 fn extracts_bfd_liveness_detection() {
67 let ifaces = interfaces(&juniper::parse_braces(
68 r#"
69interfaces {
70 ae0 {
71 aggregated-ether-options {
72 bfd-liveness-detection {
73 local-address 192.0.2.1;
74 neighbor 192.0.2.2;
75 minimum-interval 300;
76 minimum-receive-interval 400;
77 multiplier 3;
78 version automatic;
79 holddown-interval 1000;
80 no-adaptation;
81 detection-time {
82 threshold 5000;
83 }
84 transmit-interval {
85 minimum-interval 250;
86 threshold 2000;
87 }
88 authentication {
89 algorithm keyed-sha-1;
90 key-chain BFD-KEYS;
91 loose-check;
92 }
93 }
94 }
95 }
96}
97"#,
98 ));
99 let bfd = ifaces[0]
100 .aggregated_ether_options
101 .as_ref()
102 .unwrap()
103 .bfd_liveness_detection
104 .as_ref()
105 .unwrap();
106 assert_eq!(bfd.local_address.as_deref(), Some("192.0.2.1"));
107 assert_eq!(bfd.neighbor.as_deref(), Some("192.0.2.2"));
108 assert_eq!(bfd.minimum_interval.as_deref(), Some("300"));
109 assert_eq!(bfd.minimum_receive_interval.as_deref(), Some("400"));
110 assert_eq!(bfd.multiplier.as_deref(), Some("3"));
111 assert_eq!(bfd.version.as_deref(), Some("automatic"));
112 assert_eq!(bfd.holddown_interval.as_deref(), Some("1000"));
113 assert!(bfd.no_adaptation);
114 assert_eq!(bfd.detection_time_threshold.as_deref(), Some("5000"));
115 assert_eq!(bfd.transmit_interval_minimum.as_deref(), Some("250"));
116 assert_eq!(bfd.transmit_interval_threshold.as_deref(), Some("2000"));
117 assert_eq!(bfd.authentication_algorithm.as_deref(), Some("keyed-sha-1"));
118 assert_eq!(bfd.authentication_key_chain.as_deref(), Some("BFD-KEYS"));
119 assert!(bfd.authentication_loose_check);
120 }
121
122 #[test]
123 fn bare_bfd_liveness_detection_has_no_settings() {
124 let ifaces = interfaces(&juniper::parse_braces(
125 "interfaces {\n ae0 {\n aggregated-ether-options {\n bfd-liveness-detection {\n neighbor 192.0.2.2;\n }\n }\n }\n}\n",
126 ));
127 let bfd = ifaces[0]
128 .aggregated_ether_options
129 .as_ref()
130 .unwrap()
131 .bfd_liveness_detection
132 .as_ref()
133 .unwrap();
134 assert_eq!(bfd.neighbor.as_deref(), Some("192.0.2.2"));
135 assert_eq!(bfd.local_address, None);
136 assert!(!bfd.no_adaptation);
137 assert_eq!(bfd.authentication_algorithm, None);
138 assert!(!bfd.authentication_loose_check);
139 }
140}