Skip to main content

asterust_junos/interfaces/ether_options/
ieee_802_3ad.rs

1//! `802.3ad`
2//! `interfaces { <name> { ether-options { 802.3ad { ... } } } }`.
3//!
4//! # See also
5//!
6//! - [802.3ad](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/802.3ad-edit-interfaces.html)
7//! - [lacp (IEEE 802.1AX) (MX Series)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/lacp-edit-interfaces-802.3ad.html)
8
9use crate::{active_children, arg_of, child_block, statement_words, value_after};
10use asterust::config::ConfigLine;
11
12/// The `802.3ad` statement that makes an interface a member of an aggregated Ethernet bundle.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct Ieee8023ad {
16    /// The bundle, e.g. `"ae0"`.
17    pub aggregated_interface: Option<String>,
18    /// `primary` or `backup`, for link protection.
19    pub role: Option<String>,
20    pub link_index: Option<String>,
21    pub distribution_list: Option<String>,
22    /// From `lacp { port-priority ...; }`.
23    pub lacp_port_priority: Option<String>,
24}
25
26/// The `802.3ad` statement of `options`, written `802.3ad ae0;`, `802.3ad ae0 { ... }` or `802.3ad
27/// { ae0; ... }`.
28pub(super) fn parse_ieee_802_3ad(options: &ConfigLine) -> Option<Ieee8023ad> {
29    let statement = active_children(options).find(|c| c.text == "802.3ad" || c.arg("802.3ad").is_some())?;
30    let words = statement_words(options, "802.3ad")?;
31    Some(Ieee8023ad {
32        aggregated_interface: words.iter().find(|w| w.starts_with("ae")).map(|w| w.to_string()),
33        role: words
34            .iter()
35            .find(|w| matches!(**w, "primary" | "backup"))
36            .map(|w| w.to_string()),
37        link_index: value_after(&words, "link-index"),
38        distribution_list: value_after(&words, "distribution-list"),
39        lacp_port_priority: child_block(statement, "lacp")
40            .and_then(|lacp| arg_of(lacp, "port-priority"))
41            .map(str::to_string),
42    })
43}