Skip to main content

asterust_junos/interfaces/
redundancy_group.rs

1//! `redundancy-group`
2//! `interfaces { <name> { redundancy-group { member-interface <name> { ... } } } }`.
3//!
4//! The redundant logical tunnel (RLT) bundle used by pseudowire headend termination.
5//!
6//! # See also
7//!
8//! - [redundancy-group (Redundant Tunnel)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/redundancy-group-edit-interfaces-tunnel.html)
9
10use crate::{arg_of, has_leaf, named_children};
11use asterust::config::ConfigLine;
12
13/// A `member-interface` of a redundant tunnel group.
14#[derive(Clone, Debug, PartialEq, Eq)]
15#[non_exhaustive]
16pub struct RedundancyGroupMember {
17    pub name: String,
18    /// `active` or `backup`.
19    pub role: Option<String>,
20    pub minimum_links: Option<String>,
21}
22
23/// The `redundancy-group` of a redundant tunnel interface.
24#[derive(Clone, Debug, PartialEq, Eq)]
25#[non_exhaustive]
26pub struct RedundancyGroup {
27    pub member_interfaces: Vec<RedundancyGroupMember>,
28}
29
30pub(super) fn parse_redundancy_group(group: &ConfigLine) -> RedundancyGroup {
31    RedundancyGroup {
32        member_interfaces: named_children(group, "member-interface")
33            .map(|(name, member)| RedundancyGroupMember {
34                name: name.to_string(),
35                role: ["active", "backup"]
36                    .into_iter()
37                    .find(|role| has_leaf(member, role))
38                    .map(str::to_string),
39                minimum_links: arg_of(member, "minimum-links").map(str::to_string),
40            })
41            .collect(),
42    }
43}