Skip to main content

asterust_junos/protocols/isis/
mod.rs

1//! `isis`
2//! `protocols { isis { ... } }`.
3//!
4//! # See also
5//!
6//! - [isis](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/isis-edit-protocols.html)
7//! - [interface (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-protocols-isis.html)
8//! - [reference-bandwidth (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/reference-bandwidth-edit-protocols-isis.html)
9//! - [export (IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/export-edit-protocols-isis.html)
10//! - [import (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/import-edit-protocols-isis.html)
11//! - [lsp-lifetime](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/lsp-lifetime-edit-protocols-isis.html)
12//! - [max-areas](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/max-areas-edit-protocols-isis.html)
13//! - [max-snp-size](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/max-snp-size-edit-protocols-isis.html)
14//! - [no-ipv4-routing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-ipv4-routing-edit-protocols-isis.html)
15//! - [no-ipv6-routing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-ipv6-routing-edit-protocols-isis.html)
16//! - [loose-authentication-check](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/loose-authentication-check-edit-protocols-isis.html)
17//! - [ignore-attached-bit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ignore-attached-bit-edit-protocols-isis.html)
18//! - [rib-group (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/rib-group-edit-protocols-isis.html)
19//! - [clns-routing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/clns-routing-edit-protocols-isis.html)
20//! - [clns-updown-compatibility](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/clns-updown-compatibility-edit-protocols-isis.html)
21//! - [rfc7775-compliance](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/rfc7775-compliance-edit-protocols-isis.html)
22//! - [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)
23//! - [disable (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/en_US/junos12.3/topics/reference/configuration-statement/disable-edit-protocols-isis.html), from the Junos 12.3 archive
24//! - [traceoptions (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/traceoptions-edit-protocols-isis.html)
25//! - [traffic-engineering (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/traffic-engineering-edit-protocols-isis.html)
26//! - [backup-spf-options (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/backup-spf-options-edit-protocols-isis.html)
27//! - [topologies (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/topologies-edit-protocols-isis.html)
28//! - [no-external-export](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/protocols-isis-no-external-export-protocol.html)
29//! - [source-packet-routing (Protocols IS-IS)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/source-packet-routing-edit-protocols-isis.html)
30
31mod backup_spf_options;
32mod dynamic_overload;
33mod graceful_restart;
34mod interface;
35mod level;
36mod no_external_export;
37mod overload;
38mod source_packet_routing;
39mod spf_options;
40mod srv6;
41mod topologies;
42mod traffic_engineering;
43
44pub use backup_spf_options::IsisBackupSpfOptions;
45pub use dynamic_overload::IsisDynamicOverload;
46pub use graceful_restart::IsisGracefulRestart;
47pub use interface::{IsisBfd, IsisInterface, IsisInterfaceLevel};
48pub use level::IsisLevel;
49pub use overload::IsisOverload;
50pub use source_packet_routing::IsisSourcePacketRouting;
51pub use spf_options::IsisSpfOptions;
52pub use srv6::{IsisSrv6, IsisSrv6AdjacencySegment, IsisSrv6Locator};
53pub use topologies::IsisTopologies;
54pub use traffic_engineering::{IsisTeFamily, IsisTrafficEngineering};
55
56use super::traceoptions::{parse_traceoptions, Traceoptions};
57use crate::{
58    arg_of, args_of, child_block, has_leaf, list_values, named_children, statement_words, top_level, value_after,
59};
60use asterust::config::Config;
61use backup_spf_options::parse_backup_spf_options;
62use dynamic_overload::parse_dynamic_overload;
63use graceful_restart::parse_graceful_restart;
64use interface::parse_interface;
65use level::parse_level;
66use no_external_export::parse_no_external_export;
67use overload::parse_overload;
68use source_packet_routing::parse_source_packet_routing;
69use spf_options::parse_spf_options;
70use topologies::parse_topologies;
71use traffic_engineering::parse_traffic_engineering;
72
73/// The `protocols isis` configuration. The NET lives on the loopback's `family iso` address, see
74/// [`crate::interfaces::InterfaceUnit::iso_addresses`].
75#[derive(Clone, Debug, PartialEq, Eq)]
76#[non_exhaustive]
77pub struct Isis {
78    pub interfaces: Vec<IsisInterface>,
79    /// The `level <1|2>` entries directly under `isis`.
80    pub levels: Vec<IsisLevel>,
81    /// IS-IS is disabled.
82    pub disable: bool,
83    /// Bits per second as written.
84    pub reference_bandwidth: Option<String>,
85    pub export_policies: Vec<String>,
86    pub import_policies: Vec<String>,
87    /// Seconds.
88    pub lsp_lifetime: Option<String>,
89    pub max_areas: Option<String>,
90    pub max_lsp_size: Option<String>,
91    pub max_snp_size: Option<String>,
92    pub no_ipv4_routing: bool,
93    pub no_ipv6_routing: bool,
94    pub no_authentication_check: bool,
95    pub loose_authentication_check: bool,
96    pub ignore_attached_bit: bool,
97    pub clns_routing: bool,
98    pub clns_updown_compatibility: bool,
99    pub rfc7775_compliance: bool,
100    /// The routing table group for `inet`, from `rib-group { inet ...; }`.
101    pub rib_group_inet: Option<String>,
102    pub rib_group_inet6: Option<String>,
103    pub strict_dual_isis: bool,
104    /// Seconds.
105    pub strict_dual_isis_holddown: Option<String>,
106    pub overload: Option<IsisOverload>,
107    pub spf_options: Option<IsisSpfOptions>,
108    pub graceful_restart: Option<IsisGracefulRestart>,
109    pub traceoptions: Option<Traceoptions>,
110    pub traffic_engineering: Option<IsisTrafficEngineering>,
111    pub backup_spf_options: Option<IsisBackupSpfOptions>,
112    pub topologies: Option<IsisTopologies>,
113    pub dynamic_overload: Option<IsisDynamicOverload>,
114    /// The protocols of `no-external-export`, whose routes are not exported into IS-IS.
115    pub no_external_export: Vec<String>,
116    pub source_packet_routing: Option<IsisSourcePacketRouting>,
117}
118
119/// Returns the `protocols isis` block, or `None` if IS-IS is not configured.
120///
121/// # Examples
122///
123/// ```
124/// use asterust::config::juniper;
125/// use asterust_junos::protocols::isis::isis;
126///
127/// let config = juniper::parse_braces("protocols {\n    isis {\n        interface ge-0/0/0.0 {\n            point-to-point;\n        }\n    }\n}\n");
128/// let isis = isis(&config).unwrap();
129/// assert_eq!(isis.interfaces[0].name, "ge-0/0/0.0");
130/// assert!(isis.interfaces[0].point_to_point);
131/// ```
132pub fn isis(config: &Config) -> Option<Isis> {
133    let isis = child_block(top_level(config, "protocols")?, "isis")?;
134    let policies =
135        |keyword: &str| -> Vec<String> { args_of(isis, keyword).into_iter().flat_map(list_values).collect() };
136    let rib_group = statement_words(isis, "rib-group");
137    let strict_dual_isis = statement_words(isis, "strict-dual-isis");
138    Some(Isis {
139        interfaces: named_children(isis, "interface")
140            .map(|(name, iface)| parse_interface(name, iface))
141            .collect(),
142        levels: named_children(isis, "level")
143            .map(|(arg, level)| parse_level(arg, level))
144            .collect(),
145        disable: has_leaf(isis, "disable"),
146        reference_bandwidth: arg_of(isis, "reference-bandwidth").map(str::to_string),
147        export_policies: policies("export"),
148        import_policies: policies("import"),
149        lsp_lifetime: arg_of(isis, "lsp-lifetime").map(str::to_string),
150        max_areas: arg_of(isis, "max-areas").map(str::to_string),
151        max_lsp_size: arg_of(isis, "max-lsp-size").map(str::to_string),
152        max_snp_size: arg_of(isis, "max-snp-size").map(str::to_string),
153        no_ipv4_routing: has_leaf(isis, "no-ipv4-routing"),
154        no_ipv6_routing: has_leaf(isis, "no-ipv6-routing"),
155        no_authentication_check: has_leaf(isis, "no-authentication-check"),
156        loose_authentication_check: has_leaf(isis, "loose-authentication-check"),
157        ignore_attached_bit: has_leaf(isis, "ignore-attached-bit"),
158        clns_routing: has_leaf(isis, "clns-routing"),
159        clns_updown_compatibility: has_leaf(isis, "clns-updown-compatibility"),
160        rfc7775_compliance: has_leaf(isis, "rfc7775-compliance"),
161        rib_group_inet: rib_group.as_ref().and_then(|words| value_after(words, "inet")),
162        rib_group_inet6: rib_group.as_ref().and_then(|words| value_after(words, "inet6")),
163        strict_dual_isis: strict_dual_isis.is_some(),
164        strict_dual_isis_holddown: strict_dual_isis.and_then(|words| value_after(&words, "holddown")),
165        overload: parse_overload(isis),
166        spf_options: parse_spf_options(isis),
167        graceful_restart: parse_graceful_restart(isis),
168        traceoptions: parse_traceoptions(isis),
169        traffic_engineering: parse_traffic_engineering(isis),
170        backup_spf_options: parse_backup_spf_options(isis),
171        topologies: parse_topologies(isis),
172        dynamic_overload: parse_dynamic_overload(isis),
173        no_external_export: parse_no_external_export(isis),
174        source_packet_routing: parse_source_packet_routing(isis),
175    })
176}
177
178#[cfg(test)]
179mod tests {
180    use super::*;
181    use asterust::config::juniper;
182
183    // Written from JunOS hierarchy knowledge, not adapted from documentation; see the README "Sources".
184    const CONFIG: &str = r#"
185protocols {
186    isis {
187        level 2 wide-metrics-only;
188        interface ge-0/0/0.0 {
189            point-to-point;
190            level 1 disable;
191        }
192        interface lo0.0 {
193            passive;
194        }
195        interface ge-0/0/1.0;
196    }
197}
198"#;
199
200    #[test]
201    fn extracts_interfaces() {
202        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
203        let names: Vec<_> = isis.interfaces.iter().map(|i| i.name.as_str()).collect();
204        assert_eq!(names, ["ge-0/0/0.0", "lo0.0", "ge-0/0/1.0"]);
205        assert!(isis.interfaces[0].point_to_point);
206        assert!(!isis.interfaces[0].passive);
207        assert!(isis.interfaces[1].passive);
208        assert!(!isis.interfaces[2].point_to_point);
209    }
210
211    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
212    const GLOBAL: &str = r#"
213protocols {
214    isis {
215        disable;
216        reference-bandwidth 100g;
217        export [ EXPORT-A EXPORT-B ];
218        import IMPORT-A;
219        lsp-lifetime 1500;
220        max-areas 5;
221        max-lsp-size 1492;
222        max-snp-size 1400;
223        no-ipv4-routing;
224        no-ipv6-routing;
225        no-authentication-check;
226        loose-authentication-check;
227        ignore-attached-bit;
228        clns-routing;
229        clns-updown-compatibility;
230        rfc7775-compliance;
231        rib-group {
232            inet RG-V4;
233            inet6 RG-V6;
234        }
235        strict-dual-isis {
236            holddown 30;
237        }
238    }
239}
240"#;
241
242    #[test]
243    fn reads_the_global_options() {
244        let isis = isis(&juniper::parse_braces(GLOBAL)).unwrap();
245        assert!(isis.disable);
246        assert_eq!(isis.reference_bandwidth.as_deref(), Some("100g"));
247        assert_eq!(isis.export_policies, ["EXPORT-A", "EXPORT-B"]);
248        assert_eq!(isis.import_policies, ["IMPORT-A"]);
249        assert_eq!(isis.lsp_lifetime.as_deref(), Some("1500"));
250        assert_eq!(isis.max_areas.as_deref(), Some("5"));
251        assert_eq!(isis.max_lsp_size.as_deref(), Some("1492"));
252        assert_eq!(isis.max_snp_size.as_deref(), Some("1400"));
253        assert!(isis.no_ipv4_routing);
254        assert!(isis.no_ipv6_routing);
255        assert!(isis.no_authentication_check);
256        assert!(isis.loose_authentication_check);
257        assert!(isis.ignore_attached_bit);
258        assert!(isis.clns_routing);
259        assert!(isis.clns_updown_compatibility);
260        assert!(isis.rfc7775_compliance);
261        assert_eq!(isis.rib_group_inet.as_deref(), Some("RG-V4"));
262        assert_eq!(isis.rib_group_inet6.as_deref(), Some("RG-V6"));
263        assert!(isis.strict_dual_isis);
264        assert_eq!(isis.strict_dual_isis_holddown.as_deref(), Some("30"));
265    }
266
267    #[test]
268    fn leaves_the_global_options_unset_when_absent() {
269        let isis = isis(&juniper::parse_braces(CONFIG)).unwrap();
270        assert!(!isis.disable);
271        assert_eq!(isis.reference_bandwidth, None);
272        assert!(isis.export_policies.is_empty());
273        assert_eq!(isis.rib_group_inet, None);
274        assert!(!isis.strict_dual_isis);
275        assert_eq!(isis.overload, None);
276        assert_eq!(isis.spf_options, None);
277        assert_eq!(isis.graceful_restart, None);
278    }
279
280    #[test]
281    fn no_isis_is_none() {
282        assert!(isis(&juniper::parse_braces("protocols {\n bgp {\n }\n}\n")).is_none());
283    }
284}