From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D8D031FF16B for ; Fri, 7 Nov 2025 15:32:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 701E213955; Fri, 7 Nov 2025 15:32:45 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Fri, 7 Nov 2025 15:31:33 +0100 Message-ID: <20251107143201.689035-20-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251107143201.689035-1-s.hanreich@proxmox.com> References: <20251107143201.689035-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.176 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH proxmox-perl-rs v3 10/12] pve-rs: fabrics: add function to get the neighbors for a fabric X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" From: Gabriel Goller Add a function that takes a fabricId and returns all routing protocol neighbors (OpenFabric or OSPF) identified by FRR. For OpenFabric, the fabric name is used as the area identifier, so we can filter easily. For OSPF, the fabric configuration is read/parsed to extract interfaces, which are then matched against the FRR neighbor output. The fabric configuration is always read first to verify that a fabric exists before querying FRR, as configuration parsing is (probably) faster than vtysh execution. Signed-off-by: Gabriel Goller Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 49 +++++++++++++ pve-rs/src/sdn/status.rs | 114 +++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 150b7fa..5230aa3 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -666,6 +666,55 @@ pub mod pve_rs_sdn_fabrics { } } + /// Get the neighbors for this specific fabric on this node + /// + /// Read and parse the fabric config to get the fabric protocol and the interfaces (ospf). + /// Parse the frr output of the neighbor commands and return a common format. + #[export] + fn neighbors(fabric_id: FabricId) -> Result { + // Read fabric config to get protocol of fabric + let config = get_fabrics_config()?; + + let fabric = config.get_fabric(&fabric_id)?; + + match fabric { + FabricEntry::Openfabric(_) => { + let openfabric_neighbors_string = String::from_utf8( + Command::new("sh") + .args(["-c", "vtysh -c 'show openfabric neighbor detail json'"]) + .output()? + .stdout, + )?; + let openfabric_neighbors: proxmox_frr::de::openfabric::Neighbors = + if openfabric_neighbors_string.is_empty() { + proxmox_frr::de::openfabric::Neighbors::default() + } else { + serde_json::from_str(&openfabric_neighbors_string) + .with_context(|| "error parsing openfabric neighbors")? + }; + + status::get_neighbors_openfabric(fabric_id, openfabric_neighbors).map(|v| v.into()) + } + FabricEntry::Ospf(fabric) => { + let ospf_neighbors_string = String::from_utf8( + Command::new("sh") + .args(["-c", "vtysh -c 'show ip ospf neighbor json'"]) + .output()? + .stdout, + )?; + let ospf_neighbors: proxmox_frr::de::ospf::Neighbors = + if ospf_neighbors_string.is_empty() { + proxmox_frr::de::ospf::Neighbors::default() + } else { + serde_json::from_str(&ospf_neighbors_string) + .with_context(|| "error parsing ospf neighbors")? + }; + + status::get_neighbors_ospf(fabric_id, fabric, ospf_neighbors).map(|v| v.into()) + } + } + } + /// Get the interfaces for this specific fabric on this node /// /// Read and parse the fabric config to get the protocol of the fabric and retrieve the diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs index 450bb6c..fb8f289 100644 --- a/pve-rs/src/sdn/status.rs +++ b/pve-rs/src/sdn/status.rs @@ -31,6 +31,16 @@ mod ospf { use proxmox_frr::de; use serde::Serialize; + /// The status of a neighbor. + /// + /// Contains the neighbor name and the neighbor status. + #[derive(Debug, Serialize)] + pub struct NeighborStatus { + pub neighbor: String, + pub status: String, + pub uptime: String, + } + /// The status of a fabric interface /// /// Contains the interface name, the interface state (so if the interface is up/down) and the type @@ -47,6 +57,16 @@ mod openfabric { use proxmox_frr::de; use serde::Serialize; + /// The status of a neighbor. + /// + /// Contains the neighbor name and the neighbor status. + #[derive(Debug, Serialize)] + pub struct NeighborStatus { + pub neighbor: String, + pub status: de::openfabric::AdjacencyState, + pub uptime: String, + } + /// The status of a fabric interface /// /// Contains the interface name, the interface state (so if the interface is up/down) and the type @@ -60,6 +80,25 @@ mod openfabric { } } +/// Common NeighborStatus that contains either OSPF or Openfabric neighbors +#[derive(Debug, Serialize)] +#[serde(untagged)] +pub enum NeighborStatus { + Openfabric(Vec), + Ospf(Vec), +} + +impl From> for NeighborStatus { + fn from(value: Vec) -> Self { + NeighborStatus::Openfabric(value) + } +} +impl From> for NeighborStatus { + fn from(value: Vec) -> Self { + NeighborStatus::Ospf(value) + } +} + /// Common InterfaceStatus that contains either OSPF or Openfabric interfaces #[derive(Debug, Serialize)] #[serde(untagged)] @@ -230,6 +269,81 @@ pub fn get_routes( Ok(stats) } +/// Convert the parsed openfabric neighbor neighbor information into a list of +/// [`openfabric::NeighborStatus`]. +/// +/// OpenFabric uses the name of the fabric as an "area", so simply match that to the fabric_id. +pub fn get_neighbors_openfabric( + fabric_id: FabricId, + neighbors: de::openfabric::Neighbors, +) -> Result, anyhow::Error> { + let mut stats: Vec = Vec::new(); + + for area in &neighbors.areas { + if area.area != fabric_id.as_str() { + continue; + } + for circuit in &area.circuits { + let (Some(adj), Some(interface)) = (&circuit.adj, &circuit.interface) else { + continue; + }; + let Some(state) = interface.state else { + continue; + }; + stats.push(openfabric::NeighborStatus { + neighbor: adj.clone(), + status: state, + uptime: interface.last_ago.clone(), + }); + } + } + + Ok(stats) +} + +/// Convert the parsed ospf neighbor neighbor information into a list of [`ospf::NeighborStatus`]. +/// +/// Ospf does not use the name of the fabric at all, so we again need to retrieve the interfaces of +/// the fabric on this specific node and then match the neighbors to the fabric using the +/// interfaces. +pub fn get_neighbors_ospf( + fabric_id: FabricId, + fabric: &Entry, + neighbors: de::ospf::Neighbors, +) -> Result, anyhow::Error> { + let hostname = proxmox_sys::nodename(); + + let mut stats: Vec = Vec::new(); + + if let Ok(node) = fabric.node_section(&NodeId::from_string(hostname.to_string())?) { + let mut interface_names: HashSet<&str> = node + .properties() + .interfaces() + .map(|i| i.name().as_str()) + .collect(); + + let dummy_interface = format!("dummy_{}", fabric_id.as_str()); + interface_names.insert(&dummy_interface); + + for neighbor_list in neighbors.neighbors.values() { + // Find first neighbor whose interface is in our fabric + if let Some(neighbor) = neighbor_list.iter().find(|n| { + n.interface_name + .split_once(':') + .is_some_and(|(iface, _)| interface_names.contains(iface)) + }) { + stats.push(ospf::NeighborStatus { + neighbor: neighbor.interface_address.clone(), + status: neighbor.neighbor_state.clone(), + uptime: neighbor.up_time.clone(), + }); + } + } + } + + Ok(stats) +} + /// Conver the `show openfabric interface` output into a list of [`openfabric::InterfaceStatus`]. /// /// Openfabric uses the name of the fabric as an "area", so simply match that to the fabric_id. -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel