Skip to main content

asterust_junos/protocols/pim/
interface.rs

1//! `interface`
2//! `protocols { pim { interface (<name> | all) { ... } } }`.
3//!
4//! # See also
5//!
6//! - [interface (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-pim.html)
7//! - [family (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/family-edit-protocols-pim.html)
8//! - [mode (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mode-edit-protocols-pim.html)
9//! - [version (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/version-edit-protocols-pim.html)
10//! - [hello-interval](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hello-interval-edit-protocols-pim.html)
11//! - [priority (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/priority-edit-protocols-pim-interface.html)
12//! - [override-interval](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/override-interval-edit-protocols-pim.html)
13//! - [propagation-delay](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/propagation-delay-edit-protocols-pim.html)
14//! - [reset-tracking-bit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/reset-tracking-bit-edit-protocols-pim.html)
15//! - [neighbor-policy](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/neighbor-policy-edit-protocols-pim.html)
16//! - [accept-remote-source](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/accept-remote-source-edit-protocols-pim.html)
17//! - [accept-join-always-from](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/accept-join-always-from-protocols-pim-interface.html)
18//! - [df-election](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/df-election-edit-protocols-pim-interface.html)
19//! - [bfd-liveness-detection (Protocols PIM)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/bfd-liveness-detection-edit-protocols-pim.html)
20//! - [Configuring PIM and the Bidirectional Forwarding Detection (BFD) Protocol](https://networkingdocs.hpe.com/documentation/us/en/software/junos/multicast/topics/topic-map/mcast-pim-bfd.html)
21
22use crate::{arg_of, args_of, child_block, has_leaf, list_values, named_children};
23use asterust::config::ConfigLine;
24
25/// The BFD session of a PIM interface or interface family. The key chain is a name; keys are never read.
26#[derive(Clone, Debug, Default, PartialEq, Eq)]
27#[non_exhaustive]
28pub struct PimBfd {
29    /// Milliseconds.
30    pub minimum_interval: Option<String>,
31    pub minimum_receive_interval: Option<String>,
32    pub multiplier: Option<String>,
33    /// `0`, `1` or `automatic`.
34    pub version: Option<String>,
35    pub no_adaptation: bool,
36    pub pdu_size: Option<String>,
37    /// From `detection-time { threshold ...; }`.
38    pub detection_time_threshold: Option<String>,
39    /// From `transmit-interval { minimum-interval ...; }`.
40    pub transmit_interval_minimum: Option<String>,
41    /// From `transmit-interval { threshold ...; }`.
42    pub transmit_interval_threshold: Option<String>,
43    pub authentication_algorithm: Option<String>,
44    pub authentication_key_chain: Option<String>,
45    pub authentication_loose_check: bool,
46}
47
48/// A `family (inet | inet6)` statement of PIM or of one of its interfaces.
49#[derive(Clone, Debug, PartialEq, Eq)]
50#[non_exhaustive]
51pub struct PimFamily {
52    /// `inet` or `inet6`.
53    pub name: String,
54    pub disable: bool,
55    pub bfd_liveness_detection: Option<PimBfd>,
56}
57
58/// The `bidirectional { df-election { ... } }` settings of an interface, all but the robustness count in milliseconds.
59#[derive(Clone, Debug, Default, PartialEq, Eq)]
60#[non_exhaustive]
61pub struct PimDfElection {
62    pub backoff_period: Option<String>,
63    pub offer_period: Option<String>,
64    pub robustness_count: Option<String>,
65}
66
67/// The `multiple-triggered-joins` settings of an interface.
68#[derive(Clone, Debug, Default, PartialEq, Eq)]
69#[non_exhaustive]
70pub struct PimMultipleTriggeredJoins {
71    pub count: Option<String>,
72    /// Milliseconds.
73    pub interval: Option<String>,
74}
75
76/// An `interface <name>` entry of PIM; the name can be `all`.
77#[derive(Clone, Debug, PartialEq, Eq)]
78#[non_exhaustive]
79pub struct PimInterface {
80    pub name: String,
81    pub disable: bool,
82    /// `bidirectional-sparse`, `bidirectional-sparse-dense`, `dense`, `sparse` or `sparse-dense`.
83    pub mode: Option<String>,
84    pub version: Option<String>,
85    /// Seconds.
86    pub hello_interval: Option<String>,
87    /// The designated router priority.
88    pub priority: Option<String>,
89    /// Milliseconds.
90    pub override_interval: Option<String>,
91    /// Milliseconds.
92    pub propagation_delay: Option<String>,
93    pub reset_tracking_bit: bool,
94    pub accept_remote_source: bool,
95    /// `dual-dr { enhanced; }`.
96    pub dual_dr_enhanced: bool,
97    pub neighbor_policies: Vec<String>,
98    pub accept_join_always_from: Vec<String>,
99    pub families: Vec<PimFamily>,
100    pub bfd_liveness_detection: Option<PimBfd>,
101    pub df_election: Option<PimDfElection>,
102    pub multiple_triggered_joins: Option<PimMultipleTriggeredJoins>,
103}
104
105fn parse_bfd(bfd: &ConfigLine) -> PimBfd {
106    let field = |keyword: &str| arg_of(bfd, keyword).map(str::to_string);
107    let nested = |block: &str, keyword: &str| {
108        child_block(bfd, block)
109            .and_then(|block| arg_of(block, keyword))
110            .map(str::to_string)
111    };
112    PimBfd {
113        minimum_interval: field("minimum-interval"),
114        minimum_receive_interval: field("minimum-receive-interval"),
115        multiplier: field("multiplier"),
116        version: field("version"),
117        no_adaptation: has_leaf(bfd, "no-adaptation"),
118        pdu_size: field("pdu-size"),
119        detection_time_threshold: nested("detection-time", "threshold"),
120        transmit_interval_minimum: nested("transmit-interval", "minimum-interval"),
121        transmit_interval_threshold: nested("transmit-interval", "threshold"),
122        authentication_algorithm: nested("authentication", "algorithm"),
123        authentication_key_chain: nested("authentication", "key-chain"),
124        authentication_loose_check: child_block(bfd, "authentication")
125            .is_some_and(|auth| has_leaf(auth, "loose-check")),
126    }
127}
128
129/// The `family` statements of `parent`.
130pub(super) fn parse_families(parent: &ConfigLine) -> Vec<PimFamily> {
131    named_children(parent, "family")
132        .map(|(name, family)| PimFamily {
133            name: name.to_string(),
134            disable: has_leaf(family, "disable"),
135            bfd_liveness_detection: child_block(family, "bfd-liveness-detection").map(parse_bfd),
136        })
137        .collect()
138}
139
140pub(super) fn parse_interface(name: &str, interface: &ConfigLine) -> PimInterface {
141    let field = |keyword: &str| arg_of(interface, keyword).map(str::to_string);
142    let policies =
143        |keyword: &str| -> Vec<String> { args_of(interface, keyword).into_iter().flat_map(list_values).collect() };
144    PimInterface {
145        name: name.to_string(),
146        disable: has_leaf(interface, "disable"),
147        mode: field("mode"),
148        version: field("version"),
149        hello_interval: field("hello-interval"),
150        priority: field("priority"),
151        override_interval: field("override-interval"),
152        propagation_delay: field("propagation-delay"),
153        reset_tracking_bit: has_leaf(interface, "reset-tracking-bit"),
154        accept_remote_source: has_leaf(interface, "accept-remote-source"),
155        dual_dr_enhanced: child_block(interface, "dual-dr").is_some_and(|dual| has_leaf(dual, "enhanced")),
156        neighbor_policies: policies("neighbor-policy"),
157        accept_join_always_from: policies("accept-join-always-from"),
158        families: parse_families(interface),
159        bfd_liveness_detection: child_block(interface, "bfd-liveness-detection").map(parse_bfd),
160        df_election: child_block(interface, "bidirectional")
161            .and_then(|bidirectional| child_block(bidirectional, "df-election"))
162            .map(|df| PimDfElection {
163                backoff_period: arg_of(df, "backoff-period").map(str::to_string),
164                offer_period: arg_of(df, "offer-period").map(str::to_string),
165                robustness_count: arg_of(df, "robustness-count").map(str::to_string),
166            }),
167        multiple_triggered_joins: child_block(interface, "multiple-triggered-joins").map(|joins| {
168            PimMultipleTriggeredJoins {
169                count: arg_of(joins, "count").map(str::to_string),
170                interval: arg_of(joins, "interval").map(str::to_string),
171            }
172        }),
173    }
174}