public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 07/13] ui: add VrfTree component
Date: Fri, 28 Feb 2025 16:17:57 +0100	[thread overview]
Message-ID: <20250228151803.158984-21-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250228151803.158984-1-s.hanreich@proxmox.com>

This component shows a tree of all EVPN Zones of all remotes
configured in the PDM. They are grouped by VRF (= VRF VXLAN VNI of the
EVPN zone) first. The second level are the remotes, so users can see
all remotes where the VRF already exists. The third level, below the
respective remote, shows all VNets in the zones as well as their VXLAN
VNI.

I've decided to refer to EVPN Zones in the PDM UI as VRF, since this
is the well-established name for a routing table in this context. It
makes the purpose of having multiple zones clearer, since users were
confused about how to create multiple VRFs. By changing the name in
the PDM UI, this should be a lot easier to grasp for users not
familiar with the SDN stack. It also harmonizes our terminology with
the well-established standard terminology used in RFC 8356 [1]

[1] https://datatracker.ietf.org/doc/html/rfc8365

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 ui/src/lib.rs               |   2 +
 ui/src/sdn/evpn/mod.rs      |   2 +
 ui/src/sdn/evpn/vrf_tree.rs | 291 ++++++++++++++++++++++++++++++++++++
 ui/src/sdn/mod.rs           |   1 +
 4 files changed, 296 insertions(+)
 create mode 100644 ui/src/sdn/evpn/mod.rs
 create mode 100644 ui/src/sdn/evpn/vrf_tree.rs
 create mode 100644 ui/src/sdn/mod.rs

diff --git a/ui/src/lib.rs b/ui/src/lib.rs
index e3755ec..bde8917 100644
--- a/ui/src/lib.rs
+++ b/ui/src/lib.rs
@@ -30,6 +30,8 @@ mod widget;
 pub mod pbs;
 pub mod pve;
 
+pub mod sdn;
+
 pub mod renderer;
 
 mod tasks;
