asterust-junos 0.3.17

Typed Juniper JunOS config views (interfaces, OSPF, BGP, IS-IS, routing instances, policy options, firewall filters, system) extracted from an asterust config tree.
Documentation
//! `interface`
//! `protocols { rsvp { interface (<name> | all) { ... } } }`.
//!
//! # See also
//!
//! - [interface (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-rsvp.html)
//! - [bandwidth (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/bandwidth-edit-protocols-rsvp.html)
//! - [subscription](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/subscription-edit-protocols-rsvp.html)
//! - [authentication-key (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-key-edit-protocols-rsvp.html)
//! - [hello-interval (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hello-interval-edit-protocols-rsvp.html)
//! - [aggregate (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/aggregate-edit-protocols-rsvp.html)
//! - [reliable](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/reliable-edit-protocols-rsvp.html)
//! - [update-threshold](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/update-threshold-edit-protocols-rsvp.html)

use super::link_protection::{parse_link_protection, RsvpLinkProtection};
use crate::{arg_of, has_leaf, toggle};
use asterust::config::ConfigLine;

/// An `interface <name>` entry of RSVP; the name can be `all`. The `authentication-key` is read only with the
/// `secrets` feature.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct RsvpInterface {
    pub name: String,
    pub disable: bool,
    /// `Some(true)` for `aggregate`, `Some(false)` for `no-aggregate`.
    pub aggregate: Option<bool>,
    /// An `authentication-key` is configured.
    pub has_authentication_key: bool,
    /// The `authentication-key`; `None` unless the `secrets` feature is enabled.
    pub authentication_key: Option<crate::Secret>,
    /// Bits per second, as written.
    pub bandwidth: Option<String>,
    /// Seconds.
    pub hello_interval: Option<String>,
    /// `Some(true)` for `reliable`, `Some(false)` for `no-reliable`.
    pub reliable: Option<bool>,
    /// The percentage of the link bandwidth that can be reserved. Class-type forms are not extracted.
    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()),
        authentication_key: crate::secret_value(arg_of(interface, "authentication-key")),
        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),
    }
}