//! `mc-ae`
//! `interfaces <aeN> { aggregated-ether-options { mc-ae { ... } } }`.
//!
//! The multichassis aggregated Ethernet (MC-LAG) settings of a bundle.
//!
//! # See also
//!
//! - [mc-ae](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mc-ae-edit-interfaces.html)
use crate::{arg_of, child_block, has_leaf};
use asterust::config::ConfigLine;
/// The `events` of `mc-ae`.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct McAeEvents {
pub iccp_peer_down: bool,
pub force_icl_down: bool,
pub prefer_status_control_active: bool,
}
/// The `mc-ae` of an aggregated Ethernet bundle.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct McAe {
pub chassis_id: Option<String>,
pub events: Option<McAeEvents>,
pub init_delay_time: Option<String>,
pub mc_ae_id: Option<String>,
/// `"active-active"` or `"active-standby"`.
pub mode: Option<String>,
pub redundancy_group: Option<String>,
pub revert_time: Option<String>,
/// `"active"` or `"standby"`.
pub status_control: Option<String>,
/// `"revertive"` or `"non-revertive"`.
pub switchover_mode: Option<String>,
pub enhanced_convergence: bool,
}
pub(super) fn parse_mc_ae(line: &ConfigLine) -> McAe {
let field = |keyword: &str| arg_of(line, keyword).map(str::to_string);
McAe {
chassis_id: field("chassis-id"),
events: child_block(line, "events").map(|events| McAeEvents {
iccp_peer_down: has_leaf(events, "iccp-peer-down"),
force_icl_down: has_leaf(events, "force-icl-down"),
prefer_status_control_active: has_leaf(events, "prefer-status-control-active"),
}),
init_delay_time: field("init-delay-time"),
mc_ae_id: field("mc-ae-id"),
mode: field("mode"),
redundancy_group: field("redundancy-group"),
revert_time: field("revert-time"),
status_control: field("status-control"),
switchover_mode: field("switchover-mode"),
enhanced_convergence: has_leaf(line, "enhanced-convergence"),
}
}
#[cfg(test)]
mod tests {
use crate::interfaces::interfaces;
use asterust::config::juniper;
// Adapted from the MC-LAG User Guide, MC-LAG Examples: `ae1` of the first peer; see the README "Sources".
const DOC_MC_AE: &str = r#"
interfaces {
ae1 {
aggregated-ether-options {
lacp {
active;
system-id 00:01:02:03:04:05;
admin-key 3;
}
mc-ae {
mc-ae-id 3;
redundancy-group 1;
chassis-id 0;
mode active-active;
status-control active;
init-delay-time 240;
}
}
unit 0 {
family ethernet-switching {
interface-mode trunk;
vlan {
members v10;
}
}
}
}
}
"#;
#[test]
fn reads_the_guide_mc_ae() {
let ifaces = interfaces(&juniper::parse_braces(DOC_MC_AE));
let options = ifaces[0].aggregated_ether_options.as_ref().unwrap();
assert_eq!(options.lacp.as_ref().unwrap().admin_key.as_deref(), Some("3"));
let mc_ae = options.mc_ae.as_ref().unwrap();
assert_eq!(mc_ae.mc_ae_id.as_deref(), Some("3"));
assert_eq!(mc_ae.redundancy_group.as_deref(), Some("1"));
assert_eq!(mc_ae.chassis_id.as_deref(), Some("0"));
assert_eq!(mc_ae.mode.as_deref(), Some("active-active"));
assert_eq!(mc_ae.status_control.as_deref(), Some("active"));
assert_eq!(mc_ae.init_delay_time.as_deref(), Some("240"));
assert!(mc_ae.events.is_none() && !mc_ae.enhanced_convergence);
}
// Not from documentation: the other `mc-ae` statements of the CLI Reference page. See the README "Sources".
#[test]
fn reads_the_other_statements() {
let ifaces = interfaces(&juniper::parse_braces(
"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",
));
let mc_ae = ifaces[0]
.aggregated_ether_options
.as_ref()
.unwrap()
.mc_ae
.as_ref()
.unwrap();
assert_eq!(mc_ae.mode.as_deref(), Some("active-standby"));
assert_eq!(mc_ae.revert_time.as_deref(), Some("5"));
assert_eq!(mc_ae.switchover_mode.as_deref(), Some("revertive"));
assert!(mc_ae.enhanced_convergence);
let events = mc_ae.events.as_ref().unwrap();
assert!(events.iccp_peer_down && events.force_icl_down && events.prefer_status_control_active);
assert!(ifaces[1].aggregated_ether_options.as_ref().unwrap().mc_ae.is_none());
}
}