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
//! `pppoe-options`
//! `interfaces { pp0 { unit <n> { pppoe-options { ... } } } }`.
//!
//! # See also
//!
//! - [pppoe-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pppoe-options-edit-interfaces.html)
//! - [pppoe-options (SRX Series)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pppoe-options-interfaces-security.html)
//! - [auto-reconnect](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/auto-reconnect-edit-interfaces.html)
//! - [client](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/client-edit-interfaces.html)
//! - [server](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/server-edit-interfaces.html)
//! - [service-name](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/service-name-edit-interfaces.html)
//! - [underlying-interface](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/underlying-interface-edit-interfaces.html)
//! - [access-concentrator](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/access-concentrator-edit-interfaces.html)

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

/// The `pppoe-options` of a `pp0` unit.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PppoeOptions {
    pub access_concentrator: Option<String>,
    /// Seconds.
    pub auto_reconnect: Option<String>,
    /// `client` or `server`.
    pub role: Option<String>,
    pub ignore_eol_tag: bool,
    pub service_name: Option<String>,
    pub underlying_interface: Option<String>,
    pub ppp_max_payload: Option<String>,
}

pub(super) fn parse_pppoe_options(options: &ConfigLine) -> PppoeOptions {
    let value = |keyword| arg_of(options, keyword).map(str::to_string);
    PppoeOptions {
        access_concentrator: value("access-concentrator"),
        auto_reconnect: value("auto-reconnect"),
        role: ["client", "server"]
            .into_iter()
            .find(|role| has_leaf(options, role))
            .map(str::to_string),
        ignore_eol_tag: has_leaf(options, "ignore-eol-tag"),
        service_name: value("service-name"),
        underlying_interface: value("underlying-interface"),
        ppp_max_payload: value("ppp-max-payload"),
    }
}