Skip to main content

asterust_junos/system/services/
flow_tap_dtcp.rs

1//! `flow-tap-dtcp`
2//! `system { services { flow-tap-dtcp { ... } } }`.
3//!
4//! # See also
5//!
6//! - [flow-tap-dtcp](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/flow-tap-dtcp-edit-system.html)
7
8use crate::{arg_of, child_block};
9use asterust::config::ConfigLine;
10
11/// The `ssh` block of `flow-tap-dtcp`.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct FlowTapDtcpSsh {
15    pub connection_limit: Option<String>,
16    pub rate_limit: Option<String>,
17}
18
19/// The `system services flow-tap-dtcp` configuration.
20#[derive(Clone, Debug, PartialEq, Eq)]
21#[non_exhaustive]
22pub struct FlowTapDtcp {
23    pub ssh: Option<FlowTapDtcpSsh>,
24}
25
26pub(super) fn parse_flow_tap_dtcp(dtcp: &ConfigLine) -> FlowTapDtcp {
27    FlowTapDtcp {
28        ssh: child_block(dtcp, "ssh").map(|ssh| FlowTapDtcpSsh {
29            connection_limit: arg_of(ssh, "connection-limit").map(str::to_string),
30            rate_limit: arg_of(ssh, "rate-limit").map(str::to_string),
31        }),
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use crate::system::system;
38    use asterust::config::juniper;
39
40    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
41    #[test]
42    fn extracts_flow_tap_dtcp_limits() {
43        let dtcp = system(&juniper::parse_braces(
44            "system {\n    services {\n        flow-tap-dtcp {\n            ssh {\n                connection-limit 50;\n                rate-limit 100;\n            }\n        }\n    }\n}\n",
45        ))
46        .unwrap()
47        .services
48        .unwrap()
49        .flow_tap_dtcp
50        .unwrap();
51        let ssh = dtcp.ssh.unwrap();
52        assert_eq!(ssh.connection_limit.as_deref(), Some("50"));
53        assert_eq!(ssh.rate_limit.as_deref(), Some("100"));
54    }
55
56    #[test]
57    fn bare_flow_tap_dtcp_ssh_has_no_limits() {
58        let dtcp = system(&juniper::parse_braces(
59            "system {\n    services {\n        flow-tap-dtcp {\n            ssh;\n        }\n    }\n}\n",
60        ))
61        .unwrap()
62        .services
63        .unwrap()
64        .flow_tap_dtcp
65        .unwrap();
66        let ssh = dtcp.ssh.unwrap();
67        assert_eq!(ssh.connection_limit, None);
68        assert_eq!(ssh.rate_limit, None);
69    }
70
71    #[test]
72    fn no_flow_tap_dtcp_is_none() {
73        let services = system(&juniper::parse_braces(
74            "system {\n    services {\n        ssh;\n    }\n}\n",
75        ))
76        .unwrap()
77        .services
78        .unwrap();
79        assert!(services.flow_tap_dtcp.is_none());
80    }
81}