asterust_junos/protocols/ldp/interface.rs
1//! `interface`
2//! `protocols { ldp { interface (<name> | all) { ... } } }`.
3//!
4//! # See also
5//!
6//! - [interface (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-ldp.html)
7//! - [disable (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/disable-edit-protocols-ldp.html)
8//! - [hello-interval (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hello-interval-edit-protocols-ldp.html)
9//! - [hold-time (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hold-time-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//! - [allow-subnet-mismatch](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/allow-subnet-mismatch-edit-protocols-ldp.html)
12//! - [LDP Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/ldp-configuration.html), for `link-protection`
13
14use crate::{arg_of, child_block, has_leaf};
15use asterust::config::ConfigLine;
16
17/// `link-protection { ... }` of an LDP interface. A bare `link-protection;` leaves both flags unset.
18#[derive(Clone, Debug, Default, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct LdpLinkProtection {
21 pub disable: bool,
22 pub dynamic_rsvp_lsp: bool,
23}
24
25/// An `interface <name>` entry of LDP; the name can be `all`.
26#[derive(Clone, Debug, PartialEq, Eq)]
27#[non_exhaustive]
28pub struct LdpInterface {
29 pub name: String,
30 pub disable: bool,
31 /// Seconds.
32 pub hello_interval: Option<String>,
33 /// Seconds.
34 pub hold_time: Option<String>,
35 /// `interface` or `loopback`.
36 pub transport_address: Option<String>,
37 pub allow_subnet_mismatch: bool,
38 pub link_protection: Option<LdpLinkProtection>,
39}
40
41pub(super) fn parse_interface(name: &str, interface: &ConfigLine) -> LdpInterface {
42 let field = |keyword: &str| arg_of(interface, keyword).map(str::to_string);
43 LdpInterface {
44 name: name.to_string(),
45 disable: has_leaf(interface, "disable"),
46 hello_interval: field("hello-interval"),
47 hold_time: field("hold-time"),
48 transport_address: field("transport-address"),
49 allow_subnet_mismatch: has_leaf(interface, "allow-subnet-mismatch"),
50 link_protection: child_block(interface, "link-protection").map(|block| LdpLinkProtection {
51 disable: has_leaf(block, "disable"),
52 dynamic_rsvp_lsp: has_leaf(block, "dynamic-rsvp-lsp"),
53 }),
54 }
55}