Skip to content

Commit 7db2e9d

Browse files
committed
feat(status): Move BMP into separate config file
Signed-off-by: Sergey Matov <[email protected]>
1 parent 21b3688 commit 7db2e9d

File tree

4 files changed

+158
-9
lines changed

4 files changed

+158
-9
lines changed

config/src/internal/routing/bmp.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Open Network Fabric Authors
3+
4+
//! Dataplane configuration model: BMP (BGP Monitoring Protocol)
5+
6+
#![allow(unused)]
7+
8+
use std::net::IpAddr;
9+
10+
#[derive(Clone, Debug)]
11+
pub enum BmpSource {
12+
Address(IpAddr),
13+
Interface(String),
14+
}
15+
16+
#[derive(Clone, Debug)]
17+
pub struct BmpOptions {
18+
/// Name for `bmp targets <name>`
19+
pub target_name: String,
20+
/// Collector host/IP in `bmp connect`
21+
pub connect_host: String,
22+
/// Collector TCP port
23+
pub port: u16,
24+
/// Optional local source (address or interface)
25+
pub source: Option<BmpSource>,
26+
/// Optional reconnect backoff (ms)
27+
pub min_retry_ms: Option<u64>,
28+
pub max_retry_ms: Option<u64>,
29+
/// `bmp stats interval` (ms)
30+
pub stats_interval_ms: u64,
31+
/// Monitoring toggles
32+
pub monitor_ipv4_pre: bool,
33+
pub monitor_ipv4_post: bool,
34+
pub monitor_ipv6_pre: bool,
35+
pub monitor_ipv6_post: bool,
36+
37+
/// VRFs/views to import into the default BMP instance:
38+
/// renders as multiple `bmp import-vrf-view <vrf>`
39+
pub import_vrf_views: Vec<String>,
40+
}
41+
42+
impl Default for BmpOptions {
43+
fn default() -> Self {
44+
Self {
45+
target_name: "bmp1".to_string(),
46+
connect_host: "127.0.0.1".to_string(),
47+
port: 5000,
48+
source: None,
49+
min_retry_ms: Some(1_000),
50+
max_retry_ms: Some(20_000),
51+
stats_interval_ms: 60_000,
52+
monitor_ipv4_pre: true,
53+
monitor_ipv4_post: true,
54+
monitor_ipv6_pre: false,
55+
monitor_ipv6_post: false,
56+
import_vrf_views: Vec::new(),
57+
}
58+
}
59+
}
60+
61+
impl BmpOptions {
62+
#[must_use]
63+
pub fn new<T: Into<String>, H: Into<String>>(
64+
target_name: T,
65+
connect_host: H,
66+
port: u16,
67+
) -> Self {
68+
Self {
69+
target_name: target_name.into(),
70+
connect_host: connect_host.into(),
71+
port,
72+
..Default::default()
73+
}
74+
}
75+
76+
#[must_use]
77+
pub fn set_source_addr(mut self, ip: IpAddr) -> Self {
78+
self.source = Some(BmpSource::Address(ip));
79+
self
80+
}
81+
82+
#[must_use]
83+
pub fn set_source_interface<S: Into<String>>(mut self, ifname: S) -> Self {
84+
self.source = Some(BmpSource::Interface(ifname.into()));
85+
self
86+
}
87+
88+
#[must_use]
89+
pub fn set_retry_ms(mut self, min_ms: u64, max_ms: u64) -> Self {
90+
self.min_retry_ms = Some(min_ms);
91+
self.max_retry_ms = Some(max_ms);
92+
self
93+
}
94+
95+
#[must_use]
96+
pub fn set_stats_interval_ms(mut self, ms: u64) -> Self {
97+
self.stats_interval_ms = ms;
98+
self
99+
}
100+
101+
#[must_use]
102+
pub fn monitor_ipv4(mut self, pre: bool, post: bool) -> Self {
103+
self.monitor_ipv4_pre = pre;
104+
self.monitor_ipv4_post = post;
105+
self
106+
}
107+
108+
#[must_use]
109+
pub fn monitor_ipv6(mut self, pre: bool, post: bool) -> Self {
110+
self.monitor_ipv6_pre = pre;
111+
self.monitor_ipv6_post = post;
112+
self
113+
}
114+
115+
#[must_use]
116+
pub fn add_import_vrf_view<S: Into<String>>(mut self, vrf: S) -> Self {
117+
self.import_vrf_views.push(vrf.into());
118+
self
119+
}
120+
121+
pub fn push_import_vrf_view<S: Into<String>>(&mut self, vrf: S) {
122+
self.import_vrf_views.push(vrf.into());
123+
}
124+
125+
#[must_use]
126+
pub fn set_import_vrf_views<I, S>(mut self, vrfs: I) -> Self
127+
where
128+
I: IntoIterator<Item = S>,
129+
S: Into<String>,
130+
{
131+
self.import_vrf_views = vrfs.into_iter().map(Into::into).collect();
132+
self
133+
}
134+
}

