Skip to main content

asterust_junos/system/
icmp.rs

1//! `icmp`
2//! `system { icmp { ... } }`.
3//!
4//! # See also
5//!
6//! - [icmp (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-icmp.html)
7
8use crate::arg_of;
9use asterust::config::ConfigLine;
10
11/// The `system icmp` options.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct Icmp {
15    /// IPv4 source address of ICMP TTL expiry error messages.
16    pub ttl_expired_source_address: Option<String>,
17}
18
19pub(super) fn parse_icmp(icmp: &ConfigLine) -> Icmp {
20    Icmp {
21        ttl_expired_source_address: arg_of(icmp, "ttl-expired-source-address").map(str::to_string),
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use crate::system::system;
28    use asterust::config::juniper;
29
30    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
31    #[test]
32    fn extracts_icmp_options() {
33        let icmp = system(&juniper::parse_braces(
34            "system {\n    icmp {\n        ttl-expired-source-address 192.0.2.1;\n    }\n}\n",
35        ))
36        .unwrap()
37        .icmp
38        .unwrap();
39        assert_eq!(icmp.ttl_expired_source_address.as_deref(), Some("192.0.2.1"));
40    }
41
42    #[test]
43    fn no_icmp_is_none() {
44        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
45        assert!(system.icmp.is_none());
46    }
47}