asterust_junos/protocols/mpls/label_switched_path.rs
1//! `label-switched-path`
2//! `protocols { mpls { label-switched-path <name> { to <address>; ... } } }`.
3//!
4//! # See also
5//!
6//! - [label-switched-path (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/label-switched-path-edit-protocols-mpls.html)
7//! - [to](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/to-edit-protocols-mpls.html)
8//! - [from (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/from-edit-protocols-mpls.html)
9//! - [fast-reroute (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/fast-reroute-edit-protocols-mpls.html)
10//! - [link-protection (Dynamic LSPs)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/link-protection-edit-protocols-mpls.html)
11//! - [adaptive (protocols mpls)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/adaptive-edit-protocols-mpls.html)
12//! - [admin-down](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/admin-down-edit-protocols-mpls.html)
13//! - [metric (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/metric-edit-protocols-mpls.html)
14//! - [install (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/install-edit-protocols-mpls.html)
15//! - [retry-timer](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/retry-timer-edit-protocols-mpls.html)
16//! - [retry-limit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/retry-limit-edit-protocols-mpls.html)
17//! - [revert-timer](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/revert-timer-edit-protocols-mpls.html)
18//! - [soft-preemption (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/soft-preemption-edit-protocols-mpls.html)
19//! - [entropy-label (protocols mpls)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/entropy-label-edit-protocols-mpls.html)
20//! - [inter-domain](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/inter-domain-edit-protocols-mpls.html)
21//! - [ldp-tunneling](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ldp-tunneling-edit-protocols-mpls.html)
22//! - [description (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/description-edit-protocols-mpls.html)
23//! - [Basic MPLS Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/mpls-basic-configuration.html)
24
25use super::lsp_path::{parse_admin_group, parse_paths, MplsAdminGroupConstraints, MplsLspPath};
26use crate::{active_children, arg_of, args_of, child_block, first_word, has_leaf, list_values, toggle};
27use asterust::config::ConfigLine;
28
29/// The `fast-reroute` options of an LSP. A bare `fast-reroute;` leaves every option unset.
30#[derive(Clone, Debug, Default, PartialEq, Eq)]
31#[non_exhaustive]
32pub struct MplsFastReroute {
33 pub bandwidth: Option<String>,
34 pub bandwidth_percent: Option<String>,
35 pub hop_limit: Option<String>,
36 pub exclude: Vec<String>,
37 pub include_all: Vec<String>,
38 pub include_any: Vec<String>,
39}
40
41/// A `label-switched-path <name>`. The `auto-bandwidth`, `lsp-attributes`, `policing`, `p2mp`, `traceoptions` and
42/// per-class-type `bandwidth` blocks are not extracted.
43#[derive(Clone, Debug, PartialEq, Eq)]
44#[non_exhaustive]
45pub struct MplsLabelSwitchedPath {
46 pub name: String,
47 /// The egress router address.
48 pub to: Option<String>,
49 pub from: Option<String>,
50 pub description: Option<String>,
51 pub disable: bool,
52 pub admin_down: bool,
53 pub adaptive: bool,
54 pub admin_group: MplsAdminGroupConstraints,
55 /// Bits per second, as written.
56 pub bandwidth: Option<String>,
57 pub class_of_service: Option<String>,
58 pub cross_credibility_cspf: bool,
59 pub entropy_label: bool,
60 pub inter_domain: bool,
61 pub ldp_tunneling: bool,
62 pub link_protection: bool,
63 pub node_link_protection: bool,
64 pub metric: Option<String>,
65 pub no_cspf: bool,
66 pub no_decrement_ttl: bool,
67 pub no_self_ping: bool,
68 /// Seconds.
69 pub optimize_timer: Option<String>,
70 pub preference: Option<String>,
71 /// `<setup> <reservation>`, as written.
72 pub priority: Option<String>,
73 /// `random`, `least-fill` or `most-fill`.
74 pub path_selection: Option<String>,
75 /// `Some(true)` for `record`, `Some(false)` for `no-record`.
76 pub record: Option<bool>,
77 pub retry_limit: Option<String>,
78 /// Seconds.
79 pub retry_timer: Option<String>,
80 /// Seconds.
81 pub revert_timer: Option<String>,
82 pub soft_preemption: bool,
83 pub standby: bool,
84 /// The prefixes of `install`, which are installed in `inet.3` while the LSP is up.
85 pub install: Vec<String>,
86 pub fast_reroute: Option<MplsFastReroute>,
87 pub primary: Vec<MplsLspPath>,
88 pub secondary: Vec<MplsLspPath>,
89}
90
91pub(super) fn parse_label_switched_path(name: &str, lsp: &ConfigLine) -> MplsLabelSwitchedPath {
92 let field = |keyword: &str| arg_of(lsp, keyword).map(str::to_string);
93 let selection = ["random", "least-fill", "most-fill"]
94 .into_iter()
95 .find(|option| has_leaf(lsp, option));
96 MplsLabelSwitchedPath {
97 name: name.to_string(),
98 to: field("to"),
99 from: field("from"),
100 description: field("description"),
101 disable: has_leaf(lsp, "disable"),
102 admin_down: has_leaf(lsp, "admin-down"),
103 adaptive: has_leaf(lsp, "adaptive"),
104 admin_group: parse_admin_group(lsp),
105 bandwidth: field("bandwidth"),
106 class_of_service: field("class-of-service"),
107 cross_credibility_cspf: has_leaf(lsp, "cross-credibility-cspf"),
108 entropy_label: has_leaf(lsp, "entropy-label"),
109 inter_domain: has_leaf(lsp, "inter-domain"),
110 ldp_tunneling: has_leaf(lsp, "ldp-tunneling"),
111 link_protection: has_leaf(lsp, "link-protection"),
112 node_link_protection: has_leaf(lsp, "node-link-protection"),
113 metric: field("metric"),
114 no_cspf: has_leaf(lsp, "no-cspf"),
115 no_decrement_ttl: has_leaf(lsp, "no-decrement-ttl"),
116 no_self_ping: has_leaf(lsp, "no-self-ping"),
117 optimize_timer: field("optimize-timer"),
118 preference: field("preference"),
119 priority: field("priority"),
120 path_selection: selection.map(str::to_string),
121 record: toggle(lsp, "record"),
122 retry_limit: field("retry-limit"),
123 retry_timer: field("retry-timer"),
124 revert_timer: field("revert-timer"),
125 soft_preemption: has_leaf(lsp, "soft-preemption"),
126 standby: has_leaf(lsp, "standby"),
127 install: args_of(lsp, "install")
128 .into_iter()
129 .filter_map(first_word)
130 .map(str::to_string)
131 .collect(),
132 fast_reroute: child_block(lsp, "fast-reroute").map(parse_fast_reroute),
133 primary: parse_paths(lsp, "primary"),
134 secondary: parse_paths(lsp, "secondary"),
135 }
136}
137
138fn parse_fast_reroute(block: &ConfigLine) -> MplsFastReroute {
139 let field = |keyword: &str| arg_of(block, keyword).map(str::to_string);
140 let list = |keyword: &str| -> Vec<String> {
141 active_children(block)
142 .filter_map(|c| c.arg(keyword))
143 .flat_map(list_values)
144 .collect()
145 };
146 MplsFastReroute {
147 bandwidth: field("bandwidth"),
148 bandwidth_percent: field("bandwidth-percent"),
149 hop_limit: field("hop-limit"),
150 exclude: list("exclude"),
151 include_all: list("include-all"),
152 include_any: list("include-any"),
153 }
154}