use super::aggregated_ether_options::{parse_link_protection, parse_load_balance};
use super::aggregated_ether_options::{LinkProtection, LoadBalance};
use crate::{child_block, has_leaf, top_level};
use asterust::config::Config;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LogicalTunnelOptions {
pub link_protection: Option<LinkProtection>,
pub load_balance: Option<LoadBalance>,
pub per_unit_mac_disable: bool,
}
pub fn logical_tunnel_options(config: &Config) -> Option<LogicalTunnelOptions> {
let options = child_block(top_level(config, "interfaces")?, "logical-tunnel-options")?;
Some(LogicalTunnelOptions {
link_protection: child_block(options, "link-protection").map(parse_link_protection),
load_balance: child_block(options, "load-balance").map(parse_load_balance),
per_unit_mac_disable: has_leaf(options, "per-unit-mac-disable"),
})
}
#[cfg(test)]
mod tests {
use super::logical_tunnel_options;
use asterust::config::juniper;
#[test]
fn extracts_logical_tunnel_options() {
let config = juniper::parse_braces(
r#"
interfaces {
logical-tunnel-options {
link-protection {
non-revertive;
}
load-balance {
adaptive {
scan-interval 20;
}
local-bias percent 50;
}
per-unit-mac-disable;
}
}
"#,
);
let options = logical_tunnel_options(&config).unwrap();
assert_eq!(options.link_protection.as_ref().unwrap().revertive, Some(false));
let balance = options.load_balance.as_ref().unwrap();
assert_eq!(balance.adaptive_scan_interval.as_deref(), Some("20"));
assert_eq!(balance.local_bias_percent.as_deref(), Some("50"));
assert!(options.per_unit_mac_disable);
}
#[test]
fn logical_tunnel_options_are_optional() {
let config = juniper::parse_braces("interfaces {\n lt-0/0/0 {\n disable;\n }\n}\n");
assert!(logical_tunnel_options(&config).is_none());
}
}