diff --git a/ui/src/sdn/evpn/mod.rs b/ui/src/sdn/evpn/mod.rs
new file mode 100644
index 0000000..0745f52
--- /dev/null
+++ b/ui/src/sdn/evpn/mod.rs
@@ -0,0 +1,2 @@
+mod vrf_tree;
+pub use vrf_tree::VrfTree;
diff --git a/ui/src/sdn/evpn/vrf_tree.rs b/ui/src/sdn/evpn/vrf_tree.rs
new file mode 100644
index 0000000..5e8005c
--- /dev/null
+++ b/ui/src/sdn/evpn/vrf_tree.rs
@@ -0,0 +1,291 @@
+use std::cmp::Ordering;
+use std::collections::HashMap;
+use std::rc::Rc;
+
+use pdm_client::types::{ListController, ListVnet, ListZone, Remote, SdnObjectState};
+use pwt::css;
+use pwt::props::{ContainerBuilder, EventSubscriber, ExtractPrimaryKey, WidgetBuilder};
+use pwt::state::{Selection, SlabTree, TreeStore};
+use pwt::tr;
+use pwt::widget::data_table::{
+    DataTable, DataTableCellRenderArgs, DataTableColumn, DataTableHeader, DataTableRowRenderArgs,
+};
+use pwt::widget::{Button, Column, Container, Fa, Row, Toolbar};
+use pwt_macros::widget;
+use yew::virtual_dom::Key;
+use yew::{html, Callback, Component, Context, Html, MouseEvent, Properties};
+
+#[widget(comp=VrfTreeComponent)]
+#[derive(Clone, PartialEq, Properties)]
+pub struct VrfTree {
+    zones: Rc<Vec<ListZone>>,
+    vnets: Rc<Vec<ListVnet>>,
+    remotes: Rc<Vec<Remote>>,
+    controllers: Rc<Vec<ListController>>,
+    on_add: Callback<MouseEvent>,
+    on_add_vnet: Callback<MouseEvent>,
+}
+
+impl VrfTree {
+    pub fn new(
+        zones: Rc<Vec<ListZone>>,
+        vnets: Rc<Vec<ListVnet>>,
+        remotes: Rc<Vec<Remote>>,
+        controllers: Rc<Vec<ListController>>,
+        on_add: Callback<MouseEvent>,
+        on_add_vnet: Callback<MouseEvent>,
+    ) -> Self {
+        yew::props!(Self {
+            zones,
+            vnets,
+            remotes,
+            controllers,
+            on_add,
+            on_add_vnet,
+        })
+    }
+}
+
+pub enum VrfTreeMsg {
+    SelectionChange,
+}
+
+#[derive(Clone, PartialEq, Debug)]
+pub enum VrfTreeEntry {
+    Root(Key),
+    Vrf {
+        vni: u32,
+    },
+    Remote {
+        id: String,
+        zone: String,
+        state: Option<SdnObjectState>,
+    },
+    Vnet {
+        id: String,
+        remote: String,
+        vxlan_id: u32,
+        state: Option<SdnObjectState>,
+    },
+}
+
+impl ExtractPrimaryKey for VrfTreeEntry {
+    fn extract_key(&self) -> Key {
+        match self {
+            Self::Root(key) => key.clone(),
+            Self::Vrf { vni } => Key::from(vni.to_string()),
+            Self::Remote { id, zone, .. } => Key::from(format!("{}/{}", id, zone)),
+            Self::Vnet {
+                id,
+                remote,
+                vxlan_id,
+                ..
+            } => Key::from(format!("{}/{}/{}", id, remote, vxlan_id)),
+        }
+    }
+}
+
+fn zones_to_vrf_view(zones: &[ListZone], vnets: &[ListVnet]) -> SlabTree<VrfTreeEntry> {
+    let mut tree = SlabTree::new();
+
+    let mut vrfs = HashMap::new();
+    let mut zone_vnets = HashMap::new();
+
+    for zone in zones {
+        vrfs.entry(zone.zone.vrf_vxlan.expect("EVPN zone has a VXLAN ID"))
+            .or_insert(Vec::new())
+            .push(zone);
+    }
+
+    for vnet in vnets {
+        zone_vnets
+            .entry(format!("{}/{}", vnet.remote, vnet.vnet.zone_pending()))
+            .or_insert(Vec::new())
+            .push(vnet);
+    }
+
+    let mut root = tree.set_root(VrfTreeEntry::Root(Key::from("root")));
+    root.set_expanded(true);
+
+    for (vni, zones) in vrfs {
+        let mut vrf_entry = root.append(VrfTreeEntry::Vrf { vni });
+        vrf_entry.set_expanded(true);
+
+        for zone in zones {
+            let mut remote_entry = vrf_entry.append(VrfTreeEntry::Remote {
+                id: zone.remote.clone(),
+                zone: zone.zone.zone.clone(),
+                state: zone.zone.state,
+            });
+
+            remote_entry.set_expanded(true);
+
+            let key = format!("{}/{}", zone.remote, zone.zone.zone);
+            if let Some(vnets) = zone_vnets.get(&key) {
+                for vnet in vnets {
+                    remote_entry.append(VrfTreeEntry::Vnet {
+                        id: vnet.vnet.vnet.clone(),
+                        remote: vnet.remote.clone(),
+                        vxlan_id: vnet.vnet.tag_pending().expect("EVPN VNet has a tag."),
+                        state: vnet.vnet.state,
+                    });
+                }
+            }
+        }
+    }
+
+    tree
+}
+
+fn render_vxlan(args: &mut DataTableCellRenderArgs<VrfTreeEntry>) -> Html {
+    match args.record() {
+        VrfTreeEntry::Vnet { vxlan_id, .. } => vxlan_id.to_string().as_str().into(),
+        _ => html! {},
+    }
+}
+
+fn render_zone(args: &mut DataTableCellRenderArgs<VrfTreeEntry>) -> Html {
+    match args.record() {
+        VrfTreeEntry::Remote { zone, .. } => zone.as_str().into(),
+        _ => html! {},
+    }
+}
+
+fn render_remote_or_vrf(args: &mut DataTableCellRenderArgs<VrfTreeEntry>) -> Html {
+    let mut row = Row::new().class(css::AlignItems::Baseline).gap(2);
+
+    row = match args.record() {
+        VrfTreeEntry::Vrf { vni } => row
+            .with_child(Fa::new("th"))
+            .with_child(format!("VRF {vni}")),
+        VrfTreeEntry::Remote { id, .. } => {
+            row.with_child(Fa::new("server")).with_child(id.as_str())
+        }
+        VrfTreeEntry::Vnet { id, .. } => row
+            .with_child(Fa::new("network-wired"))
+            .with_child(id.as_str()),
+        _ => row,
+    };
+
+    row.into()
+}
+
+fn render_state(args: &mut DataTableCellRenderArgs<VrfTreeEntry>) -> Html {
+    let state = match args.record() {
+        VrfTreeEntry::Remote { state, .. } => *state,
+        VrfTreeEntry::Vnet { state, .. } => *state,
+        _ => None,
+    };
+
+    match state {
+        Some(SdnObjectState::New) => "new",
+        Some(SdnObjectState::Changed) => "changed",
+        Some(SdnObjectState::Deleted) => "deleted",
+        None => "",
+    }
+    .into()
+}
+
+fn vrf_sorter(a: &VrfTreeEntry, b: &VrfTreeEntry) -> Ordering {
+    match (a, b) {
+        (VrfTreeEntry::Vrf { vni: vni_a }, VrfTreeEntry::Vrf { vni: vni_b }) => vni_a.cmp(vni_b),
+        (VrfTreeEntry::Remote { id: id_a, .. }, VrfTreeEntry::Remote { id: id_b, .. }) => {
+            id_a.cmp(id_b)
+        }
+        (
+            VrfTreeEntry::Vnet {
+                vxlan_id: vxlan_id_a,
+                ..
+            },
+            VrfTreeEntry::Vnet {
+                vxlan_id: vxlan_id_b,
+                ..
+            },
+        ) => vxlan_id_a.cmp(vxlan_id_b),
+        (_, _) => std::cmp::Ordering::Equal,
+    }
+}
+
+pub struct VrfTreeComponent {
+    store: TreeStore<VrfTreeEntry>,
+    selection: Selection,
+}
+
+impl VrfTreeComponent {
+    fn columns(store: TreeStore<VrfTreeEntry>) -> Rc<Vec<DataTableHeader<VrfTreeEntry>>> {
+        Rc::new(vec![
+            DataTableColumn::new(tr!("VRF / Remote"))
+                .tree_column(store)
+                .render_cell(render_remote_or_vrf)
+                .sorter(vrf_sorter)
+                .into(),
+            DataTableColumn::new(tr!("Zone"))
+                .render_cell(render_zone)
+                .into(),
+            DataTableColumn::new(tr!("VXLAN"))
+                .render_cell(render_vxlan)
+                .into(),
+            DataTableColumn::new(tr!("State"))
+                .render_cell(render_state)
+                .into(),
+        ])
+    }
+}
+
+impl Component for VrfTreeComponent {
+    type Properties = VrfTree;
+    type Message = VrfTreeMsg;
+
+    fn create(ctx: &Context<Self>) -> Self {
+        let store = TreeStore::new().view_root(false);
+        store.set_sorter(vrf_sorter);
+
+        let selection =
+            Selection::new().on_select(ctx.link().callback(|_| Self::Message::SelectionChange));
+
+        Self { store, selection }
+    }
+
+    fn view(&self, ctx: &Context<Self>) -> Html {
+        let toolbar = Toolbar::new()
+            .class("pwt-w-100")
+            .class("pwt-overflow-hidden")
+            .class("pwt-border-bottom")
+            .with_child(Button::new(tr!("Add")).onclick(ctx.props().on_add.clone()))
+            .with_child(Button::new(tr!("Add VNet")).onclick(ctx.props().on_add_vnet.clone()));
+
+        let columns = Self::columns(self.store.clone());
+
+        let table = DataTable::new(columns, self.store.clone())
+            .selection(self.selection.clone())
+            .striped(false)
+            .row_render_callback(|args: &mut DataTableRowRenderArgs<VrfTreeEntry>| {
+                if let VrfTreeEntry::Vrf { .. } = args.record() {
+                    args.add_class("pwt-bg-color-surface");
+                }
+            })
+            .class(css::FlexFit);
+
+        Container::new()
+            .class(css::FlexFit)
+            .with_child(
+                Column::new()
+                    .class(css::FlexFit)
+                    .with_child(toolbar)
+                    .with_child(table),
+            )
+            .into()
+    }
+
+    fn changed(&mut self, ctx: &Context<Self>, old_props: &Self::Properties) -> bool {
+        if !Rc::ptr_eq(&ctx.props().zones, &old_props.zones) {
+            let data = zones_to_vrf_view(&ctx.props().zones, &ctx.props().vnets);
+            self.store.set_data(data);
+            self.store.set_sorter(vrf_sorter);
+
+            return true;
+        }
+
+        false
+    }
+}
diff --git a/ui/src/sdn/mod.rs b/ui/src/sdn/mod.rs
new file mode 100644
index 0000000..ef2eab9
--- /dev/null
+++ b/ui/src/sdn/mod.rs
@@ -0,0 +1 @@
+pub mod evpn;
-- 
2.39.5


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


  parent reply	other threads:[~2025-02-28 15:18 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 15:17 [pdm-devel] [RFC proxmox{-api-types, -yew-comp, -datacenter-manager} 00/26] Add initial SDN / EVPN integration Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 01/12] sdn: add list/create zone endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 02/12] sdn: generate zones endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 03/12] sdn: add list/create vnet endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 04/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 05/12] sdn: add list/create controller endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 06/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 07/12] sdn: add acquire/release lock endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 08/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 09/12] sdn: add apply configuration endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 10/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 11/12] tasks: add helper for querying successfully finished tasks Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 12/12] sdn: add helpers for pending values Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-yew-comp 1/1] sdn: add descriptions for sdn tasks Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 01/13] server: add locked sdn client and helper methods Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 02/13] api: sdn: add list_zones endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 03/13] api: sdn: add create_zone endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 04/13] api: sdn: add list_vnets endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 05/13] api: sdn: add create_vnet endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 06/13] api: sdn: add list_controllers endpoint Stefan Hanreich
2025-02-28 15:17 ` Stefan Hanreich [this message]
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 08/13] ui: sdn: add RouterTable component Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 09/13] ui: sdn: add AddVnetWindow component Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 10/13] ui: sdn: add AddZoneWindow component Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 11/13] ui: sdn: add EvpnPanel Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 12/13] ui: sdn: add EvpnPanel to main menu Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 13/13] pve: sdn: add descriptions for sdn tasks Stefan Hanreich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250228151803.158984-21-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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