mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Bandwidth overrides are correctly applied.
This commit is contained in:
parent
1c0aba7c78
commit
631b9672f5
@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use tracing::{error, info};
|
||||
use crate::uisp_types::UispSite;
|
||||
|
||||
pub type BandwidthOverrides = HashMap<String, (f32, f32)>;
|
||||
|
||||
@ -27,14 +28,28 @@ pub fn get_site_bandwidth_overrides(
|
||||
}
|
||||
let mut reader = reader.unwrap();
|
||||
let mut overrides = HashMap::new();
|
||||
for result in reader.deserialize::<IntegrationBandwidthRow>() {
|
||||
for (line, result) in reader.records().enumerate() {
|
||||
if let Ok(result) = result {
|
||||
overrides.insert(
|
||||
result.parent_node,
|
||||
(result.download_mbps, result.upload_mbps),
|
||||
);
|
||||
if result.len() != 3 {
|
||||
error!("Wrong number of records on line {line}");
|
||||
continue;
|
||||
}
|
||||
let parent_node = result[0].to_string();
|
||||
if let Ok(d) = &result[1].parse::<f32>() {
|
||||
if let Ok(u) = &result[2].parse::<f32>() {
|
||||
overrides.insert(parent_node, (*d, *u));
|
||||
} else {
|
||||
error!("Cannot parse {} as float on line {line}", &result[2]);
|
||||
}
|
||||
} else {
|
||||
error!("Cannot parse {} as float on line {line}", &result[1]);
|
||||
}
|
||||
} else {
|
||||
error!("Error reading integrationUISPbandwidths.csv line");
|
||||
error!("{result:?}");
|
||||
}
|
||||
}
|
||||
|
||||
info!("Loaded {} bandwidth overrides", overrides.len());
|
||||
return Ok(overrides);
|
||||
}
|
||||
@ -43,12 +58,13 @@ pub fn get_site_bandwidth_overrides(
|
||||
Ok(HashMap::new())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct IntegrationBandwidthRow {
|
||||
#[serde(rename = "ParentNode")]
|
||||
pub parent_node: String,
|
||||
#[serde(rename = "Download Mbs")]
|
||||
pub download_mbps: f32,
|
||||
#[serde(rename = "Upload Mbps")]
|
||||
pub upload_mbps: f32,
|
||||
}
|
||||
pub fn apply_bandwidth_overrides(sites: &mut Vec<UispSite>, bandwidth_overrides: &BandwidthOverrides) {
|
||||
for site in sites.iter_mut() {
|
||||
if let Some((up, down)) = bandwidth_overrides.get(&site.name) {
|
||||
tracing::info!("Bandwidth override for {} applied", &site.name);
|
||||
// Apply the overrides
|
||||
site.max_down_mbps = *down as u32;
|
||||
site.max_up_mbps = *up as u32;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ mod zero_capacity_sites;
|
||||
use crate::errors::UispIntegrationError;
|
||||
use crate::ip_ranges::IpRanges;
|
||||
use crate::strategies::full::ap_promotion::promote_access_points;
|
||||
use crate::strategies::full::bandwidth_overrides::get_site_bandwidth_overrides;
|
||||
use crate::strategies::full::bandwidth_overrides::{apply_bandwidth_overrides, get_site_bandwidth_overrides};
|
||||
use crate::strategies::full::client_site_promotion::promote_clients_with_children;
|
||||
use crate::strategies::full::network_json::write_network_file;
|
||||
use crate::strategies::full::parse::parse_uisp_datasets;
|
||||
@ -49,7 +49,6 @@ pub async fn build_full_network(
|
||||
&data_links_raw,
|
||||
&devices_raw,
|
||||
&config,
|
||||
&bandwidth_overrides,
|
||||
&ip_ranges,
|
||||
);
|
||||
|
||||
@ -96,6 +95,9 @@ pub async fn build_full_network(
|
||||
// Build Path Weights
|
||||
walk_tree_for_routing(&mut sites, &root_site, &routing_overrides)?;
|
||||
|
||||
// Apply bandwidth overrides
|
||||
apply_bandwidth_overrides(&mut sites, &bandwidth_overrides);
|
||||
|
||||
// Correct any sites with zero capacity
|
||||
correct_zero_capacity_sites(&mut sites, &config);
|
||||
|
||||
|
@ -10,11 +10,10 @@ pub fn parse_uisp_datasets(
|
||||
data_links_raw: &[DataLink],
|
||||
devices_raw: &[Device],
|
||||
config: &Config,
|
||||
bandwidth_overrides: &BandwidthOverrides,
|
||||
ip_ranges: &IpRanges,
|
||||
) -> (Vec<UispSite>, Vec<UispDataLink>, Vec<UispDevice>) {
|
||||
let (mut sites, data_links, devices) = (
|
||||
parse_sites(sites_raw, config, bandwidth_overrides),
|
||||
parse_sites(sites_raw, config),
|
||||
parse_data_links(data_links_raw, devices_raw),
|
||||
parse_devices(devices_raw, config, ip_ranges),
|
||||
);
|
||||
@ -36,11 +35,10 @@ pub fn parse_uisp_datasets(
|
||||
fn parse_sites(
|
||||
sites_raw: &[Site],
|
||||
config: &Config,
|
||||
bandwidth_overrides: &BandwidthOverrides,
|
||||
) -> Vec<UispSite> {
|
||||
let mut sites: Vec<UispSite> = sites_raw
|
||||
.iter()
|
||||
.map(|s| UispSite::from_uisp(s, &config, bandwidth_overrides))
|
||||
.map(|s| UispSite::from_uisp(s, &config))
|
||||
.collect();
|
||||
info!("{} sites have been successfully parsed", sites.len());
|
||||
sites
|
||||
|
@ -44,7 +44,6 @@ impl UispSite {
|
||||
pub fn from_uisp(
|
||||
value: &Site,
|
||||
config: &Config,
|
||||
bandwidth_overrides: &BandwidthOverrides,
|
||||
) -> Self {
|
||||
let mut uisp_parent_id = None;
|
||||
|
||||
@ -84,12 +83,6 @@ impl UispSite {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((up, down)) = bandwidth_overrides.get(&value.name_or_blank()) {
|
||||
// Apply the overrides
|
||||
max_down_mbps = *down as u32;
|
||||
max_up_mbps = *up as u32;
|
||||
}
|
||||
|
||||
Self {
|
||||
id: value.id.clone(),
|
||||
name: value.name_or_blank(),
|
||||
|
Loading…
Reference in New Issue
Block a user