asterust_junos/protocols/ospf/
database_protection.rs1use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, Default, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct OspfDatabaseProtection {
15 pub maximum_lsa: Option<String>,
16 pub ignore_count: Option<String>,
17 pub ignore_time: Option<String>,
19 pub reset_time: Option<String>,
21 pub warning_threshold: Option<String>,
23 pub warning_only: bool,
24}
25
26pub(super) fn parse_database_protection(ospf: &ConfigLine) -> Option<OspfDatabaseProtection> {
27 let words = statement_words(ospf, "database-protection")?;
28 Some(OspfDatabaseProtection {
29 maximum_lsa: value_after(&words, "maximum-lsa"),
30 ignore_count: value_after(&words, "ignore-count"),
31 ignore_time: value_after(&words, "ignore-time"),
32 reset_time: value_after(&words, "reset-time"),
33 warning_threshold: value_after(&words, "warning-threshold"),
34 warning_only: words.contains(&"warning-only"),
35 })
36}
37
38#[cfg(test)]
39mod tests {
40 use crate::protocols::ospf::ospf;
41 use asterust::config::juniper;
42
43 const CONFIG: &str = r#"
45protocols {
46 ospf {
47 database-protection {
48 maximum-lsa 100000;
49 ignore-count 3;
50 ignore-time 120;
51 reset-time 900;
52 warning-threshold 80;
53 warning-only;
54 }
55 }
56}
57"#;
58
59 #[test]
60 fn reads_the_limits() {
61 let protection = ospf(&juniper::parse_braces(CONFIG))
62 .unwrap()
63 .database_protection
64 .unwrap();
65 assert_eq!(protection.maximum_lsa.as_deref(), Some("100000"));
66 assert_eq!(protection.ignore_count.as_deref(), Some("3"));
67 assert_eq!(protection.ignore_time.as_deref(), Some("120"));
68 assert_eq!(protection.reset_time.as_deref(), Some("900"));
69 assert_eq!(protection.warning_threshold.as_deref(), Some("80"));
70 assert!(protection.warning_only);
71 }
72
73 #[test]
74 fn leaves_unwritten_limits_unset() {
75 let config = juniper::parse_braces("protocols {\n ospf {\n database-protection {\n maximum-lsa 500;\n }\n }\n}\n");
76 let protection = ospf(&config).unwrap().database_protection.unwrap();
77 assert_eq!(protection.maximum_lsa.as_deref(), Some("500"));
78 assert_eq!(protection.reset_time, None);
79 assert!(!protection.warning_only);
80 }
81}