Skip to main content

asterust_junos/protocols/bgp/
neighbor.rs

1//! `neighbor`
2//! `protocols { bgp { group <name> { neighbor <address> { ... } } } }`.
3//!
4//! # See also
5//!
6//! - [neighbor (Protocols BGP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/neighbor-edit-protocols-bgp.html)
7
8use super::peer_options::{parse_peer_options, BgpPeerOptions};
9use crate::{arg_of, first_word};
10use asterust::config::ConfigLine;
11
12/// A `neighbor <address>` in a BGP group. Settings inherited from the group are not resolved.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct BgpNeighbor {
16    pub address: String,
17    pub description: Option<String>,
18    pub peer_as: Option<String>,
19    pub local_address: Option<String>,
20    pub options: BgpPeerOptions,
21}
22
23pub(super) fn parse_neighbor(address: &str, neighbor: &ConfigLine) -> BgpNeighbor {
24    BgpNeighbor {
25        address: address.to_string(),
26        description: arg_of(neighbor, "description").map(str::to_string),
27        peer_as: arg_of(neighbor, "peer-as").and_then(first_word).map(str::to_string),
28        local_address: arg_of(neighbor, "local-address").map(str::to_string),
29        options: parse_peer_options(neighbor),
30    }
31}