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 read only with the
17/// `secrets` feature.
18#[derive(Clone, Debug, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct LdpSession {
21 /// The neighbor address, or the prefix of a session group.
22 pub name: String,
23 pub authentication_algorithm: Option<String>,
24 /// An `authentication-key` is configured.
25 pub has_authentication_key: bool,
26 /// The `authentication-key`; `None` unless the `secrets` feature is enabled.
27 pub authentication_key: Option<crate::Secret>,
28 pub authentication_key_chain: Option<String>,
29 pub downstream_on_demand: bool,
30 /// `Some(true)` for `mtu-discovery`, `Some(false)` for `no-mtu-discovery`.
31 pub mtu_discovery: Option<bool>,
32 pub transport_address: Option<String>,
33}
34
35pub(super) fn parse_session(name: &str, session: &ConfigLine) -> LdpSession {
36 let field = |keyword: &str| arg_of(session, keyword).map(str::to_string);
37 LdpSession {
38 name: name.to_string(),
39 authentication_algorithm: field("authentication-algorithm"),
40 has_authentication_key: arg_of(session, "authentication-key").is_some(),
41 authentication_key: crate::secret_value(arg_of(session, "authentication-key")),
42 authentication_key_chain: field("authentication-key-chain"),
43 downstream_on_demand: crate::has_leaf(session, "downstream-on-demand"),
44 mtu_discovery: toggle(session, "mtu-discovery"),
45 transport_address: field("transport-address"),
46 }
47}