From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 37C3F1FF164 for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:17:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1DDB49101; Fri, 28 Mar 2025 18:14:19 +0100 (CET) From: Gabriel Goller <g.goller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 28 Mar 2025 18:12:51 +0100 Message-Id: <20250328171340.885413-4-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.026 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 02/17] network-types: add common hostname and openfabric types X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> The Hostname type will be used as a type for a pve hostname. It it used in the NodeId, which connects the pve-host with the fabric. The openfabric options are HelloInterval, CsnpInterval and HelloMultiplier. These are the options that are used in our `Ceph FullMesh Guide` and are probably the most used ones. - HelloInterval: Time interval in seconds (range 1-600) between consecutive Hello packets sent on an interface to establish and maintain adjacency between OpenFabric neighbors. - CsnpInterval: Time interval in seconds (range 1-600) between Complete Sequence Number Packets used to synchronize link-state databases between OpenFabric neighbors. - HelloMultiplier: Factor (range 2-100) applied to HelloInterval to determine how long to wait before declaring a neighbor down when no Hello packets are received. Signed-off-by: Gabriel Goller <g.goller@proxmox.com> --- proxmox-network-types/src/hostname.rs | 34 ++++++++++ proxmox-network-types/src/lib.rs | 2 + proxmox-network-types/src/openfabric.rs | 89 +++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 proxmox-network-types/src/hostname.rs create mode 100644 proxmox-network-types/src/openfabric.rs diff --git a/proxmox-network-types/src/hostname.rs b/proxmox-network-types/src/hostname.rs new file mode 100644 index 000000000000..35ada64e8194 --- /dev/null +++ b/proxmox-network-types/src/hostname.rs @@ -0,0 +1,34 @@ +use std::fmt::Display; + +use serde::{Deserialize, Serialize}; + +/// Hostname of pve node. +/// +/// This is used to distinguish different pve nodes in a fabric. +#[derive(Debug, Deserialize, Serialize, Clone, Eq, Hash, PartialOrd, Ord, PartialEq)] +#[serde(from = "String")] +pub struct Hostname(String); + +impl From<String> for Hostname { + fn from(value: String) -> Self { + Hostname::new(value) + } +} + +impl AsRef<str> for Hostname { + fn as_ref(&self) -> &str { + &self.0 + } +} + +impl Display for Hostname { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +impl Hostname { + pub fn new(name: impl Into<String>) -> Hostname { + Self(name.into()) + } +} diff --git a/proxmox-network-types/src/lib.rs b/proxmox-network-types/src/lib.rs index e69de29bb2d1..afceab018312 100644 --- a/proxmox-network-types/src/lib.rs +++ b/proxmox-network-types/src/lib.rs @@ -0,0 +1,2 @@ +pub mod hostname; +pub mod openfabric; diff --git a/proxmox-network-types/src/openfabric.rs b/proxmox-network-types/src/openfabric.rs new file mode 100644 index 000000000000..f3fce5dcca7c --- /dev/null +++ b/proxmox-network-types/src/openfabric.rs @@ -0,0 +1,89 @@ +use std::{fmt::Display, num::ParseIntError}; + +use serde::{Deserialize, Serialize}; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum IntegerRangeError { + #[error("The value must be between {min} and {max} seconds")] + OutOfRange { min: i32, max: i32 }, + #[error("Error parsing to number")] + ParsingError(#[from] ParseIntError), +} + +/// The OpenFabric CSNP Interval. +/// +/// The Complete Sequence Number Packets (CSNP) interval in seconds. The interval range is 1 to +/// 600. +#[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[serde(try_from = "u16")] +pub struct CsnpInterval(u16); + +impl TryFrom<u16> for CsnpInterval { + type Error = IntegerRangeError; + + fn try_from(number: u16) -> Result<Self, Self::Error> { + if (1..=600).contains(&number) { + Ok(CsnpInterval(number)) + } else { + Err(IntegerRangeError::OutOfRange { min: 1, max: 600 }) + } + } +} + +impl Display for CsnpInterval { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +/// The OpenFabric Hello Interval. +/// +/// The Hello Interval for a given interface in seconds. The range is 1 to 600. Hello packets are +/// used to establish and maintain adjacency between OpenFabric neighbors. +#[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[serde(try_from = "u16")] +pub struct HelloInterval(u16); + +impl TryFrom<u16> for HelloInterval { + type Error = IntegerRangeError; + + fn try_from(number: u16) -> Result<Self, Self::Error> { + if (1..=600).contains(&number) { + Ok(HelloInterval(number)) + } else { + Err(IntegerRangeError::OutOfRange { min: 1, max: 600 }) + } + } +} + +impl Display for HelloInterval { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +/// The OpenFabric Hello Multiplier. +/// +/// This is the multiplier for the hello holding time on a given interface. The range is 2 to 100. +#[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[serde(try_from = "u16")] +pub struct HelloMultiplier(u16); + +impl TryFrom<u16> for HelloMultiplier { + type Error = IntegerRangeError; + + fn try_from(number: u16) -> Result<Self, Self::Error> { + if (2..=100).contains(&number) { + Ok(HelloMultiplier(number)) + } else { + Err(IntegerRangeError::OutOfRange { min: 2, max: 100 }) + } + } +} + +impl Display for HelloMultiplier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel