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 8EB961FF183 for ; Wed, 16 Jul 2025 15:08:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 09C23F7B9; Wed, 16 Jul 2025 15:08:52 +0200 (CEST) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Wed, 16 Jul 2025 15:07:34 +0200 Message-Id: <20250716130837.585796-14-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.014 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-ve-rs v5 08/22] frr: add generic types over openfabric and ospf 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" Add generic FRR types that contain openfabric and ospf variants. Also add the FrrConfig, which holds the whole FRR configuration in a single struct, which will then be serialized to the FRR configuration file. Signed-off-by: Gabriel Goller --- proxmox-frr/src/lib.rs | 94 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/proxmox-frr/src/lib.rs b/proxmox-frr/src/lib.rs index b023b0d11426..20dea7b6d488 100644 --- a/proxmox-frr/src/lib.rs +++ b/proxmox-frr/src/lib.rs @@ -1,10 +1,63 @@ pub mod openfabric; pub mod ospf; pub mod route_map; -use std::{fmt::Display, str::FromStr}; + +use std::collections::{BTreeMap, BTreeSet}; +use std::fmt::Display; +use std::str::FromStr; + +use crate::route_map::{AccessList, ProtocolRouteMap, RouteMap}; use thiserror::Error; +/// Generic FRR router. +/// +/// This generic FRR router contains all the protocols that we implement. +/// In FRR this is e.g.: +/// ```text +/// router openfabric test +/// !.... +/// ! or +/// router ospf +/// !.... +/// ``` +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum Router { + Openfabric(openfabric::OpenfabricRouter), + Ospf(ospf::OspfRouter), +} + +impl From for Router { + fn from(value: openfabric::OpenfabricRouter) -> Self { + Router::Openfabric(value) + } +} + +/// Generic FRR routername. +/// +/// The variants represent different protocols. Some have `router `, others have +/// `router `, some only have `router `. +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum RouterName { + Openfabric(openfabric::OpenfabricRouterName), + Ospf(ospf::OspfRouterName), +} + +impl From for RouterName { + fn from(value: openfabric::OpenfabricRouterName) -> Self { + Self::Openfabric(value) + } +} + +impl Display for RouterName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Openfabric(r) => r.fmt(f), + Self::Ospf(r) => r.fmt(f), + } + } +} + /// The interface name is the same on ospf and openfabric, but it is an enum so that we can have /// two different entries in the btreemap. This allows us to have an interface in a ospf and /// openfabric fabric. @@ -146,3 +199,42 @@ impl Display for CommonInterfaceName { self.0.fmt(f) } } + +/// Main FRR config. +/// +/// Contains the two main frr building blocks: routers and interfaces. It also holds other +/// top-level FRR options, such as access-lists, router-maps and protocol-routemaps. This struct +/// gets generated using the `FrrConfigBuilder` in `proxmox-ve-config`. +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct FrrConfig { + pub router: BTreeMap, + pub interfaces: BTreeMap, + pub access_lists: Vec, + pub routemaps: Vec, + pub protocol_routemaps: BTreeSet, +} + +impl FrrConfig { + pub fn new() -> Self { + Self::default() + } + + pub fn router(&self) -> impl Iterator + '_ { + self.router.iter() + } + + pub fn interfaces(&self) -> impl Iterator + '_ { + self.interfaces.iter() + } + + pub fn access_lists(&self) -> impl Iterator + '_ { + self.access_lists.iter() + } + pub fn routemaps(&self) -> impl Iterator + '_ { + self.routemaps.iter() + } + + pub fn protocol_routemaps(&self) -> impl Iterator + '_ { + self.protocol_routemaps.iter() + } +} -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel