asterust-junos 0.5.13

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
//! `icmp`
//! `system { icmp { ... } }`.
//!
//! # See also
//!
//! - [icmp (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-icmp.html)

use crate::arg_of;
use asterust::config::ConfigLine;

/// The `system icmp` options.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Icmp {
    /// IPv4 source address of ICMP TTL expiry error messages.
    pub ttl_expired_source_address: Option<String>,
}

pub(super) fn parse_icmp(icmp: &ConfigLine) -> Icmp {
    Icmp {
        ttl_expired_source_address: arg_of(icmp, "ttl-expired-source-address").map(str::to_string),
    }
}

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

    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
    #[test]
    fn extracts_icmp_options() {
        let icmp = system(&juniper::parse_braces(
            "system {\n    icmp {\n        ttl-expired-source-address 192.0.2.1;\n    }\n}\n",
        ))
        .unwrap()
        .icmp
        .unwrap();
        assert_eq!(icmp.ttl_expired_source_address.as_deref(), Some("192.0.2.1"));
    }

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