From 0835cd9281b8e4ee421e9b4185a1cea0b727fe06 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Thu, 3 Apr 2025 16:41:34 -0500 Subject: [PATCH] The calculated graph is included in the submission blob. Route overrides are now applied as "FROM NAME", "TO NAME", "BANDWIDTH" --- src/rust/Cargo.lock | 2 ++ src/rust/uisp_integration/Cargo.toml | 2 +- .../uisp_integration/src/strategies/full2.rs | 25 ++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index a4f75c8f..365108b7 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -2591,6 +2591,8 @@ checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" dependencies = [ "fixedbitset", "indexmap", + "serde", + "serde_derive", ] [[package]] diff --git a/src/rust/uisp_integration/Cargo.toml b/src/rust/uisp_integration/Cargo.toml index 69f91697..a9cdd794 100644 --- a/src/rust/uisp_integration/Cargo.toml +++ b/src/rust/uisp_integration/Cargo.toml @@ -20,4 +20,4 @@ ip_network_table = { workspace = true } ip_network = { workspace = true } serde_cbor = { workspace = true } lqos_bus = { path = "../lqos_bus" } -petgraph = "0.7.1" +petgraph = { version = "0.7.1", features = ["serde-1"] } diff --git a/src/rust/uisp_integration/src/strategies/full2.rs b/src/rust/uisp_integration/src/strategies/full2.rs index 846f5287..da2fad22 100644 --- a/src/rust/uisp_integration/src/strategies/full2.rs +++ b/src/rust/uisp_integration/src/strategies/full2.rs @@ -10,9 +10,12 @@ use std::sync::Arc; use petgraph::Undirected; use tracing::{error, info, warn}; use petgraph::visit::{EdgeRef, NodeRef}; +use serde::Serialize; +use crate::blackboard_blob; +use crate::strategies::full::routes_override::RouteOverride; use crate::strategies::full::shaped_devices_writer::ShapedDevice; -#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone)] +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Serialize)] pub enum GraphMapping { Root { name: String, id: String }, Site { name: String, id: String }, @@ -31,7 +34,7 @@ impl GraphMapping { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub enum LinkMapping { Ethernet, DevicePair(String, String), @@ -214,6 +217,7 @@ pub async fn build_full_network_v2( // Visualizer save_dot_file(&graph)?; + let _ = blackboard_blob("UISP-Graph", &graph).await; // Figure out the network.json layers let mut parents = HashMap::new(); @@ -228,7 +232,7 @@ pub async fn build_full_network_v2( &graph, root_idx, |n| n == node, - |e| (10_000u64).saturating_sub(link_capacity_mbps(&e.weight(), &uisp_data.devices)), + |e| (10_000u64).saturating_sub(link_capacity_mbps(&e.weight(), &uisp_data.devices, &routing_overrides)), |_| 0, ).unwrap_or((0, vec![])); @@ -418,15 +422,24 @@ fn network_json_capacity( } -fn link_capacity_mbps(link_mapping: &LinkMapping, devices: &[UispDevice]) -> u64 { +fn link_capacity_mbps(link_mapping: &LinkMapping, devices: &[UispDevice], route_overrides: &[RouteOverride]) -> u64 { match link_mapping { LinkMapping::Ethernet => 10_000, LinkMapping::DevicePair(device_a, device_b) => { let capacity ; + if let Some(device_a) = devices.iter().find(|d| d.id == *device_a) { - capacity = device_a.download; + if let Some(override_a) = route_overrides.iter().find(|o| o.from_site == device_a.name) { + capacity = override_a.cost as u64; + } else { + capacity = device_a.download; + } } else if let Some(device_b) = devices.iter().find(|d| d.id == *device_b) { - capacity = device_b.download; + if let Some(override_b) = route_overrides.iter().find(|o| o.from_site == device_b.name) { + capacity = override_b.cost as u64; + } else { + capacity = device_b.download; + } } else { capacity = 10_000; } -- knotmirror 0.0.1