Skip to main content

asterust_junos/protocols/mpls/
path.rs

1//! `path`
2//! `protocols { mpls { path <name> { <address> (strict | loose); ... } } }`.
3//!
4//! # See also
5//!
6//! - [path (Protocols MPLS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/path-edit-protocols-mpls.html)
7
8use crate::{active_children, split_name};
9use asterust::config::ConfigLine;
10
11/// A `path <name>`, the explicit hops that an LSP's `primary` or `secondary` path follows. An empty path imposes no
12/// routing limits.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct MplsPath {
16    pub name: String,
17    pub hops: Vec<MplsPathHop>,
18}
19
20/// A hop of an [`MplsPath`], in order.
21#[derive(Clone, Debug, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct MplsPathHop {
24    /// An IP address, a hostname or the name of an abstract hop.
25    pub address: String,
26    /// `strict` or `loose`, or for an abstract hop `abstract`, `loose` or `loose-link`.
27    pub qualifier: Option<String>,
28}
29
30pub(super) fn parse_path(name: &str, path: &ConfigLine) -> MplsPath {
31    MplsPath {
32        name: name.to_string(),
33        hops: active_children(path)
34            .map(|hop| {
35                let (address, rest) = split_name(&hop.text);
36                MplsPathHop {
37                    address: address.to_string(),
38                    qualifier: Some(rest).filter(|q| !q.is_empty()).map(str::to_string),
39                }
40            })
41            .collect(),
42    }
43}