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 CEA941FF183 for ; Wed, 16 Jul 2025 15:09:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0FD5CFD17; Wed, 16 Jul 2025 15:09:10 +0200 (CEST) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Wed, 16 Jul 2025 15:07:51 +0200 Message-Id: <20250716130837.585796-31-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250716130837.585796-1-g.goller@proxmox.com> References: <20250716130837.585796-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.013 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 RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-perl-rs v5 3/5] pve-rs: sdn: fabrics: add frr config generation 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: Stefan Hanreich We use proxmox-ve-config to generate a FRR config and serialize it with the proxmox-frr crate in order to return it to perl in its internally used format (an array of strings). The Perl SDN module in turn merges it with the FRR configuration generated by Perl modules and persists it to the FRR configuration file. We also provide a method that returns a list of daemons, that are required to be enabled for the current FRR configuration. This is used by Perl to write the daemons configuration file of FRR. Co-authored-by: Gabriel Goller Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 54 +++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 59545307b811..165b542fb7a0 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -5,7 +5,7 @@ pub mod pve_rs_sdn_fabrics { //! This provides the configuration for the SDN fabrics, as well as helper methods for reading //! / writing the configuration, as well as for generating ifupdown2 and FRR configuration. - use std::collections::BTreeMap; + use std::collections::{BTreeMap, HashSet}; use std::ops::Deref; use std::sync::Mutex; @@ -14,6 +14,7 @@ pub mod pve_rs_sdn_fabrics { use serde::{Deserialize, Serialize}; use perlmod::Value; + use proxmox_frr::serializer::to_raw_config; use proxmox_section_config::typed::SectionConfigData; use proxmox_ve_config::common::valid::Validatable; @@ -27,6 +28,7 @@ pub mod pve_rs_sdn_fabrics { api::{Node, NodeUpdater}, }; use proxmox_ve_config::sdn::fabric::{FabricConfig, FabricEntry}; + use proxmox_ve_config::sdn::frr::FrrConfigBuilder; /// A SDN Fabric config instance. #[derive(Serialize, Deserialize)] @@ -306,4 +308,54 @@ pub mod pve_rs_sdn_fabrics { Ok(hex::encode(hash)) } + + /// Method: Return all FRR daemons that need to be enabled for this fabric configuration + /// instance. + /// + /// FRR is a single service and different protocols are implement in daemons which can be + /// activated using the `/etc/frr/daemons` file. + /// + /// + #[export] + pub fn enabled_daemons( + #[try_from_ref] this: &PerlFabricConfig, + node_id: NodeId, + ) -> Vec { + let config = this.fabric_config.lock().unwrap(); + + let node_fabrics = config + .values() + .filter(|fabric| fabric.get_node(&node_id).is_ok()); + + let mut daemons = HashSet::new(); + + for fabric in node_fabrics { + match fabric { + FabricEntry::Ospf(_) => { + daemons.insert("ospfd"); + } + FabricEntry::Openfabric(_) => { + daemons.insert("fabricd"); + } + }; + } + + daemons.into_iter().map(String::from).collect() + } + + /// Method: Return the FRR configuration for this config instance, as an array of + /// strings, where each line represents a line in the FRR configuration. + #[export] + pub fn get_frr_raw_config( + #[try_from_ref] this: &PerlFabricConfig, + node_id: NodeId, + ) -> Result, Error> { + let config = this.fabric_config.lock().unwrap(); + + let frr_config = FrrConfigBuilder::default() + .add_fabrics(config.clone().into_valid()?) + .build(node_id)?; + + to_raw_config(&frr_config) + } } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel