asterust_junos/interfaces/
logical_tunnel_options.rs1use super::aggregated_ether_options::{parse_link_protection, parse_load_balance};
9use super::aggregated_ether_options::{LinkProtection, LoadBalance};
10use crate::{child_block, has_leaf, top_level};
11use asterust::config::Config;
12
13#[derive(Clone, Debug, PartialEq, Eq)]
15#[non_exhaustive]
16pub struct LogicalTunnelOptions {
17 pub link_protection: Option<LinkProtection>,
18 pub load_balance: Option<LoadBalance>,
19 pub per_unit_mac_disable: bool,
20}
21
22pub fn logical_tunnel_options(config: &Config) -> Option<LogicalTunnelOptions> {
36 let options = child_block(top_level(config, "interfaces")?, "logical-tunnel-options")?;
37 Some(LogicalTunnelOptions {
38 link_protection: child_block(options, "link-protection").map(parse_link_protection),
39 load_balance: child_block(options, "load-balance").map(parse_load_balance),
40 per_unit_mac_disable: has_leaf(options, "per-unit-mac-disable"),
41 })
42}
43
44#[cfg(test)]
45mod tests {
46 use super::logical_tunnel_options;
47 use asterust::config::juniper;
48
49 #[test]
51 fn extracts_logical_tunnel_options() {
52 let config = juniper::parse_braces(
53 r#"
54interfaces {
55 logical-tunnel-options {
56 link-protection {
57 non-revertive;
58 }
59 load-balance {
60 adaptive {
61 scan-interval 20;
62 }
63 local-bias percent 50;
64 }
65 per-unit-mac-disable;
66 }
67}
68"#,
69 );
70 let options = logical_tunnel_options(&config).unwrap();
71 assert_eq!(options.link_protection.as_ref().unwrap().revertive, Some(false));
72 let balance = options.load_balance.as_ref().unwrap();
73 assert_eq!(balance.adaptive_scan_interval.as_deref(), Some("20"));
74 assert_eq!(balance.local_bias_percent.as_deref(), Some("50"));
75 assert!(options.per_unit_mac_disable);
76 }
77
78 #[test]
79 fn logical_tunnel_options_are_optional() {
80 let config = juniper::parse_braces("interfaces {\n lt-0/0/0 {\n disable;\n }\n}\n");
81 assert!(logical_tunnel_options(&config).is_none());
82 }
83}