From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-perl-rs v3 4/4] fabrics: add function to get all neighbors of the fabric
Date: Tue, 26 Aug 2025 11:49:48 +0200 [thread overview]
Message-ID: <20250826095000.180173-8-g.goller@proxmox.com> (raw)
In-Reply-To: <20250826095000.180173-1-g.goller@proxmox.com>
In order to also display the neighbors of a specific node in the
FabricContentView resource window get the Neighbors of the all the
fabrics. Query frr (vtysh) to get the neighbors of both openefabric and
ospf, parse it and then compile a array containing all neighbors and
the fabric it relates to.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
pve-rs/src/bindings/sdn/fabrics.rs | 43 ++++++++++++
pve-rs/src/sdn/status.rs | 104 +++++++++++++++++++++++++++++
2 files changed, 147 insertions(+)
diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs
index 14dad216dbf4..079a58c27d32 100644
--- a/pve-rs/src/bindings/sdn/fabrics.rs
+++ b/pve-rs/src/bindings/sdn/fabrics.rs
@@ -640,6 +640,49 @@ pub mod pve_rs_sdn_fabrics {
status::get_routes(route_status)
}
+ /// Get all the neighbors of all the fabrics on this node.
+ ///
+ /// Go through all fabrics that exist on this node. Then get the neighbors of them all and
+ /// concat them into a single array.
+ #[export]
+ fn neighbors() -> Result<Vec<status::NeighborStatus>, Error> {
+ let openfabric_neighbors_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show openfabric neighbor json'"])
+ .output()?
+ .stdout,
+ )?;
+
+ let ospf_neighbors_string = String::from_utf8(
+ Command::new("sh")
+ .args(["-c", "vtysh -c 'show ip ospf neighbor 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")?
+ };
+
+ 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")?
+ };
+
+ let neighbor_status = status::NeighborsParsed {
+ openfabric: openfabric_neighbors,
+ ospf: ospf_neighbors,
+ };
+
+ status::get_neighbors(neighbor_status)
+ }
+
/// Return the status of all fabrics on this node.
///
/// Go through all fabrics in the config, then filter out the ones that exist on this node.
diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index b15ad0330732..86be8df4a38c 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -8,6 +8,18 @@ use proxmox_ve_config::sdn::fabric::{
section_config::{fabric::FabricId, node::Node as ConfigNode},
};
+/// The status of a neighbor.
+///
+/// Contains the neighbor, the fabric and protocol it belongs to and the some status
+/// information.
+#[derive(Debug, Serialize)]
+pub struct NeighborStatus {
+ neighbor: String,
+ status: String,
+ fabric_id: FabricId,
+ protocol: Protocol,
+}
+
/// The status of a route.
///
/// Contains the route, the fabric and protocol it belongs to and some extra nexthop
@@ -66,6 +78,19 @@ pub struct RoutesParsed {
pub ospf: de::Routes,
}
+/// Parsed neighbors for all protocols
+///
+/// These are the neighbors parsed from the json output of:
+/// `vtysh -c 'show openfabric neighbor json'` and
+/// `vtysh -c 'show ip ospf neighbor json'`.
+#[derive(Debug, Serialize)]
+pub struct NeighborsParsed {
+ /// The openfabric neighbors in FRR
+ pub openfabric: de::openfabric::Neighbors,
+ /// The ospf neighbors in FRR
+ pub ospf: de::ospf::Neighbors,
+}
+
/// Convert the passed frr routes into a list of all routes with properties associating
/// them to a fabric.
pub fn get_routes(routes: RoutesParsed) -> Result<Vec<RouteStatus>, anyhow::Error> {
@@ -141,6 +166,85 @@ pub fn get_routes(routes: RoutesParsed) -> Result<Vec<RouteStatus>, anyhow::Erro
}
Ok(stats)
}
+
+/// Get a list of all neighbors of all the fabrics configured
+///
+/// Convert the passed neighbors of all frr protocols to a list of neighbors with
+/// with properties associating them to a specific fabric.
+pub fn get_neighbors(neighbors: NeighborsParsed) -> Result<Vec<NeighborStatus>, anyhow::Error> {
+ let hostname = proxmox_sys::nodename();
+
+ // get all nodes
+ let raw_config = std::fs::read_to_string("/etc/pve/sdn/fabrics.cfg")?;
+ let config = FabricConfig::parse_section_config(&raw_config)?;
+
+ let mut stats: Vec<NeighborStatus> = Vec::new();
+
+ for (nodeid, node) in config.all_nodes() {
+ if nodeid.as_str() != hostname {
+ continue;
+ }
+ let fabric_id = node.id().fabric_id();
+
+ match node {
+ ConfigNode::Openfabric(_) => {
+ for area in &neighbors.openfabric.areas {
+ if area.area == fabric_id.as_str() {
+ for circuit in &area.circuits {
+ if let (Some(adj), Some(state)) = (&circuit.adj, &circuit.state) {
+ stats.push(NeighborStatus {
+ neighbor: adj.clone(),
+ status: state.clone(),
+ protocol: Protocol::Openfabric,
+ fabric_id: fabric_id.clone(),
+ });
+ }
+ }
+ }
+ }
+ }
+ ConfigNode::Ospf(node) => {
+ let interface_names: HashSet<&str> = node
+ .properties()
+ .interfaces()
+ .map(|i| i.name().as_str())
+ .collect();
+
+ for (neighbor_key, neighbor_list) in &neighbors.ospf.neighbors {
+ let mut has_matching_neighbor = false;
+ for neighbor in neighbor_list {
+ match neighbor.interface_name.split_once(":") {
+ Some((interface_name, _)) => {
+ if interface_names.contains(interface_name) {
+ has_matching_neighbor = true;
+ break;
+ }
+ }
+ _ => {
+ continue;
+ }
+ }
+ }
+ if has_matching_neighbor {
+ let status = neighbor_list
+ .first()
+ .map(|n| n.neighbor_state.clone())
+ .unwrap_or_default();
+ stats.push(NeighborStatus {
+ neighbor: neighbor_key.clone(),
+ status,
+ protocol: Protocol::Ospf,
+ fabric_id: fabric_id.clone(),
+ });
+ }
+ }
+ }
+ }
+ }
+
+ Ok(stats)
+}
+
/// 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
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-08-26 9:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 9:49 [pve-devel] [PATCH manager/network/proxmox{-ve-rs, -perl-rs} v3 00/13] Add fabric status view Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-ve-rs v3 1/3] frr: make room for deserialization structs Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-ve-rs v3 2/3] frr: add deserialization types for openfabric and ospf Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-ve-rs v3 3/3] ve-config: add helper function to iterate over all nodes in all fabrics Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-perl-rs v3 1/4] pve: fabrics: update proxmox-frr import path Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-perl-rs v3 2/4] fabrics: add function to get status of fabric Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH proxmox-perl-rs v3 3/4] fabrics: add function to get all routes distributed by the fabrics Gabriel Goller
2025-08-26 9:49 ` Gabriel Goller [this message]
2025-08-26 9:49 ` [pve-devel] [PATCH pve-network v3 1/3] fabrics: add fabrics status to SDN::status function Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH pve-network v3 2/3] fabrics: add api endpoint to return fabrics routes Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH pve-network v3 3/3] fabrics: add api endpoint to return fabric neighbors Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH pve-manager v3 1/3] pvestatd: add fabrics status to pvestatd Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH pve-manager v3 2/3] fabrics: add resource view for fabrics Gabriel Goller
2025-08-26 9:49 ` [pve-devel] [PATCH pve-manager v3 3/3] permissions: differentiate between zone and fabric paths Gabriel Goller
2025-09-04 11:42 ` [pve-devel] [PATCH manager/network/proxmox{-ve-rs, -perl-rs} v3 00/13] Add fabric status view Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250826095000.180173-8-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox