public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics
@ 2025-09-05 11:44 Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 1/3] ve-config: add optional tag property to vnet Gabriel Goller
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:44 UTC (permalink / raw)
  To: pve-devel

This series adds endpoints to get status information about EVPN FRR
deployments. This is intended to be used mainly in PDM, but could also be
included in the PVE UI in the future.

Put very simply, in EVPN we have two types of Routes: Layer2 routes (with mac
addresses) and Layer3 routes (with ip addresses). In PVE they are separated
nicely when using a Vnet (Layer2) and a Zone (Layer3). This means we can just
add an endpoint for Vnets and Zones and get Layer2 and Layer3 statistics
about the EVPN deployment.

Getting Zone (Layer3) routes is very simple, we just need to find the VRF of
the Zone (which is always named "vrf_{zone}", then get all the routes in the
VRF using frr (`vtysh -c 'show ip route vrf ...'`). Getting VNet (Layer2)
routes is a bit more complicated, we could use `bridge fdb` to get the mac
addresses for the hosts but in order to get more information (like nexthops,
etc.) we again query frr: `vtysh -c 'show bgp l2vpn evpn route vni {vni}'`. The
VNI is the tag of a VNet -- which means we need to read the `.running-config`
beforehand and get all the VNet tags.


This series is based on the fabrics status view series:
https://lore.proxmox.com/pve-devel/20250904114206.193052-1-g.goller@proxmox.com/

proxmox-ve-rs:

Gabriel Goller (3):
  ve-config: add optional tag property to vnet
  frr: fix some route deserialization types
  frr: add deserialization types for EVPN

 proxmox-frr/Cargo.toml                        |   1 +
 proxmox-frr/debian/control                    |   2 +
 proxmox-frr/src/de/evpn.rs                    | 165 ++++++++++++++++++
 proxmox-frr/src/de/mod.rs                     |  13 +-
 proxmox-ve-config/src/sdn/config.rs           |  27 ++-
 proxmox-ve-config/tests/sdn/main.rs           |   5 +-
 .../tests/sdn/resources/running-config.json   |   1 +
 7 files changed, 205 insertions(+), 9 deletions(-)
 create mode 100644 proxmox-frr/src/de/evpn.rs


proxmox-perl-rs:

Gabriel Goller (2):
  pve-rs: sdn: fabrics: update openfabric/ospf route filtering
  pve-rs: sdn: add functions to retrieve the Zone/Vnet routes

 pve-rs/src/bindings/sdn/fabrics.rs |  57 +++++++++++++++
 pve-rs/src/sdn/status.rs           | 114 ++++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 9 deletions(-)


pve-network:

Gabriel Goller (1):
  sdn: add vnet and zone status endpoints

 src/PVE/API2/Network/SDN/Vnets.pm | 36 +++++++++++++++++++++++++++++++
 src/PVE/API2/Network/SDN/Zones.pm | 26 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)


Summary over all repositories:
  11 files changed, 429 insertions(+), 18 deletions(-)

