asterust_junos/interfaces/unit/pppoe_underlying_options.rs
1//! `pppoe-underlying-options` and `family pppoe`
2//! `interfaces { <name> { unit <n> { pppoe-underlying-options { ... } } } }`.
3//!
4//! # See also
5//!
6//! - [pppoe-underlying-options (Static and Dynamic Subscribers)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pppoe-underlying-options-edit-interfaces-pppoe.html)
7//! - [max-sessions (Dynamic PPPoE)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/max-sessions-edit-interfaces-pppoe-underlying-options.html)
8//! - [max-sessions-vsa-ignore](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/max-sessions-vsa-ignore-edit-pppoe-underlying-options.html)
9//! - [dynamic-profile (Dynamic PPPoE)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dynamic-profile-edit-interfaces-pppoe-underlying-options.html)
10//! - [service-name-table](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/service-name-table-edit-interfaces.html)
11//! - [duplicate-protection (Dynamic PPPoE)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/duplicate-protection-edit-interfaces-pppoe-underlying.html)
12//! - [direct-connect](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/direct-connect-edit-interfaces-pppoe.html)
13//! - [short-cycle-protection](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/short-cycle-protection-edit-pppoe-underlying-options.html)
14
15use crate::{arg_of, child_block, has_leaf, list_values, statement_words, value_after};
16use asterust::config::ConfigLine;
17
18/// The `duplicate-protection` of the PPPoE underlying options.
19#[derive(Clone, Debug, PartialEq, Eq)]
20#[non_exhaustive]
21pub struct DuplicateProtection {
22 /// `include { relay-session-id; }`.
23 pub include_relay_session_id: bool,
24}
25
26/// The `short-cycle-protection` of the PPPoE underlying options.
27#[derive(Clone, Debug, PartialEq, Eq)]
28#[non_exhaustive]
29pub struct ShortCycleProtection {
30 /// Seconds.
31 pub lockout_time_min: Option<String>,
32 /// Seconds.
33 pub lockout_time_max: Option<String>,
34 /// The `filter [ ... ]` values, e.g. `aci`.
35 pub filter: Vec<String>,
36}
37
38/// The `pppoe-underlying-options` of a unit, which `family pppoe` shares.
39#[derive(Clone, Debug, PartialEq, Eq)]
40#[non_exhaustive]
41pub struct PppoeUnderlyingOptions {
42 pub access_concentrator: Option<String>,
43 pub dynamic_profile: Option<String>,
44 pub direct_connect: bool,
45 pub duplicate_protection: Option<DuplicateProtection>,
46 pub max_sessions: Option<String>,
47 pub max_sessions_vsa_ignore: bool,
48 pub service_name_table: Option<String>,
49 pub short_cycle_protection: Option<ShortCycleProtection>,
50}
51
52pub(super) fn parse_pppoe_underlying_options(options: &ConfigLine) -> PppoeUnderlyingOptions {
53 let value = |keyword| arg_of(options, keyword).map(str::to_string);
54 PppoeUnderlyingOptions {
55 access_concentrator: value("access-concentrator"),
56 dynamic_profile: value("dynamic-profile"),
57 direct_connect: has_leaf(options, "direct-connect"),
58 duplicate_protection: crate::active_children(options)
59 .find(|c| c.text == "duplicate-protection" || c.text.starts_with("duplicate-protection "))
60 .map(|protection| DuplicateProtection {
61 include_relay_session_id: child_block(protection, "include")
62 .is_some_and(|include| has_leaf(include, "relay-session-id")),
63 }),
64 max_sessions: value("max-sessions"),
65 max_sessions_vsa_ignore: has_leaf(options, "max-sessions-vsa-ignore"),
66 service_name_table: value("service-name-table"),
67 short_cycle_protection: statement_words(options, "short-cycle-protection").map(|words| ShortCycleProtection {
68 lockout_time_min: value_after(&words, "lockout-time-min"),
69 lockout_time_max: value_after(&words, "lockout-time-max"),
70 filter: words
71 .iter()
72 .position(|w| *w == "filter")
73 .map(|i| list_values(&words[i + 1..].join(" ")))
74 .unwrap_or_default(),
75 }),
76 }
77}