asterust_junos/interfaces/aggregated_ether_options/
balancing.rs1use crate::{active_children, arg_of, child_block, has_leaf, named_children, value_after};
15use asterust::config::ConfigLine;
16
17#[derive(Clone, Debug, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct LoadBalance {
21 pub adaptive: bool,
23 pub adaptive_pps: bool,
25 pub adaptive_scan_interval: Option<String>,
26 pub adaptive_tolerance: Option<String>,
27 pub no_adaptive: bool,
28 pub per_packet: bool,
29 pub local_bias_percent: Option<String>,
31}
32
33#[derive(Clone, Debug, PartialEq, Eq)]
35#[non_exhaustive]
36pub struct Dlb {
37 pub assigned_flow: bool,
38 pub per_packet: bool,
39 pub flowlet_inactivity_interval: Option<String>,
41 pub ether_type: Option<String>,
43}
44
45#[derive(Clone, Debug, PartialEq, Eq)]
47#[non_exhaustive]
48pub struct LinkProtection {
49 pub disable: bool,
50 pub revertive: Option<bool>,
52}
53
54#[derive(Clone, Debug, PartialEq, Eq)]
56#[non_exhaustive]
57pub struct LinkProtectionSubGroup {
58 pub name: String,
59 pub role: Option<String>,
61}
62
63#[derive(Clone, Debug, PartialEq, Eq)]
65#[non_exhaustive]
66pub struct RebalancePeriodic {
67 pub time: Option<String>,
69 pub interval: Option<String>,
71}
72
73pub(in crate::interfaces) fn parse_load_balance(balance: &ConfigLine) -> LoadBalance {
74 let adaptive = child_block(balance, "adaptive");
75 LoadBalance {
76 adaptive: adaptive.is_some() || has_leaf(balance, "adaptive"),
77 adaptive_pps: adaptive.is_some_and(|a| has_leaf(a, "pps")),
78 adaptive_scan_interval: adaptive.and_then(|a| arg_of(a, "scan-interval")).map(str::to_string),
79 adaptive_tolerance: adaptive.and_then(|a| arg_of(a, "tolerance")).map(str::to_string),
80 no_adaptive: has_leaf(balance, "no-adaptive"),
81 per_packet: has_leaf(balance, "per-packet"),
82 local_bias_percent: arg_of(balance, "local-bias").and_then(|arg| {
83 value_after(&arg.split_whitespace().collect::<Vec<_>>(), "percent").or_else(|| Some(arg.to_string()))
84 }),
85 }
86}
87
88pub(super) fn parse_dlb(dlb: &ConfigLine) -> Dlb {
89 Dlb {
90 assigned_flow: has_leaf(dlb, "assigned-flow"),
91 per_packet: has_leaf(dlb, "per-packet"),
92 flowlet_inactivity_interval: arg_of(dlb, "flowlet").and_then(|arg| {
93 value_after(&arg.split_whitespace().collect::<Vec<_>>(), "inactivity-interval")
94 .or_else(|| arg.split_whitespace().next().map(str::to_string))
95 }),
96 ether_type: arg_of(dlb, "ether-type").map(str::to_string),
97 }
98}
99
100pub(in crate::interfaces) fn parse_link_protection(protection: &ConfigLine) -> LinkProtection {
101 LinkProtection {
102 disable: has_leaf(protection, "disable"),
103 revertive: if has_leaf(protection, "revertive") {
104 Some(true)
105 } else if has_leaf(protection, "non-revertive") {
106 Some(false)
107 } else {
108 None
109 },
110 }
111}
112
113pub(super) fn parse_link_protection_sub_groups(options: &ConfigLine) -> Vec<LinkProtectionSubGroup> {
114 named_children(options, "link-protection-sub-group")
115 .map(|(name, group)| LinkProtectionSubGroup {
116 name: name.to_string(),
117 role: ["primary", "backup"]
118 .iter()
119 .find(|role| has_leaf(group, role))
120 .map(|role| role.to_string()),
121 })
122 .collect()
123}
124
125pub(in crate::interfaces) fn parse_rebalance_periodic(periodic: &ConfigLine) -> RebalancePeriodic {
126 let words: Vec<&str> = periodic
128 .text
129 .split_whitespace()
130 .skip(1)
131 .chain(active_children(periodic).flat_map(|c| c.text.split_whitespace()))
132 .collect();
133 RebalancePeriodic {
134 time: value_after(&words, "time").or_else(|| value_after(&words, "start-time")),
135 interval: value_after(&words, "interval"),
136 }
137}