-- 
Generated by git-murpp 0.8.0


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH proxmox-ve-rs 1/3] ve-config: add optional tag property to vnet
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
@ 2025-09-05 11:44 ` Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 2/3] frr: fix some route deserialization types Gabriel Goller
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:44 UTC (permalink / raw)
  To: pve-devel

When parsing the vnet.cfg config file we also want to get the tag
(vni or vlan). We need this so that we can lookup the vni of the passed
vnet on the status api call. We need the vni so that we can filter the
frr output.

In the future we would probably want to do this better with an enum per
vnet type and parse all possible options.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 proxmox-ve-config/src/sdn/config.rs           | 27 ++++++++++++++++---
 proxmox-ve-config/tests/sdn/main.rs           |  5 ++--
 .../tests/sdn/resources/running-config.json   |  1 +
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs
index 031fedcebbfc..afc5175002b1 100644
--- a/proxmox-ve-config/src/sdn/config.rs
+++ b/proxmox-ve-config/src/sdn/config.rs
@@ -196,6 +196,7 @@ pub struct SubnetsRunningConfig {
 /// Struct for deserializing a vnet entry of the SDN running config
 #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub struct VnetRunningConfig {
+    tag: Option<u32>,
     zone: ZoneName,
 }
 
@@ -295,14 +296,16 @@ impl SubnetConfig {
 #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub struct VnetConfig {
     name: VnetName,
+    tag: Option<u32>,
     subnets: BTreeMap<Cidr, SubnetConfig>,
 }
 
 impl VnetConfig {
-    pub fn new(name: VnetName) -> Self {
+    pub fn new(name: VnetName, tag: Option<u32>) -> Self {
         Self {
             name,
             subnets: BTreeMap::default(),
+            tag,
         }
     }
 
@@ -310,7 +313,18 @@ impl VnetConfig {
         name: VnetName,
         subnets: impl IntoIterator<Item = SubnetConfig>,
     ) -> Result<Self, SdnConfigError> {
-        let mut config = Self::new(name);
+        let mut config = Self::new(name, None);
+        config.add_subnets(subnets)?;
+        Ok(config)
+    }
+
+    pub fn from_subnets_and_tag(
+        name: VnetName,
+        tag: Option<u32>,
+        subnets: impl IntoIterator<Item = SubnetConfig>,
+    ) -> Result<Self, SdnConfigError> {
+        let mut config = Self::new(name, None);
+        config.tag = tag;
         config.add_subnets(subnets)?;
         Ok(config)
     }
@@ -342,6 +356,10 @@ impl VnetConfig {
     pub fn name(&self) -> &VnetName {
         &self.name
     }
+
+    pub fn tag(&self) -> &Option<u32> {
+        &self.tag
+    }
 }
 
 #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -617,7 +635,10 @@ impl TryFrom<RunningConfig> for SdnConfig {
 
         if let Some(running_vnets) = value.vnets.take() {
             for (name, running_config) in running_vnets.ids {
-                config.add_vnet(&running_config.zone, VnetConfig::new(name))?;
+                config.add_vnet(
+                    &running_config.zone,
+                    VnetConfig::new(name, running_config.tag),
+                )?;
             }
         }
 
diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs
index 94039ad5550e..bd38bbfc71f4 100644
--- a/proxmox-ve-config/tests/sdn/main.rs
+++ b/proxmox-ve-config/tests/sdn/main.rs
@@ -25,8 +25,9 @@ fn parse_running_config() {
         ZoneName::from_str("zone0").unwrap(),
         ZoneType::Simple,
         [
-            VnetConfig::from_subnets(
+            VnetConfig::from_subnets_and_tag(
                 VnetName::from_str("vnet0").unwrap(),
+                Some(100),
                 [
                     SubnetConfig::new(
                         SubnetName::from_str("zone0-fd80::-64").unwrap(),
@@ -84,7 +85,7 @@ fn sdn_config() {
     let zone0 = ZoneConfig::new(zone0_name.clone(), ZoneType::Qinq);
     sdn_config.add_zone(zone0).unwrap();
 
-    let vnet0 = VnetConfig::new(vnet0_name.clone());
+    let vnet0 = VnetConfig::new(vnet0_name.clone(), None);
     assert_eq!(
         sdn_config.add_vnet(&zone1_name, vnet0.clone()),
         Err(SdnConfigError::ZoneNotFound)
diff --git a/proxmox-ve-config/tests/sdn/resources/running-config.json b/proxmox-ve-config/tests/sdn/resources/running-config.json
index b03c20fa6ff9..d6054ba8d023 100644
--- a/proxmox-ve-config/tests/sdn/resources/running-config.json
+++ b/proxmox-ve-config/tests/sdn/resources/running-config.json
@@ -43,6 +43,7 @@
     "ids": {
       "vnet0": {
         "type": "vnet",
+        "tag": 100,
         "zone": "zone0"
       },
       "vnet1": {
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH proxmox-ve-rs 2/3] frr: fix some route deserialization types
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 1/3] ve-config: add optional tag property to vnet Gabriel Goller
@ 2025-09-05 11:44 ` Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 3/3] frr: add deserialization types for EVPN Gabriel Goller
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:44 UTC (permalink / raw)
  To: pve-devel

