asterust_junos/interfaces/unit/family/address/vrrp_group/
track.rs1use crate::{active_children, arg_of, args_of, named_children, value_after};
12use asterust::config::ConfigLine;
13
14#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct BandwidthThreshold {
19 pub bandwidth: String,
20 pub priority_cost: Option<String>,
21}
22
23#[derive(Clone, Debug, PartialEq, Eq)]
25#[non_exhaustive]
26pub struct TrackedInterface {
27 pub name: String,
28 pub priority_cost: Option<String>,
29 pub bandwidth_thresholds: Vec<BandwidthThreshold>,
30}
31
32#[derive(Clone, Debug, PartialEq, Eq)]
34#[non_exhaustive]
35pub struct TrackedRoute {
36 pub prefix: String,
37 pub routing_instance: Option<String>,
38 pub priority_cost: Option<String>,
39}
40
41#[derive(Clone, Debug, PartialEq, Eq)]
43#[non_exhaustive]
44pub struct VrrpTrack {
45 pub interfaces: Vec<TrackedInterface>,
46 pub routes: Vec<TrackedRoute>,
47 pub priority_hold_time: Option<String>,
48}
49
50pub(super) fn parse_track(track: &ConfigLine) -> VrrpTrack {
51 VrrpTrack {
52 interfaces: named_children(track, "interface")
53 .map(|(name, interface)| TrackedInterface {
54 name: name.to_string(),
55 priority_cost: arg_of(interface, "priority-cost").map(str::to_string),
56 bandwidth_thresholds: active_children(interface)
57 .filter_map(|c| c.arg("bandwidth-threshold"))
58 .map(parse_bandwidth_threshold)
59 .collect(),
60 })
61 .collect(),
62 routes: args_of(track, "route").into_iter().map(parse_route).collect(),
63 priority_hold_time: arg_of(track, "priority-hold-time").map(str::to_string),
64 }
65}
66
67fn parse_bandwidth_threshold(arg: &str) -> BandwidthThreshold {
69 let words: Vec<&str> = arg.split_whitespace().collect();
70 BandwidthThreshold {
71 bandwidth: words.first().unwrap_or(&"").to_string(),
72 priority_cost: value_after(&words, "priority-cost"),
73 }
74}
75
76fn parse_route(arg: &str) -> TrackedRoute {
78 let words: Vec<&str> = arg.split_whitespace().collect();
79 TrackedRoute {
80 prefix: words.first().unwrap_or(&"").to_string(),
81 routing_instance: value_after(&words, "routing-instance"),
82 priority_cost: value_after(&words, "priority-cost"),
83 }
84}