asterust-junos 0.5.12

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
//! `lacp`
//! `interfaces { <name> { aggregated-ether-options { lacp { ... } } } }`.
//!
//! # See also
//!
//! - [aggregate-wait-time](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interfaces-edit-aggregate-wait-time.html)
//! - [sync-reset](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interfaces-aggregated-ether-options-lacp-sync-reset.html)
//! - [link-protection](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/link-protection-edit-interfaces.html)
//! - [lacp (Aggregated Ethernet)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/lacp-edit-interfaces-aggregated-ethernet-qfx-series.html)

use super::balancing::{parse_link_protection, LinkProtection};
use crate::{arg_of, child_block, has_leaf};
use asterust::config::ConfigLine;

/// The `lacp` settings of an aggregated Ethernet bundle.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Lacp {
    /// `active` or `passive`; LACP is passive when neither is written.
    pub mode: Option<String>,
    /// `fast` or `slow`.
    pub periodic: Option<String>,
    pub system_priority: Option<String>,
    pub system_id: Option<String>,
    pub admin_key: Option<String>,
    pub force_up: bool,
    pub fast_failover: bool,
    pub accept_data: bool,
    /// Seconds.
    pub aggregate_wait_time: Option<String>,
    /// `enable` or `disable`.
    pub sync_reset: Option<String>,
    pub link_protection: Option<LinkProtection>,
}

pub(in crate::interfaces) fn parse_lacp(lacp: &ConfigLine) -> Lacp {
    Lacp {
        mode: ["active", "passive"]
            .iter()
            .find(|mode| has_leaf(lacp, mode))
            .map(|mode| mode.to_string()),
        periodic: arg_of(lacp, "periodic").map(str::to_string),
        system_priority: arg_of(lacp, "system-priority").map(str::to_string),
        system_id: arg_of(lacp, "system-id").map(str::to_string),
        admin_key: arg_of(lacp, "admin-key").map(str::to_string),
        force_up: has_leaf(lacp, "force-up"),
        fast_failover: has_leaf(lacp, "fast-failover"),
        accept_data: has_leaf(lacp, "accept-data"),
        aggregate_wait_time: arg_of(lacp, "aggregate-wait-time").map(str::to_string),
        sync_reset: arg_of(lacp, "sync-reset").map(str::to_string),
        link_protection: child_block(lacp, "link-protection").map(parse_link_protection),
    }
}