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