asterust_junos/policy_options/
lists.rs1use crate::{active_children, args_of};
10use asterust::config::ConfigLine;
11
12#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct MacList {
16 pub name: String,
17 pub mac_addresses: Vec<String>,
18}
19
20#[derive(Clone, Debug, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct RibList {
24 pub name: String,
25 pub items: Vec<String>,
27}
28
29pub(super) fn parse_mac_list(name: &str, line: &ConfigLine) -> MacList {
30 MacList {
31 name: name.to_string(),
32 mac_addresses: active_children(line)
34 .filter(|c| !c.text.contains(' '))
35 .map(|c| c.text.clone())
36 .collect(),
37 }
38}
39
40pub(super) fn parse_rib_list(name: &str, line: &ConfigLine) -> RibList {
41 RibList {
42 name: name.to_string(),
43 items: args_of(line, "rib-list-item").into_iter().map(str::to_string).collect(),
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use crate::policy_options::policy_options;
50 use asterust::config::juniper;
51
52 #[test]
54 fn reads_mac_and_rib_lists() {
55 let config = juniper::parse_braces(
56 "policy-options {\n mac-list MACS {\n 00:11:22:33:44:55;\n 00:11:22:33:44:66;\n }\n rib-list RIBS {\n rib-list-item inet.0;\n rib-list-item vrf-a.inet.0;\n }\n}\n",
57 );
58 let options = policy_options(&config).unwrap();
59 assert_eq!(options.mac_lists[0].name, "MACS");
60 assert_eq!(
61 options.mac_lists[0].mac_addresses,
62 ["00:11:22:33:44:55", "00:11:22:33:44:66"]
63 );
64 assert_eq!(options.rib_lists[0].name, "RIBS");
65 assert_eq!(options.rib_lists[0].items, ["inet.0", "vrf-a.inet.0"]);
66 }
67}