Skip to main content

asterust_junos/policy_options/
as_path.rs

1//! `as-path`
2//! `policy-options { as-path <name> <regular-expression>; }`.
3//!
4//! # See also
5//!
6//! - [as-path (Policy Options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/as-path-edit-policy-options.html)
7
8use crate::{has_leaf, split_name, unquote};
9use asterust::config::ConfigLine;
10
11/// An `as-path <name> <regular-expression>`.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct AsPath {
15    pub name: String,
16    pub regex: String,
17    /// `dynamic-db`: the path is read from the dynamic database.
18    pub dynamic_db: bool,
19}
20
21pub(super) fn parse_as_path(line: &ConfigLine) -> Option<AsPath> {
22    let (name, regex) = split_name(line.arg("as-path")?);
23    Some(AsPath {
24        name: name.to_string(),
25        regex: unquote(regex).to_string(),
26        dynamic_db: has_leaf(line, "dynamic-db"),
27    })
28}