asterust_junos/protocols/ldp/session.rs
1//! `session` and `session-group`
2//! `protocols { ldp { session <address> { ... } session-group <prefix> { ... } } }`.
3//!
4//! # See also
5//!
6//! - [session-group](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/session-group-edit-protocols-ldp.html)
7//! - [downstream-on-demand](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/downstream-on-demand-edit-protocols-ldp-session.html)
8//! - [authentication-key (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-key-edit-protocols-ldp.html)
9//! - [authentication-key-chain (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-key-chain-edit-protocols-ldp.html)
10//! - [transport-address](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/transport-address-edit-protocols-ldp.html)
11//! - [LDP Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/ldp-configuration.html)
12
13use crate::{arg_of, toggle};
14use asterust::config::ConfigLine;
15
16/// A `session <address>` or `session-group <prefix>` entry of LDP. The `authentication-key` is never extracted.
17#[derive(Clone, Debug, PartialEq, Eq)]
18#[non_exhaustive]
19pub struct LdpSession {
20 /// The neighbor address, or the prefix of a session group.
21 pub name: String,
22 pub authentication_algorithm: Option<String>,
23 /// An `authentication-key` is configured.
24 pub has_authentication_key: bool,
25 pub authentication_key_chain: Option<String>,
26 pub downstream_on_demand: bool,
27 /// `Some(true)` for `mtu-discovery`, `Some(false)` for `no-mtu-discovery`.
28 pub mtu_discovery: Option<bool>,
29 pub transport_address: Option<String>,
30}
31
32pub(super) fn parse_session(name: &str, session: &ConfigLine) -> LdpSession {
33 let field = |keyword: &str| arg_of(session, keyword).map(str::to_string);
34 LdpSession {
35 name: name.to_string(),
36 authentication_algorithm: field("authentication-algorithm"),
37 has_authentication_key: arg_of(session, "authentication-key").is_some(),
38 authentication_key_chain: field("authentication-key-chain"),
39 downstream_on_demand: crate::has_leaf(session, "downstream-on-demand"),
40 mtu_discovery: toggle(session, "mtu-discovery"),
41 transport_address: field("transport-address"),
42 }
43}