Make some properties optional and add others that aren't always used.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 proxmox-frr/src/de/mod.rs | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/proxmox-frr/src/de/mod.rs b/proxmox-frr/src/de/mod.rs
index 43890506253d..2771a1c36661 100644
--- a/proxmox-frr/src/de/mod.rs
+++ b/proxmox-frr/src/de/mod.rs
@@ -16,19 +16,23 @@ pub struct NextHop {
     /// IP of the nexthop
     pub ip: Option<IpAddr>,
     /// AFI (either IPv4, IPv6 or something else)
-    pub afi: String,
+    pub afi: Option<String>,
     /// Index of the outgoing interface
     #[serde(rename = "interfaceIndex")]
-    pub interface_index: i32,
+    pub interface_index: Option<i32>,
     #[serde(rename = "interfaceName")]
     /// Name of the outgoing interface
-    pub interface_name: String,
+    pub interface_name: Option<String>,
     /// If the nexthop is active
     pub active: bool,
+    /// If the nexthop is unreachable
+    pub unreachable: Option<bool>,
+    /// If the nexthop is rejected
+    pub reject: Option<bool>,
     /// If the route has the onlink flag. Onlink means that we pretend that the nexthop is
     /// directly attached to this link, even if it does not match any interface prefix.
     #[serde(rename = "onLink")]
-    pub on_link: bool,
+    pub on_link: Option<bool>,
     /// Remap-Source, this rewrites the source address to the following address, if this
     /// nexthop is used.
     #[serde(rename = "rmapSource")]
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH proxmox-ve-rs 3/3] frr: add deserialization types for EVPN
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 1/3] ve-config: add optional tag property to vnet Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 2/3] frr: fix some route deserialization types Gabriel Goller
@ 2025-09-05 11:44 ` Gabriel Goller
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve-rs: sdn: fabrics: update openfabric/ospf route filtering Gabriel Goller
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:44 UTC (permalink / raw)
  To: pve-devel

Add deserialization types for the `show bgp l2vpn evpn route vni <vni>`
command. This command shows all the L2VPN (EVPN) routes that are
distributed over BGP.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 proxmox-frr/Cargo.toml     |   1 +
 proxmox-frr/debian/control |   2 +
 proxmox-frr/src/de/evpn.rs | 165 +++++++++++++++++++++++++++++++++++++
 proxmox-frr/src/de/mod.rs  |   1 +
 4 files changed, 169 insertions(+)
 create mode 100644 proxmox-frr/src/de/evpn.rs

diff --git a/proxmox-frr/Cargo.toml b/proxmox-frr/Cargo.toml
index 8ada547301e8..1b241a03e60d 100644
--- a/proxmox-frr/Cargo.toml
+++ b/proxmox-frr/Cargo.toml
@@ -14,6 +14,7 @@ thiserror = { workspace = true }
 anyhow = "1"
 tracing = "0.1"
 serde = { workspace = true, features = [ "derive" ] }
+serde_repr = "0.1"
 
 proxmox-network-types = { workspace = true }
 proxmox-sdn-types = { workspace = true }
diff --git a/proxmox-frr/debian/control b/proxmox-frr/debian/control
index bce0c709b13e..3a73732de962 100644
--- a/proxmox-frr/debian/control
+++ b/proxmox-frr/debian/control
@@ -11,6 +11,7 @@ Build-Depends-Arch: cargo:native <!nocheck>,
  librust-proxmox-sdn-types-0.1+default-dev <!nocheck>,
  librust-serde-1+default-dev <!nocheck>,
  librust-serde-1+derive-dev <!nocheck>,
+ librust-serde-repr-0.1+default-dev <!nocheck>,
  librust-thiserror-2+default-dev <!nocheck>,
  librust-tracing-0.1+default-dev <!nocheck>
 Maintainer: Proxmox Support Team <support@proxmox.com>
@@ -31,6 +32,7 @@ Depends:
  librust-proxmox-sdn-types-0.1+default-dev,
  librust-serde-1+default-dev,
  librust-serde-1+derive-dev,
+ librust-serde-repr-0.1+default-dev,
  librust-thiserror-2+default-dev,
  librust-tracing-0.1+default-dev
 Provides:
diff --git a/proxmox-frr/src/de/evpn.rs b/proxmox-frr/src/de/evpn.rs
new file mode 100644
index 000000000000..bbc44c9a9522
--- /dev/null
+++ b/proxmox-frr/src/de/evpn.rs
@@ -0,0 +1,165 @@
+use std::{collections::HashMap, net::IpAddr};
+
+use proxmox_network_types::mac_address::MacAddress;
+use serde::Deserialize;
+use serde_repr::Deserialize_repr;
+
+/// All EVPN routes
+#[derive(Debug, Default, Deserialize)]
+pub struct Routes(pub HashMap<String, Entry>);
+
+/// The evpn routes a stored in a hashtable, which has a numPrefix and numPath key at
+/// the end which stores the number of paths and prefixes. These two keys have a i32
+/// value, while the other entries have a normal [`Route`] entry.
+#[derive(Debug, Deserialize)]
+#[serde(untagged)]
+pub enum Entry {
+    /// Route
+    Route(Route),
+    // This stores the numPrefix and numPath properties (which are not used) (this is
+    // a workaround)
+    Metadata(i32),
+}
+
+/// An EVPN route
+#[derive(Debug, Deserialize)]
+pub struct Route {
+    /// The full EVPN prefix
+    pub prefix: String,
+    /// Length of the prefix
+    #[serde(rename = "prefixLen")]
+    pub prefix_len: i32,
+    /// Paths to the EVPN route
+    pub paths: Vec<Vec<Path>>,
+}
+
+/// An EVPN Route Path
+#[derive(Debug, Deserialize)]
+pub struct Path {
+    /// Is this path valid
+    pub valid: bool,
+    /// Is this the best path
+    pub bestpath: bool,
+    /// Reason for selection (longer explanatory string)
+    #[serde(rename = "selectionReason")]
+    pub selection_reason: String,
+    /// From where the EVPN Route path comes
+    #[serde(rename = "pathFrom")]
+    pub path_from: PathFrom,
+    /// EVPN route type
+    #[serde(rename = "routeType")]
+    pub route_type: RouteType,
+    /// Ethernet tag
+    #[serde(rename = "ethTag")]
+    pub ethernet_tag: i32,
+    /// Mac Address length
+    #[serde(rename = "macLen")]
+    pub mac_length: Option<i32>,
+    /// Mac Address
+    pub mac: Option<MacAddress>,
+    /// IP Address lenght
+    #[serde(rename = "ipLen")]
+    pub ip_length: Option<i32>,
+    /// IP Address
+    pub ip: Option<IpAddr>,
+    /// Local Preference of the path
+    #[serde(rename = "locPrf")]
+    pub local_preference: Option<i32>,
+    /// Weight of the path
+    pub weight: i32,
+    /// PeerId, can be either IP or unspecified
+    #[serde(rename = "peerId")]
+    pub peer_id: PeerId,
+    /// AS path of the EVPN route
+    #[serde(rename = "path")]
+    pub as_path: String,
+    /// Origin of the route
+    pub origin: Origin,
+    /// Extended BGP Community
+    #[serde(rename = "extendedCommunity")]
+    pub extended_community: ExtendedCommunity,
+    /// Nexthops
+    pub nexthops: Vec<Nexthop>,
+}
+
+/// PeerId of the EVPN route path
+#[derive(Debug, Deserialize)]
+#[serde(untagged)]
+pub enum PeerId {
+    /// IP Address
+    IpAddr(IpAddr),
+    /// Not specified
+    Unspec(String),
+}
+
+/// Nexthop of a EVPN path
+#[derive(Debug, Deserialize)]
+pub struct Nexthop {
+    /// IP of the nexthop
+    pub ip: IpAddr,
+    /// Hostname of the nexthop
+    pub hostname: String,
+    /// Afi of the ip
+    pub afi: Option<Protocol>,
+    /// Used
+    pub used: bool,
+}
+
+/// Protocol AFI for a EVPN nexthop
+#[derive(Debug, Deserialize)]
+pub enum Protocol {
+    /// IPV4
+    #[serde(rename = "ipv4")]
+    IPv4,
+    /// IPV6
+    #[serde(rename = "ipv6")]
+    IPv6,
+}
+
+/// Extended Community for EVPN route
+#[derive(Debug, Deserialize)]
+pub struct ExtendedCommunity {
+    /// String with all the BGP ExtendedCommunities (this also contains the
+    /// RouteTarget)
+    pub string: String,
+}
+
+/// Origin of the EVPN route
+#[derive(Debug, Deserialize)]
+pub enum Origin {
+    /// Interior Gateway Protocol
+    #[serde(rename = "IGP")]
+    Igp,
+    #[serde(rename = "EGP")]
+    /// Exterior Gateway Protocol
+    Egp,
+    #[serde(rename = "incomplete")]
+    /// Incomplete
+    Incomplete,
+}
+
+/// EVPN RouteType
+#[derive(Debug, Deserialize_repr)]
+#[repr(u8)]
+pub enum RouteType {
+    /// EthernetAutoDiscovery
+    EthernetAutoDiscovery = 1,
+    /// MacIpAdvertisement
+    MacIpAdvertisement = 2,
+    /// InclusiveMulticastEthernetTag
+    InclusiveMulticastEthernetTag = 3,
+    /// EthernetSegment
+    EthernetSegment = 4,
+    /// IpPrefix
+    IpPrefix = 5,
+}
+
+/// From where the EVPN route path comes
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum PathFrom {
+    /// Internal
+    Internal,
+    /// External
+    External,
+}
diff --git a/proxmox-frr/src/de/mod.rs b/proxmox-frr/src/de/mod.rs
index 2771a1c36661..c0f262e410ee 100644
--- a/proxmox-frr/src/de/mod.rs
+++ b/proxmox-frr/src/de/mod.rs
@@ -3,6 +3,7 @@ use std::{collections::HashMap, net::IpAddr};
 use proxmox_network_types::ip_address::Cidr;
 use serde::{Deserialize, Serialize};
 
+pub mod evpn;
 pub mod openfabric;
 pub mod ospf;
 
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH proxmox-perl-rs 1/2] pve-rs: sdn: fabrics: update openfabric/ospf route filtering
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
                   ` (2 preceding siblings ...)
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 3/3] frr: add deserialization types for EVPN Gabriel Goller
@ 2025-09-05 11:44 ` Gabriel Goller
  2025-09-05 11:45 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve-rs: sdn: add functions to retrieve the Zone/Vnet routes Gabriel Goller
  2025-09-05 11:45 ` [pve-devel] [PATCH pve-network 1/1] sdn: add vnet and zone status endpoints Gabriel Goller
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:44 UTC (permalink / raw)
  To: pve-devel

