Skip to main content

asterust_junos/interfaces/otn_options/
mod.rs

1//! `otn-options`
2//! `interfaces { <name> { otn-options { ... } } }`.
3//!
4//! # See also
5//!
6//! - [otn-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/otn-options-edit-interfaces.html)
7//! - [fec](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/fec-edit-interfaces-otn-options.html)
8//! - [tti](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tti-edit-interfaces-otn-options.html)
9//! - [bytes (otn-options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/bytes-edit-interfaces-otn-options.html)
10
11mod rate;
12mod signal_degrade;
13
14pub use rate::OtnRate;
15pub use signal_degrade::SignalDegrade;
16
17use crate::{active_children, arg_of, child_block, has_leaf, statement_words, toggle, value_after};
18use asterust::config::ConfigLine;
19use rate::parse_rate;
20use signal_degrade::parse_signal_degrade;
21
22/// The OTN settings of an interface. `odu-delay-management`, `odu-signal-degrade`,
23/// `preemptive-fast-reroute`, `tca`, `trigger` and the loopback statements are not extracted.
24#[derive(Clone, Debug, PartialEq, Eq)]
25#[non_exhaustive]
26pub struct OtnOptions {
27    /// e.g. `"gfec"`, `"efec"`, `"ufec"` or `"none"`.
28    pub fec: Option<String>,
29    /// From `bytes transmit-payload-type`.
30    pub transmit_payload_type: Option<String>,
31    /// Each `tti` statement as written, e.g. `"otu-sapi \"text\""`.
32    pub tti: Vec<String>,
33    pub rate: Option<OtnRate>,
34    pub signal_degrade: Option<SignalDegrade>,
35    pub transport_monitoring: bool,
36    /// `Some(true)` for `is-ma`, `Some(false)` for `no-is-ma`.
37    pub is_ma: Option<bool>,
38    /// `Some(true)` for `laser-enable`, `Some(false)` for `no-laser-enable`.
39    pub laser_enable: Option<bool>,
40    /// `Some(true)` for `prbs`, `Some(false)` for `no-prbs`.
41    pub prbs: Option<bool>,
42    pub odu_ttim_action_enable: Option<bool>,
43    pub otu_ttim_action_enable: Option<bool>,
44}
45
46pub(super) fn parse_otn_options(otn: &ConfigLine) -> OtnOptions {
47    OtnOptions {
48        fec: arg_of(otn, "fec").map(str::to_string),
49        transmit_payload_type: statement_words(otn, "bytes")
50            .and_then(|words| value_after(&words, "transmit-payload-type")),
51        tti: active_children(otn)
52            .filter_map(|c| c.arg("tti"))
53            .map(str::to_string)
54            .collect(),
55        rate: child_block(otn, "rate").map(parse_rate),
56        signal_degrade: child_block(otn, "signal-degrade").map(parse_signal_degrade),
57        transport_monitoring: has_leaf(otn, "transport-monitoring"),
58        is_ma: toggle(otn, "is-ma"),
59        laser_enable: toggle(otn, "laser-enable"),
60        prbs: toggle(otn, "prbs"),
61        odu_ttim_action_enable: toggle(otn, "odu-ttim-action-enable"),
62        otu_ttim_action_enable: toggle(otn, "otu-ttim-action-enable"),
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use crate::interfaces::interfaces;
69    use asterust::config::juniper;
70
71    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
72    #[test]
73    fn extracts_otn_options() {
74        let ifaces = interfaces(&juniper::parse_braces(
75            r#"
76interfaces {
77    et-1/0/0 {
78        otn-options {
79            fec gfec;
80            bytes {
81                transmit-payload-type 7;
82            }
83            tti otu-sapi "LAB1";
84            tti odu-dapi "LAB2";
85            transport-monitoring;
86            laser-enable;
87            no-prbs;
88            odu-ttim-action-enable;
89            rate {
90                otu4;
91                no-pass-through;
92            }
93            signal-degrade {
94                ber-threshold-signal-degrade 1.0E-5;
95                ber-threshold-clear 1.0E-6;
96                interval 100;
97            }
98        }
99    }
100}
101"#,
102        ));
103        let otn = ifaces[0].otn_options.as_ref().unwrap();
104        assert_eq!(otn.fec.as_deref(), Some("gfec"));
105        assert_eq!(otn.transmit_payload_type.as_deref(), Some("7"));
106        assert_eq!(otn.tti, ["otu-sapi \"LAB1\"", "odu-dapi \"LAB2\""]);
107        assert!(otn.transport_monitoring);
108        assert_eq!(otn.laser_enable, Some(true));
109        assert_eq!(otn.prbs, Some(false));
110        assert_eq!(otn.odu_ttim_action_enable, Some(true));
111        assert_eq!(otn.otu_ttim_action_enable, None);
112        assert_eq!(otn.is_ma, None);
113
114        let rate = otn.rate.as_ref().unwrap();
115        assert!(rate.otu4);
116        assert!(!rate.oc192);
117        assert_eq!(rate.pass_through, Some(false));
118        assert_eq!(rate.fixed_stuff_bytes, None);
119
120        let degrade = otn.signal_degrade.as_ref().unwrap();
121        assert_eq!(degrade.ber_threshold_signal_degrade.as_deref(), Some("1.0E-5"));
122        assert_eq!(degrade.ber_threshold_clear.as_deref(), Some("1.0E-6"));
123        assert_eq!(degrade.interval.as_deref(), Some("100"));
124    }
125
126    #[test]
127    fn bare_otn_options_have_no_settings() {
128        let ifaces = interfaces(&juniper::parse_braces(
129            "interfaces {\n    et-1/0/0 {\n        otn-options {\n            fec none;\n        }\n    }\n    et-1/0/1 {\n        disable;\n    }\n}\n",
130        ));
131        let otn = ifaces[0].otn_options.as_ref().unwrap();
132        assert_eq!(otn.fec.as_deref(), Some("none"));
133        assert!(otn.tti.is_empty());
134        assert!(otn.rate.is_none());
135        assert!(otn.signal_degrade.is_none());
136        assert!(!otn.transport_monitoring);
137        assert!(ifaces[1].otn_options.is_none());
138    }
139}