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 E56B31FF164 for ; Fri, 28 Mar 2025 18:14:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 01D0B8287; Fri, 28 Mar 2025 18:13:54 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Fri, 28 Mar 2025 18:12:59 +0100 Message-Id: <20250328171340.885413-12-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250328171340.885413-1-g.goller@proxmox.com> References: <20250328171340.885413-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.025 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 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 10/17] 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. Signed-off-by: Gabriel Goller --- proxmox-frr/src/lib.rs | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/proxmox-frr/src/lib.rs b/proxmox-frr/src/lib.rs index 1a657c087ff0..08abdd371653 100644 --- a/proxmox-frr/src/lib.rs +++ b/proxmox-frr/src/lib.rs @@ -16,6 +16,46 @@ pub enum RouterNameError { FrrWordError(#[from] FrrWordError), } +/// Generic FRR router. +/// +/// This generic FRR router contains all the variants that are allowed. +#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, 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. +/// +/// Can vary between different router-types. Some have `router `, others have +/// `router `. +#[derive(Clone, Debug, PartialEq, Eq, Hash, SerializeDisplay, 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 we can have two /// different entries in the hashmap. This allows us to have an interface in an ospf and openfabric /// fabric. @@ -135,3 +175,42 @@ impl Display for CommonInterfaceName { self.0.fmt(f) } } + +/// Main FRR config. +/// +/// Contains the two main frr building blocks: routers and interfaces. To ease construction use the +/// [`FrrConfigBuilder`], which converts the intermediate representation to the FRR-specific +/// representation here. Eventually we can add different control options here, such as: `line vty`. +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct FrrConfig { + pub router: BTreeMap, + pub interfaces: BTreeMap, + pub access_lists: BTreeMap, + pub routemaps: Vec, + pub protocol_routemaps: Vec, +} + +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