Skip to main content

asterust_junos/protocols/isis/interface/
mod.rs

1//! `interface`
2//! `protocols { isis { interface <name | all> { ... } } }`.
3//!
4//! # See also
5//!
6//! - [interface (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-isis.html)
7//! - [passive (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/passive-edit-protocols-isis.html)
8//! - [link-protection (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/link-protection-edit-protocols-isis.html)
9//! - [strict-dual-isis (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/strict-dual-isis-edit-protocols-isis.html)
10//! - [delay-metric](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/delay-metric-protocols-isis-interface.html)
11//! - [no-advertise-adjacency-segment (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-advertise-adjacency-segment-edit-protocols-isis-interface-level.html)
12//! - [point-to-point](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/point-to-point-edit-protocols-isis.html), from the Junos 12.3 archive
13//! - [lsp-interval](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/lsp-interval-edit-protocols-isis.html), from the Junos 12.3 archive
14//! - [csnp-interval](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/csnp-interval-edit-protocols-isis.html), from the Junos 12.3 archive
15//! - [hello-padding](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/hello-padding-edit-protocols-isis.html), from the Junos 12.3 archive
16//! - [checksum (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/checksum-edit-protocols-isis.html), from the Junos 12.3 archive
17//! - [mesh-group (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/mesh-group-edit-protocols-isis.html), from the Junos 12.3 archive
18//! - [ldp-synchronization](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/ldp-synchronization-edit-protocols-isis.html), from the Junos 12.3 archive
19//! - [no-adjacency-holddown](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/no-adjacency-holddown-edit-protocols-isis.html), from the Junos 12.3 archive
20//! - [node-link-protection (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/node-link-protection-edit-protocols-isis.html), from the Junos 12.3 archive
21//! - [no-eligible-backup (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/no-eligible-backup-edit-protocols-isis.html), from the Junos 12.3 archive
22//! - [no-ipv4-multicast](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/no-ipv4-multicast-edit-protocols-isis.html), from the Junos 12.3 archive
23//! - [no-ipv6-multicast](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/no-ipv6-multicast-edit-protocols-isis.html), from the Junos 12.3 archive
24
25mod bfd;
26mod level;
27
28pub use bfd::IsisBfd;
29pub use level::IsisInterfaceLevel;
30
31use crate::{arg_of, args_of, has_leaf, list_values, named_children, statement_words, value_after};
32use asterust::config::ConfigLine;
33use bfd::parse_bfd;
34use level::parse_level;
35
36/// An `interface <name>` entry under IS-IS. Values are kept as written. The `delay-measurement` block and the
37/// `application-specific` blocks of a level are not extracted.
38#[derive(Clone, Debug, PartialEq, Eq)]
39#[non_exhaustive]
40pub struct IsisInterface {
41    pub name: String,
42    pub passive: bool,
43    pub point_to_point: bool,
44    pub disable: bool,
45    /// From `passive { remote-node-id ...; }`.
46    pub passive_remote_node_id: Option<String>,
47    /// From `passive { remote-node-iso ...; }`.
48    pub passive_remote_node_iso: Option<String>,
49    /// Milliseconds.
50    pub lsp_interval: Option<String>,
51    /// Seconds, or `disable`.
52    pub csnp_interval: Option<String>,
53    /// `adaptive`, `disable`, `loose` or `strict`.
54    pub hello_padding: Option<String>,
55    pub max_hello_size: Option<String>,
56    /// A number, or `blocked`.
57    pub mesh_group: Option<String>,
58    pub interface_group_holddown_delay: Option<String>,
59    pub srlg: Vec<String>,
60    pub delay_metric: Option<String>,
61    pub strict_dual_isis: bool,
62    /// Seconds, from `strict-dual-isis holddown ...`.
63    pub strict_dual_isis_holddown: Option<String>,
64    pub ldp_synchronization_disable: bool,
65    /// Seconds.
66    pub ldp_synchronization_hold_time: Option<String>,
67    pub bfd_liveness_detection: Option<IsisBfd>,
68    /// The `level <1|2>` entries of the interface.
69    pub levels: Vec<IsisInterfaceLevel>,
70    pub checksum: bool,
71    pub flood_group: bool,
72    pub link_protection: bool,
73    pub node_link_protection: bool,
74    pub no_adjacency_holddown: bool,
75    pub no_eligible_backup: bool,
76    pub no_eligible_remote_backup: bool,
77    pub no_ipv4_multicast: bool,
78    pub no_ipv6_multicast: bool,
79    pub no_ipv6_unicast: bool,
80    pub no_unicast_topology: bool,
81    pub no_advertise_adjacency_segment: bool,
82}
83
84pub(super) fn parse_interface(name: &str, iface: &ConfigLine) -> IsisInterface {
85    let field = |keyword: &str| arg_of(iface, keyword).map(str::to_string);
86    let present = |keyword: &str| statement_words(iface, keyword).is_some();
87    let passive = statement_words(iface, "passive");
88    let ldp = statement_words(iface, "ldp-synchronization");
89    let strict = statement_words(iface, "strict-dual-isis");
90    IsisInterface {
91        name: name.to_string(),
92        passive: has_leaf(iface, "passive"),
93        point_to_point: has_leaf(iface, "point-to-point"),
94        disable: has_leaf(iface, "disable"),
95        passive_remote_node_id: passive.as_ref().and_then(|words| value_after(words, "remote-node-id")),
96        passive_remote_node_iso: passive.as_ref().and_then(|words| value_after(words, "remote-node-iso")),
97        lsp_interval: field("lsp-interval"),
98        csnp_interval: field("csnp-interval"),
99        hello_padding: field("hello-padding"),
100        max_hello_size: field("max-hello-size"),
101        mesh_group: field("mesh-group"),
102        interface_group_holddown_delay: field("interface-group-holddown-delay"),
103        srlg: args_of(iface, "srlg").into_iter().flat_map(list_values).collect(),
104        delay_metric: field("delay-metric"),
105        strict_dual_isis: strict.is_some(),
106        strict_dual_isis_holddown: strict.and_then(|words| value_after(&words, "holddown")),
107        ldp_synchronization_disable: ldp.as_ref().is_some_and(|words| words.contains(&"disable")),
108        ldp_synchronization_hold_time: ldp.and_then(|words| value_after(&words, "hold-time")),
109        bfd_liveness_detection: parse_bfd(iface),
110        levels: named_children(iface, "level")
111            .map(|(arg, level)| parse_level(arg, level))
112            .collect(),
113        checksum: has_leaf(iface, "checksum"),
114        flood_group: has_leaf(iface, "flood-group"),
115        link_protection: present("link-protection"),
116        node_link_protection: present("node-link-protection"),
117        no_adjacency_holddown: has_leaf(iface, "no-adjacency-holddown"),
118        no_eligible_backup: has_leaf(iface, "no-eligible-backup"),
119        no_eligible_remote_backup: has_leaf(iface, "no-eligible-remote-backup"),
120        no_ipv4_multicast: has_leaf(iface, "no-ipv4-multicast"),
121        no_ipv6_multicast: has_leaf(iface, "no-ipv6-multicast"),
122        no_ipv6_unicast: has_leaf(iface, "no-ipv6-unicast"),
123        no_unicast_topology: has_leaf(iface, "no-unicast-topology"),
124        no_advertise_adjacency_segment: has_leaf(iface, "no-advertise-adjacency-segment"),
125    }
126}
127
128#[cfg(test)]
129mod tests {
130    use crate::protocols::isis::isis;
131    use asterust::config::juniper;
132
133    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
134    const CONFIG: &str = r#"
135protocols {
136    isis {
137        interface ge-0/0/0.0 {
138            point-to-point;
139            lsp-interval 50;
140            csnp-interval 5;
141            hello-padding adaptive;
142            max-hello-size 1400;
143            mesh-group blocked;
144            srlg [ SRLG-A ];
145            srlg SRLG-B;
146            delay-metric 1000;
147            strict-dual-isis holddown 30;
148            checksum;
149            link-protection;
150            no-eligible-backup;
151            no-ipv6-unicast;
152            ldp-synchronization {
153                hold-time 60;
154            }
155        }
156        interface lo0.0 {
157            passive {
158                remote-node-id 192.0.2.9;
159                remote-node-iso 49.0001.0000.0000.0009;
160            }
161        }
162        interface ge-0/0/1.0 {
163            disable;
164            csnp-interval disable;
165            ldp-synchronization {
166                disable;
167            }
168        }
169        interface all;
170    }
171}
172"#;
173
174    #[test]
175    fn reads_the_timers_and_flags() {
176        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
177        let iface = &isis.interfaces[0];
178        assert!(iface.point_to_point);
179        assert_eq!(iface.lsp_interval.as_deref(), Some("50"));
180        assert_eq!(iface.csnp_interval.as_deref(), Some("5"));
181        assert_eq!(iface.hello_padding.as_deref(), Some("adaptive"));
182        assert_eq!(iface.max_hello_size.as_deref(), Some("1400"));
183        assert_eq!(iface.mesh_group.as_deref(), Some("blocked"));
184        assert_eq!(iface.delay_metric.as_deref(), Some("1000"));
185        assert!(iface.strict_dual_isis);
186        assert_eq!(iface.strict_dual_isis_holddown.as_deref(), Some("30"));
187        assert!(iface.checksum);
188        assert!(iface.link_protection);
189        assert!(iface.no_eligible_backup);
190        assert!(iface.no_ipv6_unicast);
191        assert!(!iface.node_link_protection);
192        assert_eq!(iface.ldp_synchronization_hold_time.as_deref(), Some("60"));
193        assert!(!iface.ldp_synchronization_disable);
194    }
195
196    #[test]
197    fn reads_the_passive_block() {
198        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
199        let iface = &isis.interfaces[1];
200        assert!(iface.passive);
201        assert_eq!(iface.passive_remote_node_id.as_deref(), Some("192.0.2.9"));
202        assert_eq!(iface.passive_remote_node_iso.as_deref(), Some("49.0001.0000.0000.0009"));
203    }
204
205    #[test]
206    fn reads_disabled_interfaces_and_all() {
207        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
208        let disabled = &isis.interfaces[2];
209        assert!(disabled.disable);
210        assert_eq!(disabled.csnp_interval.as_deref(), Some("disable"));
211        assert!(disabled.ldp_synchronization_disable);
212        let all = &isis.interfaces[3];
213        assert_eq!(all.name, "all");
214        assert!(!all.strict_dual_isis);
215        assert_eq!(all.bfd_liveness_detection, None);
216        assert!(all.levels.is_empty());
217    }
218
219    #[test]
220    fn reads_the_srlg_entries() {
221        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
222        assert_eq!(isis.interfaces[0].srlg, ["SRLG-A", "SRLG-B"]);
223        assert!(isis.interfaces[1].srlg.is_empty());
224    }
225}