asterust_junos/interfaces/
multiservice_options.rs1use crate::{arg_of, child_block, has_leaf, toggle};
13use asterust::config::ConfigLine;
14
15#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct MultiserviceOptions {
19 pub core_dump: Option<bool>,
21 pub syslog: Option<bool>,
23 pub pic_boot_timeout: Option<String>,
25 pub down_on_flow_control: bool,
27 pub dump_on_flow_control: bool,
28 pub reset_on_flow_control: bool,
29 pub up_on_flow_control: bool,
30}
31
32pub(super) fn parse_multiservice_options(options: &ConfigLine) -> MultiserviceOptions {
33 let flow_control = |name| {
34 has_leaf(options, name)
35 || child_block(options, "flow-control-options").is_some_and(|block| has_leaf(block, name))
36 };
37 MultiserviceOptions {
38 core_dump: toggle(options, "core-dump"),
39 syslog: toggle(options, "syslog"),
40 pic_boot_timeout: arg_of(options, "pic-boot-timeout").map(str::to_string),
41 down_on_flow_control: flow_control("down-on-flow-control"),
42 dump_on_flow_control: flow_control("dump-on-flow-control"),
43 reset_on_flow_control: flow_control("reset-on-flow-control"),
44 up_on_flow_control: flow_control("up-on-flow-control"),
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use crate::interfaces::interfaces;
51 use asterust::config::juniper;
52
53 #[test]
55 fn extracts_multiservice_options() {
56 let ifaces = interfaces(&juniper::parse_braces(
57 r#"
58interfaces {
59 mo-1/0/0 {
60 multiservice-options {
61 core-dump;
62 no-syslog;
63 pic-boot-timeout 300;
64 flow-control-options {
65 down-on-flow-control;
66 reset-on-flow-control;
67 }
68 }
69 }
70 mo-1/0/1 {
71 multiservice-options {
72 no-core-dump;
73 syslog;
74 dump-on-flow-control;
75 }
76 }
77}
78"#,
79 ));
80 let first = ifaces[0].multiservice_options.as_ref().unwrap();
81 assert_eq!(first.core_dump, Some(true));
82 assert_eq!(first.syslog, Some(false));
83 assert_eq!(first.pic_boot_timeout.as_deref(), Some("300"));
84 assert!(first.down_on_flow_control && first.reset_on_flow_control);
85 assert!(!first.dump_on_flow_control && !first.up_on_flow_control);
86 let second = ifaces[1].multiservice_options.as_ref().unwrap();
87 assert_eq!(second.core_dump, Some(false));
88 assert_eq!(second.syslog, Some(true));
89 assert!(second.dump_on_flow_control);
90 }
91}