Skip to main content

asterust_junos/protocols/rsvp/
link_protection.rs

1//! `link-protection`
2//! `protocols { rsvp { interface <name> { link-protection { bypass <name> { ... } } } } }`.
3//!
4//! # See also
5//!
6//! - [link-protection (RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/link-protection-edit-protocols-rsvp.html)
7//! - [bypass (Signaled LSP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/bypass-edit-protocols-rsvp.html)
8//! - [admin-group](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/admin-group-edit-protocols-rsvp.html)
9//! - [class-of-service (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/class-of-service-edit-protocols-rsvp.html)
10//! - [priority (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/priority-edit-protocols-rsvp.html)
11//! - [no-cspf (Protocols RSVP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-cspf-edit-protocols-rsvp.html)
12
13use crate::protocols::mpls::MplsAdminGroupConstraints;
14use crate::{active_children, arg_of, args_of, child_block, first_word, has_leaf, list_values, named_children};
15use asterust::config::ConfigLine;
16
17/// A `bypass <name>` LSP of a protected RSVP interface. The per-class-type `bandwidth` block is not extracted.
18#[derive(Clone, Debug, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct RsvpBypass {
21    pub name: String,
22    /// Bits per second, as written.
23    pub bandwidth: Option<String>,
24    pub description: Option<String>,
25    pub class_of_service: Option<String>,
26    pub hop_limit: Option<String>,
27    pub no_cspf: bool,
28    /// Each `path <address> [strict | loose]`, as written.
29    pub path: Vec<String>,
30    /// `<setup> <reservation>`, as written.
31    pub priority: Option<String>,
32    /// The merge point address.
33    pub to: Option<String>,
34    pub subscription: Option<String>,
35}
36
37/// The `link-protection` block of an RSVP interface. A bare `link-protection;` leaves every option unset.
38#[derive(Clone, Debug, Default, PartialEq, Eq)]
39#[non_exhaustive]
40pub struct RsvpLinkProtection {
41    pub disable: bool,
42    pub admin_group: MplsAdminGroupConstraints,
43    /// Bits per second, as written.
44    pub bandwidth: Option<String>,
45    pub class_of_service: Option<String>,
46    pub hop_limit: Option<String>,
47    pub max_bypasses: Option<String>,
48    pub no_cspf: bool,
49    pub no_node_protection: bool,
50    /// Seconds.
51    pub optimize_timer: Option<String>,
52    /// Each `path <address> [strict | loose]`, as written.
53    pub path: Vec<String>,
54    /// `<setup> <reservation>`, as written.
55    pub priority: Option<String>,
56    pub subscription: Option<String>,
57    pub bypasses: Vec<RsvpBypass>,
58}
59
60pub(super) fn parse_link_protection(interface: &ConfigLine) -> Option<RsvpLinkProtection> {
61    let block = child_block(interface, "link-protection")?;
62    let field = |keyword: &str| arg_of(block, keyword).map(str::to_string);
63    Some(RsvpLinkProtection {
64        disable: has_leaf(block, "disable"),
65        admin_group: parse_admin_group(block),
66        bandwidth: field("bandwidth"),
67        class_of_service: field("class-of-service"),
68        hop_limit: field("hop-limit"),
69        max_bypasses: field("max-bypasses"),
70        no_cspf: has_leaf(block, "no-cspf"),
71        no_node_protection: has_leaf(block, "no-node-protection"),
72        optimize_timer: field("optimize-timer"),
73        path: args_of(block, "path").into_iter().map(str::to_string).collect(),
74        priority: field("priority"),
75        subscription: field("subscription"),
76        bypasses: named_children(block, "bypass")
77            .map(|(name, bypass)| parse_bypass(name, bypass))
78            .collect(),
79    })
80}
81
82fn parse_bypass(name: &str, bypass: &ConfigLine) -> RsvpBypass {
83    let field = |keyword: &str| arg_of(bypass, keyword).map(str::to_string);
84    RsvpBypass {
85        name: name.to_string(),
86        bandwidth: active_children(bypass)
87            .find_map(|c| c.arg("bandwidth"))
88            .and_then(first_word)
89            .map(str::to_string),
90        description: field("description"),
91        class_of_service: field("class-of-service"),
92        hop_limit: field("hop-limit"),
93        no_cspf: has_leaf(bypass, "no-cspf"),
94        path: args_of(bypass, "path").into_iter().map(str::to_string).collect(),
95        priority: field("priority"),
96        to: field("to"),
97        subscription: field("subscription"),
98    }
99}
100
101fn parse_admin_group(block: &ConfigLine) -> MplsAdminGroupConstraints {
102    let Some(groups) = child_block(block, "admin-group") else {
103        return MplsAdminGroupConstraints::default();
104    };
105    let list = |keyword: &str| -> Vec<String> { args_of(groups, keyword).into_iter().flat_map(list_values).collect() };
106    MplsAdminGroupConstraints {
107        exclude: list("exclude"),
108        include_all: list("include-all"),
109        include_any: list("include-any"),
110    }
111}