From 8afdc2e0d136f7991edde6d76418d6c94a08acb8 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Thu, 5 Jan 2023 15:03:48 +0000 Subject: [PATCH] WIP - Basic interface and Bifrost config displayable. --- src/rust/Cargo.lock | 95 ++++++++- src/rust/lqos_config/src/etc.rs | 12 +- src/rust/lqos_config/src/libre_qos_config.rs | 2 + src/rust/lqos_node_manager/Cargo.toml | 1 + .../lqos_node_manager/src/config_control.rs | 38 +++- src/rust/lqos_node_manager/src/main.rs | 3 + src/rust/lqos_node_manager/static/config.html | 192 +++++++++++++----- 7 files changed, 282 insertions(+), 61 deletions(-) diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index 7b25b200..b5a6b92b 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -383,6 +383,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -543,6 +553,18 @@ dependencies = [ "cipher", ] +[[package]] +name = "default-net" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e349ed1e06fb344a7dd8b5a676375cf671b31e8900075dd2be816efc063a63" +dependencies = [ + "libc", + "memalloc", + "system-configuration", + "windows 0.30.0", +] + [[package]] name = "devise" version = "0.3.1" @@ -786,7 +808,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows", + "windows 0.39.0", ] [[package]] @@ -1202,6 +1224,7 @@ name = "lqos_node_manager" version = "0.1.0" dependencies = [ "anyhow", + "default-net", "lazy_static", "lqos_bus", "lqos_config", @@ -1278,6 +1301,12 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "memalloc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1" + [[package]] name = "memchr" version = "2.5.0" @@ -2209,6 +2238,27 @@ dependencies = [ "winapi", ] +[[package]] +name = "system-configuration" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75182f12f490e953596550b65ee31bda7c8e043d9386174b353bda50838c3fd" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "target-lexicon" version = "0.12.5" @@ -2594,6 +2644,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b749ebd2304aa012c5992d11a25d07b406bdbe5f79d371cb7a918ce501a19eb0" +dependencies = [ + "windows_aarch64_msvc 0.30.0", + "windows_i686_gnu 0.30.0", + "windows_i686_msvc 0.30.0", + "windows_x86_64_gnu 0.30.0", + "windows_x86_64_msvc 0.30.0", +] + [[package]] name = "windows" version = "0.39.0" @@ -2628,6 +2691,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29277a4435d642f775f63c7d1faeb927adba532886ce0287bd985bffb16b6bca" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -2640,6 +2709,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_i686_gnu" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1145e1989da93956c68d1864f32fb97c8f561a8f89a5125f6a2b7ea75524e4b8" + [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -2652,6 +2727,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a09e3a0d4753b73019db171c1339cd4362c8c44baf1bcea336235e955954a6" + [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -2664,6 +2745,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_x86_64_gnu" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca64fcb0220d58db4c119e050e7af03c69e6f4f415ef69ec1773d9aab422d5a" + [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -2682,6 +2769,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08cabc9f0066848fef4bc6a1c1668e6efce38b661d2aeec75d18d8617eebb5f1" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src/rust/lqos_config/src/etc.rs b/src/rust/lqos_config/src/etc.rs index c4cdfd58..aa9b70fe 100644 --- a/src/rust/lqos_config/src/etc.rs +++ b/src/rust/lqos_config/src/etc.rs @@ -1,15 +1,15 @@ use std::path::Path; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use anyhow::{Result, Error}; -#[derive(Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct EtcLqos { pub lqos_directory: String, pub bridge: Option, pub tuning: Option, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct Tunables { pub stop_irq_balance: bool, pub netdev_budget_usecs: u32, @@ -21,21 +21,21 @@ pub struct Tunables { pub disable_offload: Vec, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct BridgeConfig { pub use_kernel_bridge: bool, pub interface_mapping: Vec, pub vlan_mapping: Vec, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct BridgeInterface { pub name: String, pub scan_vlans: bool, pub redirect_to: String, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct BridgeVlan { pub parent: String, pub tag: u32, diff --git a/src/rust/lqos_config/src/libre_qos_config.rs b/src/rust/lqos_config/src/libre_qos_config.rs index 9c0d94c1..27ac7eb4 100644 --- a/src/rust/lqos_config/src/libre_qos_config.rs +++ b/src/rust/lqos_config/src/libre_qos_config.rs @@ -1,7 +1,9 @@ use anyhow::{Error, Result}; +use serde::{Serialize, Deserialize}; use std::{fs, path::{Path, PathBuf}}; use crate::etc; +#[derive(Serialize, Deserialize, Debug)] pub struct LibreQoSConfig { pub internet_interface: String, pub isp_interface: String, diff --git a/src/rust/lqos_node_manager/Cargo.toml b/src/rust/lqos_node_manager/Cargo.toml index c8003dcb..1dea81c4 100644 --- a/src/rust/lqos_node_manager/Cargo.toml +++ b/src/rust/lqos_node_manager/Cargo.toml @@ -17,3 +17,4 @@ lqos_config = { path = "../lqos_config" } anyhow = "1" sysinfo = "0" notify = { version = "5.0.0", default-features = false, feature=["macos_kqueue"] } # Not using crossbeam because of Tokio +default-net = "0" diff --git a/src/rust/lqos_node_manager/src/config_control.rs b/src/rust/lqos_node_manager/src/config_control.rs index cf2bd7e3..bfdd46fa 100644 --- a/src/rust/lqos_node_manager/src/config_control.rs +++ b/src/rust/lqos_node_manager/src/config_control.rs @@ -1,9 +1,43 @@ -use rocket::fs::NamedFile; -use crate::cache_control::{LongCache, NoCache}; +use default_net::get_interfaces; +use lqos_config::{LibreQoSConfig, EtcLqos}; +use rocket::{fs::NamedFile, serde::json::Json}; +use crate::cache_control::NoCache; // Note that NoCache can be replaced with a cache option // once the design work is complete. #[get("/config")] pub async fn config_page<'a>() -> NoCache> { NoCache::new(NamedFile::open("static/config.html").await.ok()) +} + +#[get("/api/list_nics")] +pub async fn get_nic_list<'a>() -> NoCache>> { + let mut result = Vec::new(); + for eth in get_interfaces().iter() { + let mac = if let Some(mac) = ð.mac_addr { + mac.to_string() + } else { + String::new() + }; + result.push(( + eth.name.clone(), + format!("{:?}", eth.if_type), + mac, + )); + } + NoCache::new(Json(result)) +} + +#[get("/api/python_config")] +pub async fn get_current_python_config() -> NoCache> { + let config = lqos_config::LibreQoSConfig::load().unwrap(); + println!("{:#?}", config); + NoCache::new(Json(config)) +} + +#[get("/api/lqosd_config")] +pub async fn get_current_lqosd_config() -> NoCache> { + let config = lqos_config::EtcLqos::load().unwrap(); + println!("{:#?}", config); + NoCache::new(Json(config)) } \ No newline at end of file diff --git a/src/rust/lqos_node_manager/src/main.rs b/src/rust/lqos_node_manager/src/main.rs index 07b5e303..c31542bc 100644 --- a/src/rust/lqos_node_manager/src/main.rs +++ b/src/rust/lqos_node_manager/src/main.rs @@ -49,6 +49,9 @@ fn rocket() -> _ { unknown_devices::unknown_devices_range, queue_info::raw_queue_by_circuit, queue_info::run_btest, + config_control::get_nic_list, + config_control::get_current_python_config, + config_control::get_current_lqosd_config, // Supporting files static_pages::bootsrap_css, diff --git a/src/rust/lqos_node_manager/static/config.html b/src/rust/lqos_node_manager/static/config.html index 483ad901..5745fe60 100644 --- a/src/rust/lqos_node_manager/static/config.html +++ b/src/rust/lqos_node_manager/static/config.html @@ -55,6 +55,14 @@
Configuration
+ + +
-

Tuning Settings

+

Tuning Settings