Skip to main content

asterust_junos/interfaces/aggregated_ether_options/
mod.rs

1//! `aggregated-ether-options`
2//! `interfaces { ae<n> { aggregated-ether-options { ... } } }`.
3//!
4//! # See also
5//!
6//! - [aggregated-ether-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/aggregated-ether-options-edit-interfaces.html)
7//! - [link-speed (Aggregated Ethernet)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/link-speed-edit-interfaces-ae.html)
8//! - [local-bias](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/local-bias-edit-interface-ae.html)
9//! - [local-minimum-links-threshold](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/local-minimum-links-threshold-edit-interfaces-ae.html)
10//! - [minimum-bandwidth](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/minimum-bandwidth-edit-interfaces.html)
11//! - [resilient-hash](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/resilient-hash-edit-interfaces.html)
12//! - [fcoe-lag](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/fcoe-lag-edit-interfaces.html)
13//! - [no-fcoe-lag](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-fcoe-lag-edit-interfaces.html)
14//! - [logical-interface-chassis-redundancy](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/logical-interface-chassis-redundancy-edit-interfaces.html)
15//! - [minimum-links](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/minimum-links-edit-interfaces.html)
16
17mod balancing;
18mod bfd_liveness_detection;
19mod lacp;
20mod mc_ae;
21
22pub use balancing::{Dlb, LinkProtection, LinkProtectionSubGroup, LoadBalance, RebalancePeriodic};
23pub use bfd_liveness_detection::{BfdDamping, BfdLivenessDetection};
24pub use lacp::Lacp;
25pub use mc_ae::{McAe, McAeEvents};
26
27use super::ether_options::{parse_ethernet_switch_profile, source_address_filter, EthernetSwitchProfile};
28use super::targeted_options::{parse_targeted_options, TargetedOptions};
29use crate::{arg_of, child_block, has_leaf, toggle, value_after};
30use asterust::config::ConfigLine;
31use balancing::{parse_dlb, parse_link_protection_sub_groups};
32pub(in crate::interfaces) use balancing::{parse_link_protection, parse_load_balance, parse_rebalance_periodic};
33use bfd_liveness_detection::parse_bfd_liveness_detection;
34pub(in crate::interfaces) use lacp::parse_lacp;
35use mc_ae::parse_mc_ae;
36
37/// The `aggregated-ether-options` of an aggregated Ethernet interface.
38#[derive(Clone, Debug, PartialEq, Eq)]
39#[non_exhaustive]
40pub struct AggregatedEtherOptions {
41    pub lacp: Option<Lacp>,
42    pub mc_ae: Option<McAe>,
43    pub bfd_liveness_detection: Option<BfdLivenessDetection>,
44    /// e.g. `"10g"` or `"mixed"`.
45    pub link_speed: Option<String>,
46    pub minimum_links: Option<String>,
47    /// `Some(true)` for `flow-control`, `Some(false)` for `no-flow-control`.
48    pub flow_control: Option<bool>,
49    /// `Some(true)` for `loopback`, `Some(false)` for `no-loopback`.
50    pub loopback: Option<bool>,
51    /// `Some(true)` for `source-filtering`, `Some(false)` for `no-source-filtering`.
52    pub source_filtering: Option<bool>,
53    pub link_protection: Option<LinkProtection>,
54    pub link_protection_sub_groups: Vec<LinkProtectionSubGroup>,
55    pub local_bias: bool,
56    pub local_minimum_links_threshold: Option<String>,
57    /// From `minimum-bandwidth bw-unit <unit> bw-value <value>`, e.g. `"gbps"`.
58    pub minimum_bandwidth_unit: Option<String>,
59    pub minimum_bandwidth_value: Option<String>,
60    pub resilient_hash: bool,
61    pub load_balance: Option<LoadBalance>,
62    pub rebalance_periodic: Option<RebalancePeriodic>,
63    pub dlb: Option<Dlb>,
64    /// `Some(true)` for `fcoe-lag`, `Some(false)` for `no-fcoe-lag`.
65    pub fcoe_lag: Option<bool>,
66    pub logical_interface_chassis_redundancy: bool,
67    pub logical_interface_fpc_redundancy: bool,
68    pub targeted_options: Option<TargetedOptions>,
69    pub ethernet_switch_profile: Option<EthernetSwitchProfile>,
70    /// The MAC addresses of `source-address-filter`.
71    pub source_address_filter: Vec<String>,
72}
73
74pub(super) fn parse_aggregated_ether_options(options: &ConfigLine) -> AggregatedEtherOptions {
75    let minimum_bandwidth = crate::statement_words(options, "minimum-bandwidth");
76    AggregatedEtherOptions {
77        lacp: child_block(options, "lacp").map(parse_lacp),
78        mc_ae: child_block(options, "mc-ae").map(parse_mc_ae),
79        bfd_liveness_detection: child_block(options, "bfd-liveness-detection").map(parse_bfd_liveness_detection),
80        link_speed: arg_of(options, "link-speed").map(str::to_string),
81        minimum_links: arg_of(options, "minimum-links").map(str::to_string),
82        flow_control: toggle(options, "flow-control"),
83        loopback: toggle(options, "loopback"),
84        source_filtering: toggle(options, "source-filtering"),
85        link_protection: child_block(options, "link-protection").map(parse_link_protection),
86        link_protection_sub_groups: parse_link_protection_sub_groups(options),
87        local_bias: has_leaf(options, "local-bias"),
88        local_minimum_links_threshold: arg_of(options, "local-minimum-links-threshold").map(str::to_string),
89        minimum_bandwidth_unit: minimum_bandwidth.as_ref().and_then(|w| value_after(w, "bw-unit")),
90        minimum_bandwidth_value: minimum_bandwidth.as_ref().and_then(|w| value_after(w, "bw-value")),
91        resilient_hash: has_leaf(options, "resilient-hash"),
92        load_balance: child_block(options, "load-balance").map(parse_load_balance),
93        rebalance_periodic: crate::active_children(options)
94            .find(|c| c.arg("rebalance-periodic").is_some())
95            .map(parse_rebalance_periodic),
96        dlb: child_block(options, "dlb").map(parse_dlb),
97        fcoe_lag: toggle(options, "fcoe-lag"),
98        logical_interface_chassis_redundancy: has_leaf(options, "logical-interface-chassis-redundancy"),
99        logical_interface_fpc_redundancy: has_leaf(options, "logical-interface-fpc-redundancy"),
100        targeted_options: child_block(options, "targeted-options").map(parse_targeted_options),
101        ethernet_switch_profile: child_block(options, "ethernet-switch-profile").map(parse_ethernet_switch_profile),
102        source_address_filter: source_address_filter(options),
103    }
104}
105
106#[cfg(test)]
107mod tests {
108    use crate::interfaces::interfaces;
109    use asterust::config::juniper;
110
111    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
112    #[test]
113    fn extracts_aggregated_ether_options_and_lacp() {
114        let ifaces = interfaces(&juniper::parse_braces(
115            r#"
116interfaces {
117    ae0 {
118        aggregated-ether-options {
119            link-speed 10g;
120            minimum-links 2;
121            no-flow-control;
122            lacp {
123                active;
124                periodic fast;
125                system-priority 100;
126                system-id 00:11:22:33:44:55;
127                admin-key 7;
128                force-up;
129                fast-failover;
130                accept-data;
131            }
132        }
133    }
134}
135"#,
136        ));
137        let options = ifaces[0].aggregated_ether_options.as_ref().unwrap();
138        assert_eq!(options.link_speed.as_deref(), Some("10g"));
139        assert_eq!(options.minimum_links.as_deref(), Some("2"));
140        assert_eq!(options.flow_control, Some(false));
141        assert_eq!(options.loopback, None);
142        assert_eq!(options.source_filtering, None);
143
144        let lacp = options.lacp.as_ref().unwrap();
145        assert_eq!(lacp.mode.as_deref(), Some("active"));
146        assert_eq!(lacp.periodic.as_deref(), Some("fast"));
147        assert_eq!(lacp.system_priority.as_deref(), Some("100"));
148        assert_eq!(lacp.system_id.as_deref(), Some("00:11:22:33:44:55"));
149        assert_eq!(lacp.admin_key.as_deref(), Some("7"));
150        assert!(lacp.force_up);
151        assert!(lacp.fast_failover);
152        assert!(lacp.accept_data);
153    }
154
155    #[test]
156    fn extracts_load_balancing_and_link_protection() {
157        let ifaces = interfaces(&juniper::parse_braces(
158            r#"
159interfaces {
160    ae2 {
161        aggregated-ether-options {
162            local-bias;
163            local-minimum-links-threshold 2;
164            minimum-bandwidth bw-unit gbps bw-value 20;
165            resilient-hash;
166            fcoe-lag;
167            logical-interface-chassis-redundancy;
168            rebalance-periodic time 03:30 interval 12;
169            link-protection {
170                revertive;
171            }
172            link-protection-sub-group g1 {
173                primary;
174            }
175            link-protection-sub-group g2 {
176                backup;
177            }
178            load-balance {
179                adaptive {
180                    pps;
181                    scan-interval 30;
182                    tolerance 20;
183                }
184                per-packet;
185                local-bias percent 60;
186            }
187            dlb {
188                assigned-flow;
189                flowlet inactivity-interval 64;
190                ether-type ipv4;
191            }
192            source-address-filter {
193                00:aa:bb:cc:dd:ee;
194            }
195            lacp {
196                active;
197                aggregate-wait-time 5;
198                sync-reset enable;
199                link-protection {
200                    non-revertive;
201                    disable;
202                }
203            }
204        }
205    }
206    ae3 {
207        aggregated-ether-options {
208            no-fcoe-lag;
209            link-protection {
210                disable;
211            }
212        }
213    }
214}
215"#,
216        ));
217        let options = ifaces[0].aggregated_ether_options.as_ref().unwrap();
218        assert!(options.local_bias);
219        assert_eq!(options.local_minimum_links_threshold.as_deref(), Some("2"));
220        assert_eq!(options.minimum_bandwidth_unit.as_deref(), Some("gbps"));
221        assert_eq!(options.minimum_bandwidth_value.as_deref(), Some("20"));
222        assert!(options.resilient_hash);
223        assert_eq!(options.fcoe_lag, Some(true));
224        assert!(options.logical_interface_chassis_redundancy);
225        let rebalance = options.rebalance_periodic.as_ref().unwrap();
226        assert_eq!(rebalance.time.as_deref(), Some("03:30"));
227        assert_eq!(rebalance.interval.as_deref(), Some("12"));
228        let protection = options.link_protection.as_ref().unwrap();
229        assert!(!protection.disable);
230        assert_eq!(protection.revertive, Some(true));
231        assert_eq!(options.link_protection_sub_groups.len(), 2);
232        assert_eq!(options.link_protection_sub_groups[0].name, "g1");
233        assert_eq!(options.link_protection_sub_groups[0].role.as_deref(), Some("primary"));
234        assert_eq!(options.link_protection_sub_groups[1].role.as_deref(), Some("backup"));
235        let balance = options.load_balance.as_ref().unwrap();
236        assert!(balance.adaptive && balance.adaptive_pps && balance.per_packet && !balance.no_adaptive);
237        assert_eq!(balance.adaptive_scan_interval.as_deref(), Some("30"));
238        assert_eq!(balance.adaptive_tolerance.as_deref(), Some("20"));
239        assert_eq!(balance.local_bias_percent.as_deref(), Some("60"));
240        let dlb = options.dlb.as_ref().unwrap();
241        assert!(dlb.assigned_flow && !dlb.per_packet);
242        assert_eq!(dlb.flowlet_inactivity_interval.as_deref(), Some("64"));
243        assert_eq!(dlb.ether_type.as_deref(), Some("ipv4"));
244        assert_eq!(options.source_address_filter, ["00:aa:bb:cc:dd:ee"]);
245        let lacp = options.lacp.as_ref().unwrap();
246        assert_eq!(lacp.aggregate_wait_time.as_deref(), Some("5"));
247        assert_eq!(lacp.sync_reset.as_deref(), Some("enable"));
248        let lacp_protection = lacp.link_protection.as_ref().unwrap();
249        assert!(lacp_protection.disable);
250        assert_eq!(lacp_protection.revertive, Some(false));
251
252        let other = ifaces[1].aggregated_ether_options.as_ref().unwrap();
253        assert_eq!(other.fcoe_lag, Some(false));
254        assert!(other.link_protection.as_ref().unwrap().disable);
255        assert!(other.load_balance.is_none() && other.dlb.is_none() && other.rebalance_periodic.is_none());
256        assert!(!other.local_bias && !other.resilient_hash);
257    }
258
259    #[test]
260    fn bare_lacp_has_no_settings() {
261        let ifaces = interfaces(&juniper::parse_braces(
262            "interfaces {\n    ae1 {\n        aggregated-ether-options {\n            lacp {\n                passive;\n            }\n        }\n    }\n}\n",
263        ));
264        let lacp = ifaces[0]
265            .aggregated_ether_options
266            .as_ref()
267            .unwrap()
268            .lacp
269            .as_ref()
270            .unwrap();
271        assert_eq!(lacp.mode.as_deref(), Some("passive"));
272        assert_eq!(lacp.periodic, None);
273        assert!(!lacp.force_up);
274    }
275
276    #[test]
277    fn aggregated_ether_options_are_optional() {
278        let ifaces = interfaces(&juniper::parse_braces(
279            "interfaces {\n    ae0 {\n        disable;\n    }\n}\n",
280        ));
281        assert!(ifaces[0].aggregated_ether_options.is_none());
282    }
283}