[PATCH proxmox-perl-rs v2 3/7] sdn: fabrics: add BGP status endpoints

Hannes Laimer
2026-04-15T11:11:52Z

Expose BGP fabric status through the existing fabric status API.
Routes are fetched for both IPv4 and IPv6, and neighbor/interface
state is derived from BGP session info.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
pve-rs/src/bindings/sdn/fabrics.rs | 91 +++++++++++++++++++++++++
pve-rs/src/sdn/status.rs | 105 ++++++++++++++++++++++++++++-
2 files changed, 194 insertions(+), 2 deletions(-)

diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs
index 15dfee8..aa4324a 100644
--- a/pve-rs/src/bindings/sdn/fabrics.rs
+++ b/pve-rs/src/bindings/sdn/fabrics.rs
@@ -682,6 +682,35 @@ pub mod pve_rs_sdn_fabrics {

status::get_routes(fabric_id, config, ospf_routes, proxmox_sys::nodename())
}
+ FabricEntry::Bgp(_) => {
+ let bgp_ipv4_routes_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show ip route bgp json'"])
+ .output()?
+ .stdout,
+ )?;
+
+ let bgp_ipv6_routes_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show ipv6 route bgp json'"])
+ .output()?
+ .stdout,
+ )?;
+
+ let mut bgp_routes: proxmox_frr::de::Routes = if bgp_ipv4_routes_string.is_empty() {
+ proxmox_frr::de::Routes::default()
+ } else {
+ serde_json::from_str(&bgp_ipv4_routes_string)
+ .with_context(|| "error parsing bgp ipv4 routes")?
+ };
+ if !bgp_ipv6_routes_string.is_empty() {
+ let bgp_ipv6_routes: proxmox_frr::de::Routes =
+ serde_json::from_str(&bgp_ipv6_routes_string)
+ .with_context(|| "error parsing bgp ipv6 routes")?;
+ bgp_routes.0.extend(bgp_ipv6_routes.0);
+ }
+ status::get_routes(fabric_id, config, bgp_routes, proxmox_sys::nodename())
+ }
}
}

@@ -740,6 +769,23 @@ pub mod pve_rs_sdn_fabrics {
)
.map(|v| v.into())
}
+ FabricEntry::Bgp(_) => {
+ let bgp_neighbors_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show bgp neighbors json'"])
+ .output()?
+ .stdout,
+ )?;
+ let bgp_neighbors: std::collections::BTreeMap<String, status::BgpNeighborInfo> =
+ if bgp_neighbors_string.is_empty() {
+ std::collections::BTreeMap::new()
+ } else {
+ serde_json::from_str(&bgp_neighbors_string)
+ .with_context(|| "error parsing bgp neighbors")?
+ };
+
+ status::get_neighbors_bgp(fabric_id, bgp_neighbors).map(|v| v.into())
+ }
}
}

@@ -799,6 +845,23 @@ pub mod pve_rs_sdn_fabrics {
)
.map(|v| v.into())
}
+ FabricEntry::Bgp(_) => {
+ let bgp_neighbors_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show bgp neighbors json'"])
+ .output()?
+ .stdout,
+ )?;
+ let bgp_neighbors: std::collections::BTreeMap<String, status::BgpNeighborInfo> =
+ if bgp_neighbors_string.is_empty() {
+ std::collections::BTreeMap::new()
+ } else {
+ serde_json::from_str(&bgp_neighbors_string)
+ .with_context(|| "error parsing bgp neighbors")?
+ };
+
+ status::get_interfaces_bgp(fabric_id, bgp_neighbors).map(|v| v.into())
+ }
}
}

@@ -859,9 +922,37 @@ pub mod pve_rs_sdn_fabrics {
.with_context(|| "error parsing ospf routes")?
};

