asterust-junos 0.5.5

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
//! `interface`
//! `protocols { ldp { interface (<name> | all) { ... } } }`.
//!
//! # See also
//!
//! - [interface (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-ldp.html)
//! - [disable (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/disable-edit-protocols-ldp.html)
//! - [hello-interval (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hello-interval-edit-protocols-ldp.html)
//! - [hold-time (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hold-time-edit-protocols-ldp.html)
//! - [transport-address](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/transport-address-edit-protocols-ldp.html)
//! - [allow-subnet-mismatch](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/allow-subnet-mismatch-edit-protocols-ldp.html)
//! - [LDP Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/ldp-configuration.html), for `link-protection`

use crate::{arg_of, child_block, has_leaf};
use asterust::config::ConfigLine;

/// `link-protection { ... }` of an LDP interface. A bare `link-protection;` leaves both flags unset.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpLinkProtection {
    pub disable: bool,
    pub dynamic_rsvp_lsp: bool,
}

/// An `interface <name>` entry of LDP; the name can be `all`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpInterface {
    pub name: String,
    pub disable: bool,
    /// Seconds.
    pub hello_interval: Option<String>,
    /// Seconds.
    pub hold_time: Option<String>,
    /// `interface` or `loopback`.
    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"),
        }),
    }
}