asterust_junos/firewall/
three_color_policer.rs1use crate::{active_children, arg_of, child_block, has_leaf};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, Default, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct ThreeColorRate {
15 pub color_aware: Option<bool>,
17 pub committed_information_rate: Option<String>,
18 pub committed_burst_size: Option<String>,
19 pub excess_burst_size: Option<String>,
21 pub peak_information_rate: Option<String>,
23 pub peak_burst_size: Option<String>,
25}
26
27#[derive(Clone, Debug, PartialEq, Eq)]
29#[non_exhaustive]
30pub struct ThreeColorPolicer {
31 pub name: String,
32 pub actions: Vec<String>,
34 pub filter_specific: bool,
35 pub logical_interface_policer: bool,
36 pub physical_interface_policer: bool,
37 pub shared_bandwidth_policer: bool,
38 pub single_rate: Option<ThreeColorRate>,
39 pub two_rate: Option<ThreeColorRate>,
40}
41
42pub(super) fn parse_three_color_policer(name: &str, line: &ConfigLine) -> ThreeColorPolicer {
43 ThreeColorPolicer {
44 name: name.to_string(),
45 actions: child_block(line, "action")
46 .map(|action| active_children(action).map(|c| c.text.clone()).collect())
47 .unwrap_or_default(),
48 filter_specific: has_leaf(line, "filter-specific"),
49 logical_interface_policer: has_leaf(line, "logical-interface-policer"),
50 physical_interface_policer: has_leaf(line, "physical-interface-policer"),
51 shared_bandwidth_policer: has_leaf(line, "shared-bandwidth-policer"),
52 single_rate: child_block(line, "single-rate").map(parse_rate),
53 two_rate: child_block(line, "two-rate").map(parse_rate),
54 }
55}
56
57fn parse_rate(rate: &ConfigLine) -> ThreeColorRate {
58 let field = |keyword: &str| arg_of(rate, keyword).map(str::to_string);
59 ThreeColorRate {
60 color_aware: if has_leaf(rate, "color-aware") {
61 Some(true)
62 } else if has_leaf(rate, "color-blind") {
63 Some(false)
64 } else {
65 None
66 },
67 committed_information_rate: field("committed-information-rate"),
68 committed_burst_size: field("committed-burst-size"),
69 excess_burst_size: field("excess-burst-size"),
70 peak_information_rate: field("peak-information-rate"),
71 peak_burst_size: field("peak-burst-size"),
72 }
73}