+ let bgp_ipv4_routes_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show ip route bgp json'"])
+ .output()?
+ .stdout,
+ )?;
+
+ let bgp_ipv6_routes_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show ipv6 route bgp json'"])
+ .output()?
+ .stdout,
+ )?;
+
+ let mut bgp_routes: proxmox_frr::de::Routes = if bgp_ipv4_routes_string.is_empty() {
+ proxmox_frr::de::Routes::default()
+ } else {
+ serde_json::from_str(&bgp_ipv4_routes_string)
+ .with_context(|| "error parsing bgp ipv4 routes")?
+ };
+ if !bgp_ipv6_routes_string.is_empty() {
+ let bgp_ipv6_routes: proxmox_frr::de::Routes =
+ serde_json::from_str(&bgp_ipv6_routes_string)
+ .with_context(|| "error parsing bgp ipv6 routes")?;
+ bgp_routes.0.extend(bgp_ipv6_routes.0);
+ }
+
let route_status = status::RoutesParsed {
openfabric: openfabric_routes,
ospf: ospf_routes,
+ bgp: bgp_routes,
};

status::get_status(config, route_status, proxmox_sys::nodename())
diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index e1e3362..1f373d0 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -6,6 +6,7 @@ use proxmox_network_types::mac_address::MacAddress;
use serde::{Deserialize, Serialize};

use proxmox_frr::de::{self};
+use proxmox_ve_config::sdn::fabric::section_config::protocol::bgp::BgpNode;
use proxmox_ve_config::sdn::fabric::section_config::protocol::ospf::{
OspfNodeProperties, OspfProperties,
};
@@ -80,12 +81,32 @@ mod openfabric {
}
}

-/// Common NeighborStatus that contains either OSPF or Openfabric neighbors
+mod bgp {
+ use serde::Serialize;
+
+ /// The status of a BGP neighbor.
+ #[derive(Debug, Serialize, PartialEq, Eq)]
+ pub struct NeighborStatus {
+ pub neighbor: String,
+ pub status: String,
+ pub uptime: String,
+ }
+
+ /// The status of a BGP fabric interface.
+ #[derive(Debug, Serialize, PartialEq, Eq)]
+ pub struct InterfaceStatus {
+ pub name: String,
+ pub state: super::InterfaceState,
+ }
+}
+
+/// Common NeighborStatus that contains either OSPF, Openfabric, or BGP neighbors
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum NeighborStatus {
Openfabric(Vec<openfabric::NeighborStatus>),
Ospf(Vec<ospf::NeighborStatus>),
+ Bgp(Vec<bgp::NeighborStatus>),
}

impl From<Vec<openfabric::NeighborStatus>> for NeighborStatus {
@@ -98,13 +119,19 @@ impl From<Vec<ospf::NeighborStatus>> for NeighborStatus {
NeighborStatus::Ospf(value)
}
}
+impl From<Vec<bgp::NeighborStatus>> for NeighborStatus {
+ fn from(value: Vec<bgp::NeighborStatus>) -> Self {
+ NeighborStatus::Bgp(value)
+ }
+}

-/// Common InterfaceStatus that contains either OSPF or Openfabric interfaces
+/// Common InterfaceStatus that contains either OSPF, Openfabric, or BGP interfaces
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum InterfaceStatus {
Openfabric(Vec<openfabric::InterfaceStatus>),
Ospf(Vec<ospf::InterfaceStatus>),
+ Bgp(Vec<bgp::InterfaceStatus>),
}

impl From<Vec<openfabric::InterfaceStatus>> for InterfaceStatus {
@@ -117,6 +144,11 @@ impl From<Vec<ospf::InterfaceStatus>> for InterfaceStatus {
InterfaceStatus::Ospf(value)
}
}
+impl From<Vec<bgp::InterfaceStatus>> for InterfaceStatus {
+ fn from(value: Vec<bgp::InterfaceStatus>) -> Self {
+ InterfaceStatus::Bgp(value)
+ }
+}

/// The status of a route.
///
@@ -135,6 +167,8 @@ pub enum Protocol {
Openfabric,
/// OSPF
Ospf,
+ /// BGP
+ Bgp,
}

/// The status of a fabric.
@@ -173,6 +207,8 @@ pub struct RoutesParsed {
pub openfabric: de::Routes,
/// All ospf routes in FRR
pub ospf: de::Routes,
+ /// All bgp routes in FRR
+ pub bgp: de::Routes,
}

/// Config used to parse the fabric part of the running-config
@@ -217,6 +253,10 @@ pub fn get_routes(
.interfaces()
.map(|i| i.name().as_str())
.collect(),
+ ConfigNode::Bgp(n) => match n.properties() {
+ BgpNode::Internal(props) => props.interfaces().map(|i| i.name().as_str()).collect(),
+ BgpNode::External(_) => HashSet::new(),
+ },
};

let dummy_interface = format!("dummy_{}", fabric_id.as_str());
@@ -408,6 +448,62 @@ pub fn get_interfaces_ospf(
Ok(stats)
}

+/// Convert the `show bgp neighbors json` output into a list of [`bgp::NeighborStatus`].
+///
+/// BGP neighbors are filtered by the fabric's peer-group name (which matches the fabric ID).
+pub fn get_neighbors_bgp(
+ fabric_id: FabricId,
+ neighbors: BTreeMap<String, BgpNeighborInfo>,
+) -> Result<Vec<bgp::NeighborStatus>, anyhow::Error> {
+ let mut stats = Vec::new();
+
+ for (peer_name, info) in &neighbors {
+ if info.peer_group.as_deref() == Some(fabric_id.as_str()) {
+ stats.push(bgp::NeighborStatus {
+ neighbor: peer_name.clone(),
+ status: info.bgp_state.clone(),
+ uptime: info.bgp_timer_up_string.clone().unwrap_or_default(),
+ });
+ }
+ }
+
+ Ok(stats)
+}
+
+/// Convert the `show bgp neighbors json` output into a list of [`bgp::InterfaceStatus`].
+///
+/// For BGP unnumbered, each interface peer maps to a fabric interface.
+pub fn get_interfaces_bgp(
+ fabric_id: FabricId,
+ neighbors: BTreeMap<String, BgpNeighborInfo>,
+) -> Result<Vec<bgp::InterfaceStatus>, anyhow::Error> {
+ let mut stats = Vec::new();
+
+ for (peer_name, info) in &neighbors {
+ if info.peer_group.as_deref() == Some(fabric_id.as_str()) {
+ stats.push(bgp::InterfaceStatus {
+ name: peer_name.clone(),
+ state: if info.bgp_state == "Established" {
+ InterfaceState::Up
+ } else {
+ InterfaceState::Down
+ },
+ });
+ }
+ }
+
+ Ok(stats)
+}
+
+/// Minimal BGP neighbor info from `show bgp neighbors json`
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BgpNeighborInfo {
+ pub bgp_state: String,
+ pub peer_group: Option<String>,
+ pub bgp_timer_up_string: Option<String>,
+}
+
/// Get the status for each fabric using the parsed routes from frr
///
/// Using the parsed routes we get from frr, filter and map them to a HashMap mapping every
@@ -429,6 +525,7 @@ pub fn get_status(
let (current_protocol, all_routes) = match &node {
ConfigNode::Openfabric(_) => (Protocol::Openfabric, &routes.openfabric.0),
ConfigNode::Ospf(_) => (Protocol::Ospf, &routes.ospf.0),
+ ConfigNode::Bgp(_) => (Protocol::Bgp, &routes.bgp.0),
};

// get interfaces
@@ -443,6 +540,10 @@ pub fn get_status(
.interfaces()
.map(|i| i.name().as_str())
.collect(),
+ ConfigNode::Bgp(n) => match n.properties() {
+ BgpNode::Internal(props) => props.interfaces().map(|i| i.name().as_str()).collect(),
+ BgpNode::External(_) => HashSet::new(),
+ },
};

// determine status by checking if any routes exist for our interfaces
--
2.47.3