asterust_junos/protocols/mld.rs
1//! `mld`
2//! `protocols { mld { ... } }`.
3//!
4//! The configuration is shared with [`igmp`](super::igmp), see [`GroupMembership`].
5//!
6//! # See also
7//!
8//! - [mld](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mld-edit-protocols.html)
9//! - [accounting (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/accounting-edit-protocols-mld.html)
10//! - [maximum-transmit-rate (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/maximum-transmit-rate-edit-protocols-mld.html)
11//! - [query-interval (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/query-interval-edit-protocols-mld.html)
12//! - [query-last-member-interval (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/query-last-member-interval-edit-protocols-mld.html)
13//! - [query-response-interval (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/query-response-interval-edit-protocols-mld.html)
14//! - [robust-count (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/robust-count-edit-protocols-mld.html)
15//! - [interface (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-mld.html)
16//! - [disable (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/disable-edit-protocols-mld.html)
17//! - [group-limit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/group-limit-edit-protocols-mld-interface.html)
18//! - [group-policy (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/group-policy-edit-protocols-mld.html)
19//! - [group-threshold](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/group-threshold-edit-protocols-mld-interface.html)
20//! - [log-interval](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/log-interval-edit-protocols-mld-interface.html)
21//! - [oif-map](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/oif-map-edit-protocols-mld-interface.html)
22//! - [passive](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/passive-edit-protocols-mld-interface.html)
23//! - [ssm-map (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ssm-map-edit-protocols-mld.html)
24//! - [ssm-map-policy (MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ssm-map-policy-edit-protocols-mld.html)
25//! - [version (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/version-edit-protocols-mld.html)
26//! - [static (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/static-edit-protocols-mld.html)
27//! - [group (Protocols MLD)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/group-edit-protocols-mld.html)
28//! - [Configuring MLD](https://networkingdocs.hpe.com/documentation/us/en/software/junos/multicast/topics/topic-map/mcast-mld.html), for `accounting` and `immediate-leave`
29
30use super::group_membership::{parse_group_membership, GroupMembership, MembershipInterface};
31use crate::{child_block, top_level};
32use asterust::config::Config;
33
34/// The `protocols mld` configuration.
35pub type Mld = GroupMembership;
36
37/// An `interface` entry of MLD.
38pub type MldInterface = MembershipInterface;
39
40/// Returns the `protocols mld` block, or `None` if MLD is not configured.
41///
42/// # Examples
43///
44/// ```
45/// use asterust::config::juniper;
46/// use asterust_junos::protocols::mld::mld;
47///
48/// let config = juniper::parse_braces("protocols {\n mld {\n interface ge-0/1/0.0 {\n version 2;\n }\n }\n}\n");
49/// let mld = mld(&config).unwrap();
50/// assert_eq!(mld.interfaces[0].version.as_deref(), Some("2"));
51/// ```
52pub fn mld(config: &Config) -> Option<Mld> {
53 child_block(top_level(config, "protocols")?, "mld").map(parse_group_membership)
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use asterust::config::juniper;
60
61 // Blocks of the Examples: Configuring PIM Sparse Mode and Example: Configuring Source-Specific Multicast pages of
62 // the Multicast Protocols User Guide; see the README "Sources".
63 const DOC_STATIC_GROUPS: &str = r#"
64protocols {
65 mld {
66 interface ge-0/1/0.0 {
67 static {
68 group ff0e::10;
69 }
70 }
71 interface ge-0/1/1.0 {
72 static {
73 group ff0e::10;
74 }
75 }
76 }
77}
78"#;
79
80 const DOC_SSM_MAP: &str = r#"
81protocols {
82 mld {
83 interface fe-0/1/1.0 {
84 ssm-map ssm-map-ipv6-example;
85 }
86 }
87}
88"#;
89
90 // Not from documentation: written from the CLI Reference pages of the statements. See the README "Sources".
91 const EXTRA: &str = r#"
92protocols {
93 mld {
94 accounting;
95 maximum-transmit-rate 400;
96 query-interval 125;
97 query-last-member-interval 1;
98 query-response-interval 10;
99 robust-count 2;
100 interface all {
101 version 2;
102 immediate-leave;
103 oif-map [ om1 om2 ];
104 passive;
105 group-limit 50;
106 group-policy gp;
107 group-threshold 90;
108 log-interval 30;
109 ssm-map-policy ssmp;
110 accounting;
111 static {
112 group ff0e::20 {
113 source 2001:db8::1 {
114 source-count 3;
115 }
116 }
117 }
118 }
119 interface fxp0.0 {
120 disable;
121 }
122 }
123}
124"#;
125
126 fn mld_of(text: &str) -> Mld {
127 mld(&juniper::parse_braces(text)).unwrap()
128 }
129
130 #[test]
131 fn reads_the_guide_static_groups_and_ssm_map() {
132 let mld = mld_of(DOC_STATIC_GROUPS);
133 assert_eq!(mld.interfaces.len(), 2);
134 assert_eq!(mld.interfaces[0].name, "ge-0/1/0.0");
135 assert_eq!(mld.interfaces[0].static_groups.len(), 1);
136 assert_eq!(mld.interfaces[0].static_groups[0].group, "ff0e::10");
137 assert!(mld.interfaces[0].static_groups[0].sources.is_empty());
138 assert_eq!(mld.interfaces[1].static_groups[0].group, "ff0e::10");
139
140 let mld = mld_of(DOC_SSM_MAP);
141 assert_eq!(mld.interfaces[0].ssm_map.as_deref(), Some("ssm-map-ipv6-example"));
142 }
143
144 #[test]
145 fn reads_the_global_and_interface_options() {
146 let mld = mld_of(EXTRA);
147 assert!(mld.accounting);
148 assert_eq!(mld.maximum_transmit_rate.as_deref(), Some("400"));
149 assert_eq!(mld.query_interval.as_deref(), Some("125"));
150 assert_eq!(mld.query_last_member_interval.as_deref(), Some("1"));
151 assert_eq!(mld.query_response_interval.as_deref(), Some("10"));
152 assert_eq!(mld.robust_count.as_deref(), Some("2"));
153 assert_eq!(mld.traceoptions, None);
154
155 let all = &mld.interfaces[0];
156 assert_eq!(all.name, "all");
157 assert_eq!(all.version.as_deref(), Some("2"));
158 assert!(all.immediate_leave);
159 assert_eq!(all.oif_maps, ["om1", "om2"]);
160 assert!(all.passive);
161 assert!(!all.promiscuous_mode);
162 assert_eq!(all.group_limit.as_deref(), Some("50"));
163 assert_eq!(all.group_policies, ["gp"]);
164 assert_eq!(all.group_threshold.as_deref(), Some("90"));
165 assert_eq!(all.log_interval.as_deref(), Some("30"));
166 assert_eq!(all.ssm_map_policy.as_deref(), Some("ssmp"));
167 assert_eq!(all.accounting, Some(true));
168 assert!(mld.interfaces[1].disable);
169 }
170
171 #[test]
172 fn reads_a_static_group_source() {
173 let mld = mld_of(EXTRA);
174 let group = &mld.interfaces[0].static_groups[0];
175 assert_eq!(group.group, "ff0e::20");
176 assert_eq!(group.sources[0].address, "2001:db8::1");
177 assert_eq!(group.sources[0].source_count.as_deref(), Some("3"));
178 }
179
180 #[test]
181 fn no_mld_is_none() {
182 let config = juniper::parse_braces("protocols {\n igmp {\n accounting;\n }\n}\n");
183 assert_eq!(mld(&config), None);
184 }
185}