asterust_junos/protocols/bgp/
group.rs1use super::dynamic_neighbor::{parse_allow, parse_dynamic_neighbor, DynamicNeighbor};
9use super::neighbor::{parse_neighbor, BgpNeighbor};
10use super::peer_options::{parse_peer_options, BgpPeerOptions};
11use crate::{arg_of, args_of, first_word, list_values, named_children};
12use asterust::config::ConfigLine;
13
14#[derive(Clone, Debug, PartialEq, Eq)]
16#[non_exhaustive]
17pub struct BgpGroup {
18 pub name: String,
19 pub group_type: Option<String>,
21 pub description: Option<String>,
22 pub peer_as: Option<String>,
23 pub local_as: Option<String>,
24 pub local_address: Option<String>,
25 pub cluster: Option<String>,
27 pub families: Vec<String>,
29 pub import_policies: Vec<String>,
30 pub export_policies: Vec<String>,
31 pub neighbors: Vec<BgpNeighbor>,
32 pub allow: Vec<String>,
34 pub peer_as_list: Option<String>,
36 pub dynamic_neighbors: Vec<DynamicNeighbor>,
37 pub options: BgpPeerOptions,
38}
39
40pub(super) fn parse_group(name: &str, group: &ConfigLine) -> BgpGroup {
41 let policies =
42 |keyword: &str| -> Vec<String> { args_of(group, keyword).into_iter().flat_map(list_values).collect() };
43 BgpGroup {
44 name: name.to_string(),
45 group_type: arg_of(group, "type").map(str::to_string),
46 description: arg_of(group, "description").map(str::to_string),
47 peer_as: arg_of(group, "peer-as").and_then(first_word).map(str::to_string),
48 local_as: arg_of(group, "local-as").and_then(first_word).map(str::to_string),
49 local_address: arg_of(group, "local-address").map(str::to_string),
50 cluster: arg_of(group, "cluster").map(str::to_string),
51 families: named_children(group, "family").map(|(f, _)| f.to_string()).collect(),
52 import_policies: policies("import"),
53 export_policies: policies("export"),
54 neighbors: named_children(group, "neighbor")
55 .map(|(address, neighbor)| parse_neighbor(address, neighbor))
56 .collect(),
57 allow: parse_allow(group),
58 peer_as_list: arg_of(group, "peer-as-list").map(str::to_string),
59 dynamic_neighbors: named_children(group, "dynamic-neighbor")
60 .map(|(name, block)| parse_dynamic_neighbor(name, block))
61 .collect(),
62 options: parse_peer_options(group),
63 }
64}