asterust_junos/protocols/isis/
overload.rs1use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, Default, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct IsisOverload {
15 pub timeout: Option<String>,
17 pub advertise_high_metrics: bool,
18 pub allow_route_leaking: bool,
19 pub external_prefixes: bool,
20 pub internal_prefixes: bool,
21}
22
23pub(super) fn parse_overload(isis: &ConfigLine) -> Option<IsisOverload> {
24 let words = statement_words(isis, "overload")?;
25 Some(IsisOverload {
26 timeout: value_after(&words, "timeout"),
27 advertise_high_metrics: words.contains(&"advertise-high-metrics"),
28 allow_route_leaking: words.contains(&"allow-route-leaking"),
29 external_prefixes: words.contains(&"external-prefixes"),
30 internal_prefixes: words.contains(&"internal-prefixes"),
31 })
32}
33
34#[cfg(test)]
35mod tests {
36 use crate::protocols::isis::isis;
37 use asterust::config::juniper;
38
39 const FULL: &str = r#"
41protocols {
42 isis {
43 overload {
44 timeout 300;
45 advertise-high-metrics;
46 allow-route-leaking;
47 external-prefixes;
48 }
49 }
50}
51"#;
52
53 #[test]
54 fn reads_the_timeout_and_flags() {
55 let overload = isis(&juniper::parse_braces(FULL)).unwrap().overload.unwrap();
56 assert_eq!(overload.timeout.as_deref(), Some("300"));
57 assert!(overload.advertise_high_metrics);
58 assert!(overload.allow_route_leaking);
59 assert!(overload.external_prefixes);
60 assert!(!overload.internal_prefixes);
61 }
62
63 #[test]
64 fn reads_the_bare_form_and_absence() {
65 let bare = juniper::parse_braces("protocols {\n isis {\n overload;\n }\n}\n");
66 let overload = isis(&bare).unwrap().overload.unwrap();
67 assert_eq!(overload.timeout, None);
68 assert!(!overload.allow_route_leaking);
69
70 let none = juniper::parse_braces("protocols {\n isis {\n interface ge-0/0/0.0;\n }\n}\n");
71 assert_eq!(isis(&none).unwrap().overload, None);
72 }
73}