asterust-junos 0.5.14

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `peer-interface`
//! `protocols { rsvp { peer-interface <name> { ... } } }`.
//!
//! # See also
//!
//! - [peer-interface (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/peer-interface-edit-protocols-rsvp.html)
//! - [dynamic-bidirectional-transport](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dynamic-bidirectional-transport-edit-protocols-rsvp.html)
//! - [GMPLS Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/gmpls-configuration.html), for the example behind the tests

use crate::{arg_of, child_block, has_leaf, secret_value, statement_words, toggle, value_after};
use asterust::config::ConfigLine;

/// A `peer-interface <name>` of RSVP: a peer reached over an out-of-band control channel.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct RsvpPeerInterface {
    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>,
    /// `dynamic-bidirectional-transport` is configured.
    pub dynamic_bidirectional_transport: bool,
    /// The `template` of `dynamic-bidirectional-transport`.
    pub dynamic_bidirectional_transport_template: Option<String>,
    /// Seconds.
    pub hello_interval: Option<String>,
    /// `Some(true)` for `reliable`, `Some(false)` for `no-reliable`.
    pub reliable: Option<bool>,
}

pub(super) fn parse_peer_interface(name: &str, peer: &ConfigLine) -> RsvpPeerInterface {
    let transport = statement_words(peer, "dynamic-bidirectional-transport");
    RsvpPeerInterface {
        name: name.to_string(),
        disable: has_leaf(peer, "disable"),
        aggregate: toggle(peer, "aggregate"),
        has_authentication_key: arg_of(peer, "authentication-key").is_some(),
        authentication_key: secret_value(arg_of(peer, "authentication-key")),
        dynamic_bidirectional_transport: child_block(peer, "dynamic-bidirectional-transport").is_some()
            || transport.is_some(),
        dynamic_bidirectional_transport_template: transport.and_then(|words| value_after(&words, "template")),
        hello_interval: arg_of(peer, "hello-interval").map(str::to_string),
        reliable: toggle(peer, "reliable"),
    }
}