Skip to main content

asterust_junos/protocols/bgp/peer_options/
local_as.rs

1//! `local-as`
2//! `protocols { bgp { group <name> { local-as <as> [loops <n>] [private | alias] [no-prepend-global-as]; } } }`.
3//!
4//! # See also
5//!
6//! - [local-as](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/local-as-edit-protocols-bgp.html)
7
8use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11/// The `local-as` statement: the AS number the router presents to a peer, and how it is prepended.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct LocalAs {
15    pub autonomous_system: Option<String>,
16    /// How many times the local AS may appear in the AS path.
17    pub loops: Option<String>,
18    pub private: bool,
19    pub alias: bool,
20    pub no_prepend_global_as: bool,
21}
22
23pub(super) fn parse_local_as(line: &ConfigLine) -> Option<LocalAs> {
24    let words = statement_words(line, "local-as")?;
25    let first = words
26        .first()
27        .filter(|word| word.chars().next().is_some_and(|c| c.is_ascii_digit()));
28    Some(LocalAs {
29        autonomous_system: first.map(|word| word.to_string()),
30        loops: value_after(&words, "loops"),
31        private: words.contains(&"private"),
32        alias: words.contains(&"alias"),
33        no_prepend_global_as: words.contains(&"no-prepend-global-as"),
34    })
35}