mgmt/src/tests/mgmt.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ pub mod test {
367367
/* build a gw config from a sample external config */
368368
let config = GwConfig::new(external);
369369

370+
let dp_status_r: Arc<RwLock<DataplaneStatus>> =
371+
Arc::new(RwLock::new(DataplaneStatus::new()));
372+
370373
/* build router config */
371374
let router_params = RouterParamsBuilder::default()
372375
.cpi_sock_path("/tmp/cpi.sock")
373376
.cli_sock_path("/tmp/cli.sock")
374377
.frr_agent_path("/tmp/frr-agent.sock")
378+
.dp_status(dp_status_r.clone())
375379
.build()
376380
.expect("Should succeed due to defaults");
377381

@@ -401,9 +405,6 @@ pub mod test {
401405
/* VPC stats store (Arc) */
402406
let vpc_stats_store = VpcStatsStore::new();
403407

404-
let dp_status_r: Arc<RwLock<DataplaneStatus>> =
405-
Arc::new(RwLock::new(DataplaneStatus::new()));
406-
407408
/* build configuration of mgmt config processor */
408409
let processor_config = ConfigProcessorParams {
409410
router_ctl,

routing/src/frr/renderer/bgp.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use config::internal::routing::bgp::Redistribute;
1212
use config::internal::routing::bgp::VrfImports;
1313
use config::internal::routing::bgp::{AfIpv4Ucast, AfIpv6Ucast, AfL2vpnEvpn};
1414
use config::internal::routing::bgp::{BgpNeighCapabilities, Protocol};
15-
use config::internal::routing::bgp::{BmpOptions, BmpSource};
15+
use config::internal::routing::bmp::{BmpOptions, BmpSource};
1616

1717
/* impl Display */
1818
impl Rendered for BgpNeighType {
@@ -551,6 +551,7 @@ pub mod tests {
551551
AfL2vpnEvpn, BgpConfig, BgpNeighbor, NeighSendCommunities, Protocol, Redistribute,
552552
VrfImports,
553553
};
554+
use config::internal::routing::bmp::{BmpOptions, BmpSource};
554555
use lpm::prefix::Prefix;
555556
use std::net::{IpAddr, Ipv4Addr};
556557
use std::str::FromStr;
@@ -573,6 +574,19 @@ pub mod tests {
573574

574575
bgp.set_bgp_options(options);
575576

577+
let bmp = BmpOptions::new("bmp1", "127.0.0.1", 5000)
578+
.set_retry_ms(1_000, 20_000)
579+
.set_stats_interval_ms(60_000)
580+
.monitor_ipv4(true, true)
581+
.monitor_ipv6(false, false);
582+
let bmp = BmpOptions {
583+
source: Some(BmpSource::Interface("lo".to_string())),
584+
..bmp
585+
}
586+
.add_import_vrf_view("VPC-2")
587+
.add_import_vrf_view("VPC-3");
588+
bgp.set_bmp_options(bmp);
589+
576590
let n1 = BgpNeighbor::new_host(IpAddr::from_str("7.0.0.3").expect("Bad address"))
577591
.set_remote_as(65001)
578592
.set_description("A neighbor that does not belong to a peer group")

routing/src/frr/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@ pub mod tests {
124124
use super::fake_frr_agent::*;
125125
use crate::config::RouterConfig;
126126
use crate::{Router, RouterParamsBuilder};
127-
use std::time::Duration;
128-
use tracing_test::traced_test;
129-
127+
use concurrency::sync::{Arc, RwLock};
130128
use config::internal::status::DataplaneStatus;
129+
use std::time::Duration;
131130
use tokio::sync::watch;
131+
use tracing_test::traced_test;
132132

133133
#[traced_test]
134134
#[tokio::test]
135135
async fn test_fake_frr_agent() {
136-
let (_dp_status_tx, dp_status_rx) = watch::channel(DataplaneStatus::default());
136+
let dp_status: Arc<RwLock<DataplaneStatus>> = Arc::new(RwLock::new(DataplaneStatus::new()));
137137

138138
/* set router params */
139139
let router_params = RouterParamsBuilder::default()
140140
.cpi_sock_path("/tmp/cpi.sock")
141141
.cli_sock_path("/tmp/cli.sock")
142142
.frr_agent_path("/tmp/frr-agent.sock")
143-
.dp_status(dp_status_rx)
143+
.dp_status(dp_status)
144144
.build()
145145
.expect("Should succeed due to defaults");
146146

0 commit comments

Comments
 (0)