Skip to main content

asterust_junos/protocols/bgp/family/
entropy_label.rs

1//! `entropy-label`
2//! `protocols { bgp { group <name> { family inet { labeled-unicast { entropy-label { ... } } } } } }`.
3//!
4//! # See also
5//!
6//! - [entropy-label (protocols bgp)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/entropy-label-edit-protocols-bgp-family-inet-labeled-unicast.html)
7//! - [Load Balancing for a BGP Session](https://networkingdocs.hpe.com/documentation/us/en/software/junos/bgp/topics/topic-map/load-balancing-bgp-session.html)
8
9use crate::{args_of, child_block, has_leaf, list_values};
10use asterust::config::ConfigLine;
11
12/// The `entropy-label` statement of `family inet labeled-unicast`.
13#[derive(Clone, Debug, Default, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct EntropyLabel {
16    pub elc_v2_compatible: bool,
17    pub no_next_hop_validation: bool,
18    /// Policies selecting the LSPs that use an entropy label.
19    pub import: Vec<String>,
20}
21
22pub(super) fn parse_entropy_label(node: &ConfigLine) -> Option<EntropyLabel> {
23    let label = child_block(node, "entropy-label")?;
24    Some(EntropyLabel {
25        elc_v2_compatible: has_leaf(label, "elc-v2-compatible"),
26        no_next_hop_validation: has_leaf(label, "no-next-hop-validation"),
27        import: args_of(label, "import").into_iter().flat_map(list_values).collect(),
28    })
29}
30
31#[cfg(test)]
32mod tests {
33    use crate::protocols::bgp::bgp;
34    use asterust::config::juniper;
35
36    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
37    const CONFIG: &str = r#"
38protocols {
39    bgp {
40        group LU {
41            family inet {
42                labeled-unicast {
43                    entropy-label {
44                        elc-v2-compatible;
45                        import [ ENTROPY-A ENTROPY-B ];
46                    }
47                }
48                unicast {
49                    extended-nexthop;
50                }
51            }
52        }
53    }
54}
55"#;
56
57    #[test]
58    fn reads_the_entropy_label_options() {
59        let bgp = bgp(&juniper::parse_braces(CONFIG)).unwrap();
60        let label = bgp.groups[0].options.address_families[0]
61            .entropy_label
62            .as_ref()
63            .unwrap();
64        assert!(label.elc_v2_compatible);
65        assert!(!label.no_next_hop_validation);
66        assert_eq!(label.import, ["ENTROPY-A", "ENTROPY-B"]);
67    }
68
69    #[test]
70    fn reads_extended_nexthop() {
71        let bgp = bgp(&juniper::parse_braces(CONFIG)).unwrap();
72        let families = &bgp.groups[0].options.address_families;
73        assert!(families[1].extended_nexthop);
74        assert!(!families[0].extended_nexthop);
75        assert_eq!(families[1].entropy_label, None);
76    }
77}