asterust_junos/routing_options/
maximum_paths.rs1use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct MaximumPaths {
15 pub path_limit: Option<String>,
16 pub log_interval: Option<String>,
18 pub log_only: bool,
20 pub threshold: Option<String>,
22}
23
24pub(super) fn parse_maximum_paths(root: &ConfigLine) -> Option<MaximumPaths> {
25 let words = statement_words(root, "maximum-paths")?;
26 Some(MaximumPaths {
27 path_limit: words.first().map(|word| word.to_string()),
28 log_interval: value_after(&words, "log-interval"),
29 log_only: words.contains(&"log-only"),
30 threshold: value_after(&words, "threshold"),
31 })
32}
33
34#[cfg(test)]
35mod tests {
36 use crate::routing_options::routing_options;
37 use asterust::config::juniper;
38
39 #[test]
41 fn extracts_limit_threshold_and_interval() {
42 let options = routing_options(&juniper::parse_braces(
43 "routing-options {\n maximum-paths 1000 threshold 80 log-interval 60;\n}\n",
44 ))
45 .unwrap();
46 let paths = options.maximum_paths.unwrap();
47 assert_eq!(paths.path_limit.as_deref(), Some("1000"));
48 assert_eq!(paths.threshold.as_deref(), Some("80"));
49 assert_eq!(paths.log_interval.as_deref(), Some("60"));
50 assert!(!paths.log_only);
51 }
52
53 #[test]
54 fn extracts_log_only() {
55 let options = routing_options(&juniper::parse_braces(
56 "routing-options {\n maximum-paths 500 log-only;\n}\n",
57 ))
58 .unwrap();
59 let paths = options.maximum_paths.unwrap();
60 assert_eq!(paths.path_limit.as_deref(), Some("500"));
61 assert!(paths.log_only);
62 assert_eq!(paths.threshold, None);
63 }
64
65 #[test]
66 fn no_maximum_paths_is_none() {
67 let options = routing_options(&juniper::parse_braces(
68 "routing-options {\n router-id 192.0.2.1;\n}\n",
69 ))
70 .unwrap();
71 assert!(options.maximum_paths.is_none());
72 }
73}