Skip to main content

asterust_junos/interfaces/aggregated_ether_options/
mc_ae.rs

1//! `mc-ae`
2//! `interfaces <aeN> { aggregated-ether-options { mc-ae { ... } } }`.
3//!
4//! The multichassis aggregated Ethernet (MC-LAG) settings of a bundle.
5//!
6//! # See also
7//!
8//! - [mc-ae](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mc-ae-edit-interfaces.html)
9
10use crate::{arg_of, child_block, has_leaf};
11use asterust::config::ConfigLine;
12
13/// The `events` of `mc-ae`.
14#[derive(Clone, Debug, Default, PartialEq, Eq)]
15#[non_exhaustive]
16pub struct McAeEvents {
17    pub iccp_peer_down: bool,
18    pub force_icl_down: bool,
19    pub prefer_status_control_active: bool,
20}
21
22/// The `mc-ae` of an aggregated Ethernet bundle.
23#[derive(Clone, Debug, Default, PartialEq, Eq)]
24#[non_exhaustive]
25pub struct McAe {
26    pub chassis_id: Option<String>,
27    pub events: Option<McAeEvents>,
28    pub init_delay_time: Option<String>,
29    pub mc_ae_id: Option<String>,
30    /// `"active-active"` or `"active-standby"`.
31    pub mode: Option<String>,
32    pub redundancy_group: Option<String>,
33    pub revert_time: Option<String>,
34    /// `"active"` or `"standby"`.
35    pub status_control: Option<String>,
36    /// `"revertive"` or `"non-revertive"`.
37    pub switchover_mode: Option<String>,
38    pub enhanced_convergence: bool,
39}
40
41pub(super) fn parse_mc_ae(line: &ConfigLine) -> McAe {
42    let field = |keyword: &str| arg_of(line, keyword).map(str::to_string);
43    McAe {
44        chassis_id: field("chassis-id"),
45        events: child_block(line, "events").map(|events| McAeEvents {
46            iccp_peer_down: has_leaf(events, "iccp-peer-down"),
47            force_icl_down: has_leaf(events, "force-icl-down"),
48            prefer_status_control_active: has_leaf(events, "prefer-status-control-active"),
49        }),
50        init_delay_time: field("init-delay-time"),
51        mc_ae_id: field("mc-ae-id"),
52        mode: field("mode"),
53        redundancy_group: field("redundancy-group"),
54        revert_time: field("revert-time"),
55        status_control: field("status-control"),
56        switchover_mode: field("switchover-mode"),
57        enhanced_convergence: has_leaf(line, "enhanced-convergence"),
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use crate::interfaces::interfaces;
64    use asterust::config::juniper;
65
66    // Adapted from the MC-LAG User Guide, MC-LAG Examples: `ae1` of the first peer; see the README "Sources".
67    const DOC_MC_AE: &str = r#"
68interfaces {
69    ae1 {
70        aggregated-ether-options {
71            lacp {
72                active;
73                system-id 00:01:02:03:04:05;
74                admin-key 3;
75            }
76            mc-ae {
77                mc-ae-id 3;
78                redundancy-group 1;
79                chassis-id 0;
80                mode active-active;
81                status-control active;
82                init-delay-time 240;
83            }
84        }
85        unit 0 {
86            family ethernet-switching {
87                interface-mode trunk;
88                vlan {
89                    members v10;
90                }
91            }
92        }
93    }
94}
95"#;
96
97    #[test]
98    fn reads_the_guide_mc_ae() {
99        let ifaces = interfaces(&juniper::parse_braces(DOC_MC_AE));
100        let options = ifaces[0].aggregated_ether_options.as_ref().unwrap();
101        assert_eq!(options.lacp.as_ref().unwrap().admin_key.as_deref(), Some("3"));
102        let mc_ae = options.mc_ae.as_ref().unwrap();
103        assert_eq!(mc_ae.mc_ae_id.as_deref(), Some("3"));
104        assert_eq!(mc_ae.redundancy_group.as_deref(), Some("1"));
105        assert_eq!(mc_ae.chassis_id.as_deref(), Some("0"));
106        assert_eq!(mc_ae.mode.as_deref(), Some("active-active"));
107        assert_eq!(mc_ae.status_control.as_deref(), Some("active"));
108        assert_eq!(mc_ae.init_delay_time.as_deref(), Some("240"));
109        assert!(mc_ae.events.is_none() && !mc_ae.enhanced_convergence);
110    }
111
112    // Not from documentation: the other `mc-ae` statements of the CLI Reference page. See the README "Sources".
113    #[test]
114    fn reads_the_other_statements() {
115        let ifaces = interfaces(&juniper::parse_braces(
116            "interfaces {\n    ae2 {\n        aggregated-ether-options {\n            mc-ae {\n                mode active-standby;\n                revert-time 5;\n                switchover-mode revertive;\n                status-control standby;\n                enhanced-convergence;\n                events {\n                    iccp-peer-down;\n                    force-icl-down;\n                    prefer-status-control-active;\n                }\n            }\n        }\n    }\n    ae3 {\n        aggregated-ether-options {\n            minimum-links 1;\n        }\n    }\n}\n",
117        ));
118        let mc_ae = ifaces[0]
119            .aggregated_ether_options
120            .as_ref()
121            .unwrap()
122            .mc_ae
123            .as_ref()
124            .unwrap();
125        assert_eq!(mc_ae.mode.as_deref(), Some("active-standby"));
126        assert_eq!(mc_ae.revert_time.as_deref(), Some("5"));
127        assert_eq!(mc_ae.switchover_mode.as_deref(), Some("revertive"));
128        assert!(mc_ae.enhanced_convergence);
129        let events = mc_ae.events.as_ref().unwrap();
130        assert!(events.iccp_peer_down && events.force_icl_down && events.prefer_status_control_active);
131        assert!(ifaces[1].aggregated_ether_options.as_ref().unwrap().mc_ae.is_none());
132    }
133}