asterust_junos/protocols/ospf/
overload.rs1use crate::{statement_words, value_after};
12use asterust::config::ConfigLine;
13
14#[derive(Clone, Debug, Default, PartialEq, Eq)]
16#[non_exhaustive]
17pub struct OspfOverload {
18 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 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}