asterust_junos/protocols/
isis.rs1use crate::{child_block, has_leaf, named_children, top_level};
10use asterust::config::Config;
11
12#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct IsisInterface {
16 pub name: String,
17 pub passive: bool,
18 pub point_to_point: bool,
19}
20
21#[derive(Clone, Debug, PartialEq, Eq)]
24#[non_exhaustive]
25pub struct Isis {
26 pub interfaces: Vec<IsisInterface>,
27}
28
29pub fn isis(config: &Config) -> Option<Isis> {
43 let isis = child_block(top_level(config, "protocols")?, "isis")?;
44 Some(Isis {
45 interfaces: named_children(isis, "interface")
46 .map(|(name, iface)| IsisInterface {
47 name: name.to_string(),
48 passive: has_leaf(iface, "passive"),
49 point_to_point: has_leaf(iface, "point-to-point"),
50 })
51 .collect(),
52 })
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58 use asterust::config::juniper;
59
60 const CONFIG: &str = r#"
62protocols {
63 isis {
64 level 2 wide-metrics-only;
65 interface ge-0/0/0.0 {
66 point-to-point;
67 level 1 disable;
68 }
69 interface lo0.0 {
70 passive;
71 }
72 interface ge-0/0/1.0;
73 }
74}
75"#;
76
77 #[test]
78 fn extracts_interfaces() {
79 let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
80 let names: Vec<_> = isis.interfaces.iter().map(|i| i.name.as_str()).collect();
81 assert_eq!(names, ["ge-0/0/0.0", "lo0.0", "ge-0/0/1.0"]);
82 assert!(isis.interfaces[0].point_to_point);
83 assert!(!isis.interfaces[0].passive);
84 assert!(isis.interfaces[1].passive);
85 assert!(!isis.interfaces[2].point_to_point);
86 }
87
88 #[test]
89 fn no_isis_is_none() {
90 assert!(isis(&juniper::parse_braces("protocols {\n bgp {\n }\n}\n")).is_none());
91 }
92}