asterust_junos/system/services/
extensible_subscriber_services.rs1use crate::{arg_of, child_block};
14use asterust::config::ConfigLine;
15
16#[derive(Clone, Debug, PartialEq, Eq)]
18#[non_exhaustive]
19pub struct ExtensibleSubscriberServices {
20 pub access_profile: Option<String>,
21 pub commit_interval: Option<String>,
23 pub dictionary: Option<String>,
24 pub flat_file_profile: Option<String>,
25 pub logical_interface_unit_low: Option<String>,
27 pub logical_interface_unit_high: Option<String>,
29 pub maximum_subscribers: Option<String>,
30}
31
32pub(super) fn parse_extensible_subscriber_services(essmd: &ConfigLine) -> ExtensibleSubscriberServices {
33 let range = child_block(essmd, "logical-interface-unit-range");
34 let field = |keyword: &str| arg_of(essmd, keyword).map(str::to_string);
35 ExtensibleSubscriberServices {
36 access_profile: field("access-profile"),
37 commit_interval: field("commit-interval"),
38 dictionary: field("dictionary"),
39 flat_file_profile: field("flat-file-profile"),
40 logical_interface_unit_low: range.and_then(|r| arg_of(r, "low")).map(str::to_string),
41 logical_interface_unit_high: range.and_then(|r| arg_of(r, "high")).map(str::to_string),
42 maximum_subscribers: field("maximum-subscribers"),
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use crate::system::system;
49 use asterust::config::juniper;
50
51 #[test]
53 fn extracts_the_extensible_subscriber_services() {
54 let essmd = system(&juniper::parse_braces(
55 r#"
56system {
57 services {
58 extensible-subscriber-services {
59 access-profile ess-access;
60 commit-interval 60;
61 dictionary /var/etc/ess.dict;
62 flat-file-profile ess-flat;
63 logical-interface-unit-range {
64 low 1000;
65 high 2000;
66 }
67 maximum-subscribers 5000;
68 }
69 }
70}
71"#,
72 ))
73 .unwrap()
74 .services
75 .unwrap()
76 .extensible_subscriber_services
77 .unwrap();
78 assert_eq!(essmd.access_profile.as_deref(), Some("ess-access"));
79 assert_eq!(essmd.commit_interval.as_deref(), Some("60"));
80 assert_eq!(essmd.dictionary.as_deref(), Some("/var/etc/ess.dict"));
81 assert_eq!(essmd.flat_file_profile.as_deref(), Some("ess-flat"));
82 assert_eq!(essmd.logical_interface_unit_low.as_deref(), Some("1000"));
83 assert_eq!(essmd.logical_interface_unit_high.as_deref(), Some("2000"));
84 assert_eq!(essmd.maximum_subscribers.as_deref(), Some("5000"));
85 }
86
87 #[test]
88 fn no_extensible_subscriber_services_is_none() {
89 let services = system(&juniper::parse_braces(
90 "system {\n services {\n telnet;\n }\n}\n",
91 ))
92 .unwrap()
93 .services
94 .unwrap();
95 assert!(services.extensible_subscriber_services.is_none());
96 }
97}