asterust-junos 0.5.9

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `arp`
//! `system { arp { ... } }`.
//!
//! # See also
//!
//! - [purging](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/purging-edit-system-arp.html)
//! - [non-subscriber-no-reply](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/non-subscriber-no-reply-edit-system-arp.html)
//! - [proactive-arp-detection](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-arp-proactive-arp-detection.html)

use crate::has_leaf;
use asterust::config::ConfigLine;

/// The `system arp` options.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Arp {
    /// Purge obsolete ARP entries when an interface or link goes offline.
    pub purging: bool,
    /// Drop ARP requests from non-subscribers when a user route is added for a subscriber.
    pub non_subscriber_no_reply: bool,
    pub proactive_arp_detection: bool,
}

pub(super) fn parse_arp(arp: &ConfigLine) -> Arp {
    Arp {
        purging: has_leaf(arp, "purging"),
        non_subscriber_no_reply: has_leaf(arp, "non-subscriber-no-reply"),
        proactive_arp_detection: has_leaf(arp, "proactive-arp-detection"),
    }
}

#[cfg(test)]
mod tests {
    use crate::system::system;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[test]
    fn extracts_arp_options() {
        let arp = system(&juniper::parse_braces(
            "system {\n    arp {\n        purging;\n        non-subscriber-no-reply;\n        proactive-arp-detection;\n    }\n}\n",
        ))
        .unwrap()
        .arp
        .unwrap();
        assert!(arp.purging);
        assert!(arp.non_subscriber_no_reply);
        assert!(arp.proactive_arp_detection);
    }

    #[test]
    fn arp_options_default_to_off() {
        let arp = system(&juniper::parse_braces(
            "system {\n    arp {\n        purging;\n    }\n}\n",
        ))
        .unwrap()
        .arp
        .unwrap();
        assert!(!arp.non_subscriber_no_reply);
        assert!(!arp.proactive_arp_detection);
    }

    #[test]
    fn no_arp_is_none() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.arp.is_none());
    }
}