Skip to main content

asterust_junos/interfaces/unit/
vlan_map.rs

1//! `input-vlan-map` and `output-vlan-map`
2//! `interfaces { <name> { unit <n> { input-vlan-map { ... } } } }`.
3//!
4//! # See also
5//!
6//! - [input-vlan-map](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/input-vlan-map-edit-interfaces-ge.html)
7//! - [output-vlan-map](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/output-vlan-map-edit-interfaces-ge.html)
8
9use crate::{statement_words, value_after};
10use asterust::config::ConfigLine;
11
12const OPERATIONS: [&str; 8] = [
13    "pop",
14    "pop-pop",
15    "pop-swap",
16    "push",
17    "push-push",
18    "swap",
19    "swap-push",
20    "swap-swap",
21];
22
23/// An `input-vlan-map` or `output-vlan-map`.
24#[derive(Clone, Debug, Default, PartialEq, Eq)]
25#[non_exhaustive]
26pub struct VlanMap {
27    /// `pop`, `pop-pop`, `pop-swap`, `push`, `push-push`, `swap`, `swap-push` or `swap-swap`.
28    pub operation: Option<String>,
29    pub tag_protocol_id: Option<String>,
30    pub vlan_id: Option<String>,
31    pub inner_tag_protocol_id: Option<String>,
32    pub inner_vlan_id: Option<String>,
33}
34
35/// The `keyword` map of `unit`, written as a block or on one line (`output-vlan-map pop;`).
36pub(super) fn parse_vlan_map(unit: &ConfigLine, keyword: &str) -> Option<VlanMap> {
37    let words = statement_words(unit, keyword)?;
38    Some(VlanMap {
39        operation: words.iter().find(|w| OPERATIONS.contains(w)).map(|w| w.to_string()),
40        tag_protocol_id: value_after(&words, "tag-protocol-id"),
41        vlan_id: value_after(&words, "vlan-id"),
42        inner_tag_protocol_id: value_after(&words, "inner-tag-protocol-id"),
43        inner_vlan_id: value_after(&words, "inner-vlan-id"),
44    })
45}