use crate::{arg_of, child_block, has_leaf};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpLinkProtection {
pub disable: bool,
pub dynamic_rsvp_lsp: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpInterface {
pub name: String,
pub disable: bool,
pub hello_interval: Option<String>,
pub hold_time: Option<String>,
pub transport_address: Option<String>,
pub allow_subnet_mismatch: bool,
pub link_protection: Option<LdpLinkProtection>,
}
pub(super) fn parse_interface(name: &str, interface: &ConfigLine) -> LdpInterface {
let field = |keyword: &str| arg_of(interface, keyword).map(str::to_string);
LdpInterface {
name: name.to_string(),
disable: has_leaf(interface, "disable"),
hello_interval: field("hello-interval"),
hold_time: field("hold-time"),
transport_address: field("transport-address"),
allow_subnet_mismatch: has_leaf(interface, "allow-subnet-mismatch"),
link_protection: child_block(interface, "link-protection").map(|block| LdpLinkProtection {
disable: has_leaf(block, "disable"),
dynamic_rsvp_lsp: has_leaf(block, "dynamic-rsvp-lsp"),
}),
}
}