Skip to main content

asterust_junos/interfaces/
multiservice_options.rs

1//! `multiservice-options`
2//! `interfaces { <name> { multiservice-options { ... } } }`.
3//!
4//! # See also
5//!
6//! - [multiservice-options (Flow Monitoring)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multiservice-options-edit-interfaces.html)
7//! - [multiservice-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multiservice-options-edit-interfaces-ni.html)
8//! - [flow-control-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/flow-control-options-edit-interfaces.html)
9//! - [dump-on-flow-control](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dump-on-flow-control-edit-interfaces.html)
10//! - [pic-boot-timeout](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pic-boot-timeout-edit-interfaces-multiservice-options.html)
11
12use crate::{arg_of, child_block, has_leaf, toggle};
13use asterust::config::ConfigLine;
14
15/// The `multiservice-options` of a monitoring services interface.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct MultiserviceOptions {
19    /// `Some(true)` for `core-dump`, `Some(false)` for `no-core-dump`.
20    pub core_dump: Option<bool>,
21    /// `Some(true)` for `syslog`, `Some(false)` for `no-syslog`.
22    pub syslog: Option<bool>,
23    /// Seconds, `240` or `300`.
24    pub pic_boot_timeout: Option<String>,
25    /// From the `flow-control-options` block or written directly under `multiservice-options`.
26    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    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
54    #[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}