[pve-devel] [PATCH proxmox-ve-rs 02/17] network-types: add common hostname and openfabric types

Gabriel Goller g.goller at proxmox.com
Fri Mar 28 18:12:51 CET 2025


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 at 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





More information about the pve-devel mailing list