use super::link_protection::{parse_link_protection, RsvpLinkProtection};
use crate::{arg_of, has_leaf, toggle};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct RsvpInterface {
pub name: String,
pub disable: bool,
pub aggregate: Option<bool>,
pub has_authentication_key: bool,
pub bandwidth: Option<String>,
pub hello_interval: Option<String>,
pub reliable: Option<bool>,
pub subscription: Option<String>,
pub update_threshold: Option<String>,
pub link_protection: Option<RsvpLinkProtection>,
}
pub(super) fn parse_interface(name: &str, interface: &ConfigLine) -> RsvpInterface {
let field = |keyword: &str| arg_of(interface, keyword).map(str::to_string);
RsvpInterface {
name: name.to_string(),
disable: has_leaf(interface, "disable"),
aggregate: toggle(interface, "aggregate"),
has_authentication_key: crate::active_children(interface)
.any(|c| c.text == "authentication-key" || c.arg("authentication-key").is_some()),
bandwidth: field("bandwidth"),
hello_interval: field("hello-interval"),
reliable: toggle(interface, "reliable"),
subscription: crate::active_children(interface)
.find_map(|c| c.arg("subscription"))
.and_then(crate::first_word)
.map(str::to_string),
update_threshold: field("update-threshold"),
link_protection: parse_link_protection(interface),
}
}