asterust_junos/protocols/isis/
source_packet_routing.rs1use super::srv6::{parse_srv6, IsisSrv6};
12use crate::{args_of, child_block, has_leaf, list_values, statement_words, value_after};
13use asterust::config::ConfigLine;
14
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
18#[non_exhaustive]
19pub struct IsisSourcePacketRouting {
20 pub disable: bool,
21 pub explicit_null: bool,
22 pub no_strict_spf: bool,
23 pub no_binding_sid_leaking: bool,
24 pub use_flex_algorithm_metric_always: bool,
25 pub strict_asla_based_flex_algorithm: bool,
26 pub ultimate_hop_popping: bool,
27 pub node_segment_ipv4_index: Option<String>,
29 pub node_segment_ipv6_index: Option<String>,
30 pub node_segment_index_range: Option<String>,
31 pub srgb_start_label: Option<String>,
33 pub srgb_index_range: Option<String>,
34 pub adjacency_segment_hold_time: Option<String>,
36 pub flex_algorithms: Vec<String>,
38 pub srv6: Option<IsisSrv6>,
39}
40
41pub(super) fn parse_source_packet_routing(isis: &ConfigLine) -> Option<IsisSourcePacketRouting> {
42 let spr = child_block(isis, "source-packet-routing")?;
43 let node = statement_words(spr, "node-segment");
44 let srgb = statement_words(spr, "srgb");
45 let adjacency = statement_words(spr, "adjacency-segment");
46 Some(IsisSourcePacketRouting {
47 disable: has_leaf(spr, "disable"),
48 explicit_null: has_leaf(spr, "explicit-null"),
49 no_strict_spf: has_leaf(spr, "no-strict-spf"),
50 no_binding_sid_leaking: has_leaf(spr, "no-binding-sid-leaking"),
51 use_flex_algorithm_metric_always: has_leaf(spr, "use-flex-algorithm-metric-always"),
52 strict_asla_based_flex_algorithm: has_leaf(spr, "strict-asla-based-flex-algorithm"),
53 ultimate_hop_popping: has_leaf(spr, "ultimate-hop-popping"),
54 node_segment_ipv4_index: node.as_ref().and_then(|words| value_after(words, "ipv4-index")),
55 node_segment_ipv6_index: node.as_ref().and_then(|words| value_after(words, "ipv6-index")),
56 node_segment_index_range: node.as_ref().and_then(|words| value_after(words, "index-range")),
57 srgb_start_label: srgb.as_ref().and_then(|words| value_after(words, "start-label")),
58 srgb_index_range: srgb.as_ref().and_then(|words| value_after(words, "index-range")),
59 adjacency_segment_hold_time: adjacency.and_then(|words| value_after(&words, "hold-time")),
60 flex_algorithms: args_of(spr, "flex-algorithm")
61 .into_iter()
62 .flat_map(list_values)
63 .collect(),
64 srv6: parse_srv6(spr),
65 })
66}
67
68#[cfg(test)]
69mod tests {
70 use crate::protocols::isis::isis;
71 use asterust::config::juniper;
72
73 const BLOCKS: &str = r#"
75protocols {
76 isis {
77 source-packet-routing {
78 explicit-null;
79 ultimate-hop-popping;
80 strict-asla-based-flex-algorithm;
81 adjacency-segment {
82 hold-time 200000;
83 }
84 node-segment {
85 ipv4-index 7;
86 ipv6-index 8;
87 index-range 1000;
88 }
89 srgb {
90 start-label 16000;
91 index-range 8000;
92 }
93 }
94 }
95}
96"#;
97
98 const ONE_LINE: &str = r#"
99protocols {
100 isis {
101 source-packet-routing {
102 disable;
103 node-segment ipv4-index 3;
104 srgb start-label 800000 index-range 80000;
105 }
106 }
107}
108"#;
109
110 #[test]
111 fn reads_the_block_forms() {
112 let spr = isis(&juniper::parse_braces(BLOCKS))
113 .unwrap()
114 .source_packet_routing
115 .unwrap();
116 assert!(spr.explicit_null);
117 assert!(spr.ultimate_hop_popping);
118 assert!(spr.strict_asla_based_flex_algorithm);
119 assert_eq!(spr.adjacency_segment_hold_time.as_deref(), Some("200000"));
120 assert_eq!(spr.node_segment_ipv4_index.as_deref(), Some("7"));
121 assert_eq!(spr.node_segment_ipv6_index.as_deref(), Some("8"));
122 assert_eq!(spr.node_segment_index_range.as_deref(), Some("1000"));
123 assert_eq!(spr.srgb_start_label.as_deref(), Some("16000"));
124 assert_eq!(spr.srgb_index_range.as_deref(), Some("8000"));
125 assert!(!spr.disable);
126 }
127
128 #[test]
129 fn reads_the_one_line_forms() {
130 let spr = isis(&juniper::parse_braces(ONE_LINE))
131 .unwrap()
132 .source_packet_routing
133 .unwrap();
134 assert!(spr.disable);
135 assert_eq!(spr.node_segment_ipv4_index.as_deref(), Some("3"));
136 assert_eq!(spr.node_segment_ipv6_index, None);
137 assert_eq!(spr.srgb_start_label.as_deref(), Some("800000"));
138 assert_eq!(spr.srgb_index_range.as_deref(), Some("80000"));
139 assert!(spr.flex_algorithms.is_empty());
140 }
141
142 const FLEX: &str = r#"
144protocols {
145 isis {
146 source-packet-routing {
147 flex-algorithm [ 128 129 ];
148 flex-algorithm 130;
149 }
150 }
151}
152"#;
153
154 #[test]
155 fn reads_the_flex_algorithm_participation() {
156 let spr = isis(&juniper::parse_braces(FLEX))
157 .unwrap()
158 .source_packet_routing
159 .unwrap();
160 assert_eq!(spr.flex_algorithms, ["128", "129", "130"]);
161 }
162}