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