asterust_junos/interfaces/aggregated_ether_options/
mod.rs1mod bfd_liveness_detection;
11mod lacp;
12
13pub use bfd_liveness_detection::BfdLivenessDetection;
14pub use lacp::Lacp;
15
16use crate::{arg_of, child_block, toggle};
17use asterust::config::ConfigLine;
18use bfd_liveness_detection::parse_bfd_liveness_detection;
19use lacp::parse_lacp;
20
21#[derive(Clone, Debug, PartialEq, Eq)]
23#[non_exhaustive]
24pub struct AggregatedEtherOptions {
25 pub lacp: Option<Lacp>,
26 pub bfd_liveness_detection: Option<BfdLivenessDetection>,
27 pub link_speed: Option<String>,
29 pub minimum_links: Option<String>,
30 pub flow_control: Option<bool>,
32 pub loopback: Option<bool>,
34 pub source_filtering: Option<bool>,
36}
37
38pub(super) fn parse_aggregated_ether_options(options: &ConfigLine) -> AggregatedEtherOptions {
39 AggregatedEtherOptions {
40 lacp: child_block(options, "lacp").map(parse_lacp),
41 bfd_liveness_detection: child_block(options, "bfd-liveness-detection").map(parse_bfd_liveness_detection),
42 link_speed: arg_of(options, "link-speed").map(str::to_string),
43 minimum_links: arg_of(options, "minimum-links").map(str::to_string),
44 flow_control: toggle(options, "flow-control"),
45 loopback: toggle(options, "loopback"),
46 source_filtering: toggle(options, "source-filtering"),
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use crate::interfaces::interfaces;
53 use asterust::config::juniper;
54
55 #[test]
57 fn extracts_aggregated_ether_options_and_lacp() {
58 let ifaces = interfaces(&juniper::parse_braces(
59 r#"
60interfaces {
61 ae0 {
62 aggregated-ether-options {
63 link-speed 10g;
64 minimum-links 2;
65 no-flow-control;
66 lacp {
67 active;
68 periodic fast;
69 system-priority 100;
70 system-id 00:11:22:33:44:55;
71 admin-key 7;
72 force-up;
73 fast-failover;
74 accept-data;
75 }
76 }
77 }
78}
79"#,
80 ));
81 let options = ifaces[0].aggregated_ether_options.as_ref().unwrap();
82 assert_eq!(options.link_speed.as_deref(), Some("10g"));
83 assert_eq!(options.minimum_links.as_deref(), Some("2"));
84 assert_eq!(options.flow_control, Some(false));
85 assert_eq!(options.loopback, None);
86 assert_eq!(options.source_filtering, None);
87
88 let lacp = options.lacp.as_ref().unwrap();
89 assert_eq!(lacp.mode.as_deref(), Some("active"));
90 assert_eq!(lacp.periodic.as_deref(), Some("fast"));
91 assert_eq!(lacp.system_priority.as_deref(), Some("100"));
92 assert_eq!(lacp.system_id.as_deref(), Some("00:11:22:33:44:55"));
93 assert_eq!(lacp.admin_key.as_deref(), Some("7"));
94 assert!(lacp.force_up);
95 assert!(lacp.fast_failover);
96 assert!(lacp.accept_data);
97 }
98
99 #[test]
100 fn bare_lacp_has_no_settings() {
101 let ifaces = interfaces(&juniper::parse_braces(
102 "interfaces {\n ae1 {\n aggregated-ether-options {\n lacp {\n passive;\n }\n }\n }\n}\n",
103 ));
104 let lacp = ifaces[0]
105 .aggregated_ether_options
106 .as_ref()
107 .unwrap()
108 .lacp
109 .as_ref()
110 .unwrap();
111 assert_eq!(lacp.mode.as_deref(), Some("passive"));
112 assert_eq!(lacp.periodic, None);
113 assert!(!lacp.force_up);
114 }
115
116 #[test]
117 fn aggregated_ether_options_are_optional() {
118 let ifaces = interfaces(&juniper::parse_braces(
119 "interfaces {\n ae0 {\n disable;\n }\n}\n",
120 ));
121 assert!(ifaces[0].aggregated_ether_options.is_none());
122 }
123}