Skip to main content

asterust_junos/protocols/ospf/
overload.rs

1//! `overload`
2//! `protocols { ospf { overload { ... } } }`.
3//!
4//! # See also
5//!
6//! - [overload (Protocols OSPF)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/overload-edit-protocols-ospf.html)
7//! - [allow-route-leaking](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/protocols-ospf-overload-allow-route-leaking.html)
8//! - [as-external](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/protocols-ospf-overload-as-external.html)
9//! - [stub-network](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/protocols-ospf-overload-stub-network.html)
10
11use crate::{statement_words, value_after};
12use asterust::config::ConfigLine;
13
14/// The `overload` statement. A bare `overload;` leaves every field unset.
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
16#[non_exhaustive]
17pub struct OspfOverload {
18    /// Seconds; without it the overload bit stays set until the statement is removed.
19    pub timeout: Option<String>,
20    pub allow_route_leaking: bool,
21    pub as_external: bool,
22    pub stub_network: bool,
23}
24
25pub(super) fn parse_overload(ospf: &ConfigLine) -> Option<OspfOverload> {
26    let words = statement_words(ospf, "overload")?;
27    Some(OspfOverload {
28        timeout: value_after(&words, "timeout"),
29        allow_route_leaking: words.contains(&"allow-route-leaking"),
30        as_external: words.contains(&"as-external"),
31        stub_network: words.contains(&"stub-network"),
32    })
33}
34
35#[cfg(test)]
36mod tests {
37    use crate::protocols::ospf::ospf;
38    use asterust::config::juniper;
39
40    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
41    const FULL: &str = r#"
42protocols {
43    ospf {
44        overload {
45            timeout 300;
46            allow-route-leaking;
47            as-external;
48            stub-network;
49        }
50    }
51}
52"#;
53
54    #[test]
55    fn reads_the_timeout_and_flags() {
56        let overload = ospf(&juniper::parse_braces(FULL)).unwrap().overload.unwrap();
57        assert_eq!(overload.timeout.as_deref(), Some("300"));
58        assert!(overload.allow_route_leaking);
59        assert!(overload.as_external);
60        assert!(overload.stub_network);
61    }
62
63    #[test]
64    fn reads_the_bare_form_and_absence() {
65        let bare = juniper::parse_braces("protocols {\n    ospf {\n        overload;\n    }\n}\n");
66        let overload = ospf(&bare).unwrap().overload.unwrap();
67        assert_eq!(overload.timeout, None);
68        assert!(!overload.as_external);
69
70        let none = juniper::parse_braces("protocols {\n    ospf {\n        area 0.0.0.0;\n    }\n}\n");
71        assert_eq!(ospf(&none).unwrap().overload, None);
72    }
73}