Some deserialization types have been updated on the common routes `ip
route ...` command. Update the filtering function accordingly.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pve-rs/src/sdn/status.rs | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index fc8c19bbcf53..81253732472e 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -150,9 +150,11 @@ pub fn get_routes(routes: RoutesParsed) -> Result<Vec<RouteStatus>, anyhow::Erro
             let mut route_belongs_to_fabric = false;
             for route in route_list {
                 for nexthop in &route.nexthops {
-                    if interface_names.contains(&nexthop.interface_name.as_str()) {
-                        route_belongs_to_fabric = true;
-                        break;
+                    if let Some(iface_name) = &nexthop.interface_name {
+                        if interface_names.contains(iface_name.as_str()) {
+                            route_belongs_to_fabric = true;
+                            break;
+                        }
                     }
                 }
                 if route_belongs_to_fabric {
@@ -166,8 +168,12 @@ pub fn get_routes(routes: RoutesParsed) -> Result<Vec<RouteStatus>, anyhow::Erro
                     for nexthop in &route.nexthops {
                         let via = if let Some(ip) = nexthop.ip {
                             ip.to_string()
+                        } else if let Some(iface_name) = &nexthop.interface_name {
+                            iface_name.clone()
+                        } else if let Some(true) = &nexthop.unreachable {
+                            "unreachable".to_string()
                         } else {
-                            nexthop.interface_name.clone()
+                            continue;
                         };
                         via_list.push(via);
                     }
@@ -314,10 +320,13 @@ pub fn get_status(routes: RoutesParsed) -> Result<HashMap<FabricId, Status>, any
         // determine status by checking if any routes exist for our interfaces
         let has_routes = all_routes.values().any(|v| {
             v.iter().any(|route| {
-                route
-                    .nexthops
-                    .iter()
-                    .any(|nexthop| interface_names.contains(&nexthop.interface_name.as_str()))
+                route.nexthops.iter().any(|nexthop| {
+                    if let Some(iface_name) = &nexthop.interface_name {
+                        interface_names.contains(iface_name.as_str())
+                    } else {
+                        false
+                    }
+                })
             })
         });
 
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH proxmox-perl-rs 2/2] pve-rs: sdn: add functions to retrieve the Zone/Vnet routes
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
                   ` (3 preceding siblings ...)
  2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve-rs: sdn: fabrics: update openfabric/ospf route filtering Gabriel Goller
@ 2025-09-05 11:45 ` Gabriel Goller
  2025-09-05 11:45 ` [pve-devel] [PATCH pve-network 1/1] sdn: add vnet and zone status endpoints Gabriel Goller
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:45 UTC (permalink / raw)
  To: pve-devel

To show the routes of the Zones (L3VPN) and Vnets (L2VPN) query FRR with
different commands and parse the output. To correctly filter the Vnet
routes by Vnet we also need to read the sdn config to get the VNI. We
can use the VNI to filter the FRR output.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pve-rs/src/bindings/sdn/fabrics.rs | 57 +++++++++++++++++++
 pve-rs/src/sdn/status.rs           | 89 +++++++++++++++++++++++++++++-
 2 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs
index 079a58c27d32..88e25366ee40 100644
--- a/pve-rs/src/bindings/sdn/fabrics.rs
+++ b/pve-rs/src/bindings/sdn/fabrics.rs
@@ -23,6 +23,7 @@ pub mod pve_rs_sdn_fabrics {
     use proxmox_section_config::typed::SectionConfigData;
     use proxmox_ve_config::common::valid::Validatable;
 
+    use proxmox_ve_config::sdn::config::{RunningConfig, SdnConfig};
     use proxmox_ve_config::sdn::fabric::section_config::Section;
     use proxmox_ve_config::sdn::fabric::section_config::fabric::{
         Fabric as ConfigFabric, FabricId,
@@ -739,4 +740,60 @@ pub mod pve_rs_sdn_fabrics {
 
         status::get_status(route_status)
     }
+
+    /// Get all the L3 routes for the passed zone.
+    ///
+    /// Every zone has a vrf named `vrf_{zone}`. Show all the L3 (IP) routes on the VRF of the
+    /// zone.
+    #[export]
+    fn l3vpn_routes(zone: String) -> Result<status::L3VPNRoutes, Error> {
+        let command = format!("vtysh -c 'show ip route vrf vrf_{zone} json'");
+        let l3vpn_routes_string =
+            String::from_utf8(Command::new("sh").args(["-c", &command]).output()?.stdout)?;
+        let l3vpn_routes: proxmox_frr::de::Routes = if l3vpn_routes_string.is_empty() {
+            proxmox_frr::de::Routes::default()
+        } else {
+            serde_json::from_str(&l3vpn_routes_string)
+                .with_context(|| "error parsing l3vpn routes")?
+        };
+
+        status::get_l3vpn_routes(&format!("vrf_{zone}"), l3vpn_routes)
+    }
+
+    /// Get all the L2 routes for the passed vnet.
+    ///
+    /// When using VXLAN the vnet "stores" the L2 routes in it's FDB. The best way to retrieve them
+    /// with additional metadata is to query FRR. Use the `show bgp l2vpn evpn route` command.
+    /// To filter by vnet, get the VNI of the vnet from the config and use it in the command.
+    #[export]
+    fn l2vpn_routes(vnet: String) -> Result<status::L2VPNRoutes, Error> {
+        // read config to get the vni of the vnet
+        let raw_config = std::fs::read_to_string("/etc/pve/sdn/.running-config")?;
+        let running_config: RunningConfig = serde_json::from_str(&raw_config)?;
+        let parsed_config = SdnConfig::try_from(running_config)?;
+
+        let Some(vni) = parsed_config.zones().find_map(|zone| {
+            zone.vnets().find_map(|vnet_config| {
+                if vnet_config.name().as_ref() == vnet {
+                    *vnet_config.tag()
+                } else {
+                    None
+                }
+            })
+        }) else {
+            anyhow::bail!("vnet does not have a vni");
+        };
+
+        let command = format!("vtysh -c 'show bgp l2vpn evpn route vni {vni} json'");
+        let l2vpn_routes_string =
+            String::from_utf8(Command::new("sh").args(["-c", &command]).output()?.stdout)?;
+        let l2vpn_routes: proxmox_frr::de::evpn::Routes = if l2vpn_routes_string.is_empty() {
+            proxmox_frr::de::evpn::Routes::default()
+        } else {
+            serde_json::from_str(&l2vpn_routes_string)
+                .with_context(|| "error parsing l2vpn routes")?
+        };
+
+        status::get_l2vpn_routes(l2vpn_routes)
+    }
 }
diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index 81253732472e..198ef7037683 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -1,6 +1,10 @@
-use std::collections::{BTreeMap, HashMap, HashSet};
+use std::{
+    collections::{BTreeMap, HashMap, HashSet},
+    net::IpAddr,
+};
 
 use anyhow::Context;
+use proxmox_network_types::{ip_address::Cidr, mac_address::MacAddress};
 use proxmox_section_config::typed::SectionConfigData;
 use serde::{Deserialize, Serialize};
 
@@ -346,3 +350,86 @@ pub fn get_status(routes: RoutesParsed) -> Result<HashMap<FabricId, Status>, any
 
     Ok(stats)
 }
+/// Common for nexthops, they can be either a interface name or a ip addr
+#[derive(Debug, Serialize)]
+#[serde(untagged)]
+pub enum IpAddrOrInterfaceName {
+    /// IpAddr
+    IpAddr(IpAddr),
+    /// Interface Name
+    InterfaceName(String),
+}
+
+/// One L3VPN route
+#[derive(Debug, Serialize)]
+pub struct L3VPNRoute {
+    ip: Cidr,
+    next_hop: Vec<IpAddrOrInterfaceName>,
+}
+
+/// All L3VPN routes of a zone
+#[derive(Debug, Serialize)]
+pub struct L3VPNRoutes(Vec<L3VPNRoute>);
+
+/// Convert parsed routes from frr into l3vpn routes, this means we need to match against the vrf
+/// name of the zone.
+pub fn get_l3vpn_routes(vrf: &str, routes: de::Routes) -> Result<L3VPNRoutes, anyhow::Error> {
+    let mut result = Vec::new();
+    for (prefix, routes) in routes.0 {
+        for route in routes {
+            if route.vrf_name == vrf {
+                result.push(L3VPNRoute {
+                    ip: prefix,
+                    next_hop: route
+                        .nexthops
+                        .into_iter()
+                        .filter_map(|nh| {
+                            if let Some(ip) = nh.ip {
+                                Some(IpAddrOrInterfaceName::IpAddr(ip))
+                            } else {
+                                nh.interface_name.map(IpAddrOrInterfaceName::InterfaceName)
+                            }
+                        })
+                        .collect(),
+                });
+            }
+        }
+    }
+    Ok(L3VPNRoutes(result))
+}
+
+/// One L2VPN route
+#[derive(Debug, Serialize)]
+pub struct L2VPNRoute {
+    mac: MacAddress,
+    ip: IpAddr,
+    ip_nexthop: IpAddr,
+}
+
+/// All L2VPN routes of a specific vnet
+#[derive(Debug, Serialize)]
+pub struct L2VPNRoutes(Vec<L2VPNRoute>);
+
+/// Convert the parsed frr evpn struct into an array of structured L2VPN routes
+pub fn get_l2vpn_routes(routes: de::evpn::Routes) -> Result<L2VPNRoutes, anyhow::Error> {
+    let mut result = Vec::new();
+    for route in routes.0.values().filter_map(|entry| match entry {
+        de::evpn::Entry::Route(r) => Some(r),
+        de::evpn::Entry::Metadata(_) => None,
+    }) {
+        route.paths.iter().flatten().for_each(|path| {
+            if path.bestpath {
+                if let (Some(mac), Some(ip), Some(nh)) = (path.mac, path.ip, path.nexthops.first())
+                {
+                    result.push(L2VPNRoute {
+                        mac,
+                        ip,
+                        ip_nexthop: nh.ip,
+                    });
+                }
+            }
+        });
+    }
+
+    Ok(L2VPNRoutes(result))
+}
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH pve-network 1/1] sdn: add vnet and zone status endpoints
  2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
                   ` (4 preceding siblings ...)
  2025-09-05 11:45 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve-rs: sdn: add functions to retrieve the Zone/Vnet routes Gabriel Goller
@ 2025-09-05 11:45 ` Gabriel Goller
  5 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2025-09-05 11:45 UTC (permalink / raw)
  To: pve-devel

Add status endpoints for vnets and zones. This endpoint will return the
Layer 2 routes for zones and the Layer 3 routes for vnets.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 src/PVE/API2/Network/SDN/Vnets.pm | 36 +++++++++++++++++++++++++++++++
 src/PVE/API2/Network/SDN/Zones.pm | 26 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/src/PVE/API2/Network/SDN/Vnets.pm b/src/PVE/API2/Network/SDN/Vnets.pm
index 1d9e500665f6..ccaa9f792909 100644
--- a/src/PVE/API2/Network/SDN/Vnets.pm
+++ b/src/PVE/API2/Network/SDN/Vnets.pm
@@ -16,6 +16,8 @@ use PVE::API2::Network::SDN::Subnets;
 use PVE::API2::Network::SDN::Ips;
 use PVE::API2::Firewall::Vnet;
 
+use PVE::RS::SDN::Fabrics;
+
 use Storable qw(dclone);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
@@ -467,4 +469,38 @@ __PACKAGE__->register_method({
     },
 });
 
+__PACKAGE__->register_method({
+    name => 'status',
+    path => '{vnet}/status',
+    method => 'GET',
+    description => "Get sdn vnet status.",
+    permissions => {
+        description =>
+            "Require 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
+        user => 'all',
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            vnet => get_standard_option(
+                'pve-sdn-vnet-id',
+                {
+                    completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnets,
+                },
+            ),
+        },
+    },
+    returns => { type => 'object' },
+    code => sub {
+        my ($param) = @_;
+
+        my $id = extract_param($param, 'vnet');
+
+        my $privs = ['SDN.Audit', 'SDN.Allocate'];
+        &$check_vnet_access($id, $privs);
+
+        return PVE::RS::SDN::Fabrics::l2vpn_routes($id);
+    },
+});
+
 1;
diff --git a/src/PVE/API2/Network/SDN/Zones.pm b/src/PVE/API2/Network/SDN/Zones.pm
index 8d829a9fd60b..0953c0c5dcad 100644
--- a/src/PVE/API2/Network/SDN/Zones.pm
+++ b/src/PVE/API2/Network/SDN/Zones.pm
@@ -26,6 +26,8 @@ use PVE::Network::SDN::Zones::VlanPlugin;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Network::SDN::Zones;
 
+use PVE::RS::SDN::Fabrics;
+
 use PVE::RESTHandler;
 use base qw(PVE::RESTHandler);
 
@@ -594,4 +596,28 @@ __PACKAGE__->register_method({
     },
 });
 
+__PACKAGE__->register_method({
+    name => 'status',
+    path => '{zone}/status',
+    method => 'GET',
+    description => "Get sdn zone status.",
+    permissions => {
+        check => ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
+    },
+
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            zone => get_standard_option('pve-sdn-zone-id'),
+        },
+    },
+    returns => { type => 'object' },
+    code => sub {
+        my ($param) = @_;
+        my $zone = extract_param($param, 'zone');
+
+        return PVE::RS::SDN::Fabrics::l3vpn_routes($zone);
+    },
+});
+
 1;
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-09-05 11:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-05 11:44 [pve-devel] [PATCH network/proxmox{-ve-rs, -perl-rs} 0/6] Add status endpoints for EVPN statistics Gabriel Goller
2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 1/3] ve-config: add optional tag property to vnet Gabriel Goller
2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 2/3] frr: fix some route deserialization types Gabriel Goller
2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-ve-rs 3/3] frr: add deserialization types for EVPN Gabriel Goller
2025-09-05 11:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve-rs: sdn: fabrics: update openfabric/ospf route filtering Gabriel Goller
2025-09-05 11:45 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve-rs: sdn: add functions to retrieve the Zone/Vnet routes Gabriel Goller
2025-09-05 11:45 ` [pve-devel] [PATCH pve-network 1/1] sdn: add vnet and zone status endpoints Gabriel Goller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal