mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Move netlink-testing out of main - it's in a branch, where it belongs.
This commit is contained in:
146
src/rust/Cargo.lock
generated
146
src/rust/Cargo.lock
generated
@@ -253,12 +253,6 @@ version = "3.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
@@ -621,17 +615,6 @@ dependencies = [
|
||||
"windows 0.30.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "devise"
|
||||
version = "0.3.1"
|
||||
@@ -1335,7 +1318,7 @@ dependencies = [
|
||||
"log",
|
||||
"lqos_config",
|
||||
"lqos_utils",
|
||||
"nix 0.25.1",
|
||||
"nix",
|
||||
"serde",
|
||||
"tokio",
|
||||
]
|
||||
@@ -1418,7 +1401,7 @@ dependencies = [
|
||||
"log",
|
||||
"lqos_bus",
|
||||
"lqos_config",
|
||||
"nix 0.25.1",
|
||||
"nix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1441,7 +1424,7 @@ dependencies = [
|
||||
"lqos_config",
|
||||
"lqos_queue_tracker",
|
||||
"lqos_sys",
|
||||
"nix 0.25.1",
|
||||
"nix",
|
||||
"notify",
|
||||
"parking_lot 0.12.1",
|
||||
"rayon",
|
||||
@@ -1572,94 +1555,6 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-packet-core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "345b8ab5bd4e71a2986663e88c56856699d060e78e152e6e9d7966fcd5491297"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byteorder",
|
||||
"libc",
|
||||
"netlink-packet-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-packet-route"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5dee5ed749373c298237fe694eb0a51887f4cc1a27370c8464bac4382348f1a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"libc",
|
||||
"netlink-packet-core",
|
||||
"netlink-packet-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-packet-utils"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byteorder",
|
||||
"paste",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-proto"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65b4b14489ab424703c092062176d52ba55485a89c076b4f9db05092b7223aa6"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures",
|
||||
"log",
|
||||
"netlink-packet-core",
|
||||
"netlink-sys",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-sys"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures",
|
||||
"libc",
|
||||
"log",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink_testing"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"derivative",
|
||||
"futures-util",
|
||||
"rtnetlink",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.24.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.25.1"
|
||||
@@ -2288,21 +2183,6 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtnetlink"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46f1cfa18f8cebe685373a2697915d7e0db3b4554918bba118385e0f71f258a7"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"log",
|
||||
"netlink-packet-route",
|
||||
"netlink-proto",
|
||||
"nix 0.24.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
@@ -2616,26 +2496,6 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.4"
|
||||
|
||||
@@ -22,5 +22,4 @@ members = [
|
||||
"lqos_python", # Python bindings for using the Rust bus directly
|
||||
"webusers", # CLI control for managing the web user list
|
||||
"lqos_utils", # A collection of macros and helpers we find useful
|
||||
"netlink_testing", # Some work in progress to see if Rust and Netlink can talk
|
||||
]
|
||||
@@ -1,11 +0,0 @@
|
||||
[package]
|
||||
name = "netlink_testing"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
|
||||
rtnetlink = "0"
|
||||
futures-util = "0.3"
|
||||
bytemuck = "1"
|
||||
derivative = "2"
|
||||
@@ -1,204 +0,0 @@
|
||||
use std::{time::Instant, str::from_utf8};
|
||||
|
||||
use derivative::Derivative;
|
||||
use rtnetlink::{new_connection, packet::{TcMessage, tc::{Nla, Stats2}}};
|
||||
use futures_util::TryStreamExt;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug)]
|
||||
#[repr(u8)]
|
||||
enum TcaCakeStats {
|
||||
TCA_CAKE_STATS_INVALID = 0,
|
||||
TCA_CAKE_STATS_PAD = 1,
|
||||
TCA_CAKE_STATS_CAPACITY_ESTIMATE64 = 2,
|
||||
TCA_CAKE_STATS_MEMORY_LIMIT = 3,
|
||||
TCA_CAKE_STATS_MEMORY_USED =4,
|
||||
TCA_CAKE_STATS_AVG_NETOFF =5,
|
||||
TCA_CAKE_STATS_MIN_NETLEN =6,
|
||||
TCA_CAKE_STATS_MAX_NETLEN =7,
|
||||
TCA_CAKE_STATS_MIN_ADJLEN =8,
|
||||
TCA_CAKE_STATS_MAX_ADJLEN =9,
|
||||
TCA_CAKE_STATS_TIN_STATS =10,
|
||||
TCA_CAKE_STATS_DEFICIT =11,
|
||||
TCA_CAKE_STATS_COBALT_COUNT=12,
|
||||
TCA_CAKE_STATS_DROPPING=13,
|
||||
TCA_CAKE_STATS_DROP_NEXT_US=14,
|
||||
TCA_CAKE_STATS_P_DROP=15,
|
||||
TCA_CAKE_STATS_BLUE_TIMER_US=16,
|
||||
TCA_CAKE_STATS_MAX=17
|
||||
}
|
||||
|
||||
impl From<u8> for TcaCakeStats {
|
||||
fn from(n: u8) -> Self {
|
||||
match n {
|
||||
0 => Self::TCA_CAKE_STATS_INVALID,
|
||||
1 => Self::TCA_CAKE_STATS_PAD,
|
||||
2 => Self::TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
|
||||
3 => Self::TCA_CAKE_STATS_MEMORY_LIMIT,
|
||||
4 => Self::TCA_CAKE_STATS_MEMORY_USED,
|
||||
5 => Self::TCA_CAKE_STATS_AVG_NETOFF,
|
||||
6 => Self::TCA_CAKE_STATS_MIN_NETLEN,
|
||||
7 => Self::TCA_CAKE_STATS_MAX_NETLEN,
|
||||
8 => Self::TCA_CAKE_STATS_MIN_ADJLEN,
|
||||
9 => Self::TCA_CAKE_STATS_MAX_ADJLEN,
|
||||
10 => Self::TCA_CAKE_STATS_TIN_STATS,
|
||||
11 => Self::TCA_CAKE_STATS_DEFICIT,
|
||||
12 => Self::TCA_CAKE_STATS_COBALT_COUNT,
|
||||
13 => Self::TCA_CAKE_STATS_DROPPING,
|
||||
14 => Self::TCA_CAKE_STATS_DROP_NEXT_US,
|
||||
15 => Self::TCA_CAKE_STATS_P_DROP,
|
||||
16 => Self::TCA_CAKE_STATS_BLUE_TIMER_US,
|
||||
17 => Self::TCA_CAKE_STATS_MAX,
|
||||
_ => Self::TCA_CAKE_STATS_INVALID,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn slice_to_num(buff: &[u8]) -> u32 {
|
||||
u32::from_ne_bytes(
|
||||
buff.try_into().unwrap())
|
||||
}
|
||||
|
||||
fn slice_to_u16(buff: &[u8]) -> u16 {
|
||||
u16::from_ne_bytes(
|
||||
buff.try_into().unwrap())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), ()> {
|
||||
let (connection, handle, _) = new_connection().unwrap();
|
||||
tokio::spawn(connection);
|
||||
|
||||
let now = Instant::now();
|
||||
let mut result = handle.qdisc().get().index(3).execute();
|
||||
let elapsed = now.elapsed();
|
||||
println!("Time spent in NetLink API: {} nanoseconds", elapsed.as_nanos());
|
||||
let mut results = Vec::new();
|
||||
while let Ok(Some(result)) = result.try_next().await {
|
||||
results.push(result);
|
||||
}
|
||||
println!("Retrieved {} messages", results.len());
|
||||
println!("Time spent in NetLink API: {} nanoseconds", elapsed.as_nanos());
|
||||
|
||||
let mut i = 0;
|
||||
loop {
|
||||
let msg = format!("{:?}", results[i]);
|
||||
if msg.contains("cake") {
|
||||
println!("{msg}");
|
||||
for nlas in results[i].nlas.iter() {
|
||||
match nlas {
|
||||
Nla::Stats2(o) => {
|
||||
for stats in o.iter() {
|
||||
match stats {
|
||||
Stats2::StatsApp(o) => {
|
||||
println!("{:?}", o);
|
||||
|
||||
let size = std::mem::size_of::<CakeStats2>();
|
||||
println!("Size: {size} (vs buffer size {}", o.len());
|
||||
let data = bytemuck::cast_slice::<u8, CakeStats2>(&o[0 .. size])[0];
|
||||
println!("{:#?}", data);
|
||||
|
||||
/*let mut count = 0;
|
||||
while count < o.len() {
|
||||
//let field: TcaCakeStats = TcaCakeStats::from(o[count]);
|
||||
println!("{}", slice_to_num(&o[count .. count+4]) );
|
||||
count += 5;
|
||||
}*/
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
//break;
|
||||
}
|
||||
i+=1;
|
||||
if i > results.len()-1 { break; }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Debug)]
|
||||
struct CakeStats2 {
|
||||
capacity: Nla64,
|
||||
memory_limit: Nla32,
|
||||
memory_used: Nla32,
|
||||
avg_netoff: Nla32,
|
||||
max_netlen: Nla32,
|
||||
max_adjlen: Nla32,
|
||||
min_netlen: Nla32,
|
||||
min_adjlen: Nla32,
|
||||
#[derivative(Debug="ignore")]
|
||||
padding: [u8; 20],
|
||||
tins: [CakeTin; 4],
|
||||
}
|
||||
|
||||
unsafe impl bytemuck::Zeroable for CakeStats2 {}
|
||||
unsafe impl bytemuck::Pod for CakeStats2 {}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Debug)]
|
||||
struct CakeTin {
|
||||
threshold_rate64: Nla64,
|
||||
sent_bytes64: Nla64,
|
||||
backlog_bytes: Nla32,
|
||||
target_us: Nla32,
|
||||
interval_us: Nla32,
|
||||
sent_packets: Nla32,
|
||||
dropped_packets: Nla32,
|
||||
ecn_marked_packets: Nla32,
|
||||
acks_dropped_packets: Nla32,
|
||||
peak_delay_us: Nla32,
|
||||
avg_delay_us: Nla32,
|
||||
base_delay_us: Nla32,
|
||||
way_indirect_hits: Nla32,
|
||||
way_missed: Nla32,
|
||||
way_collisions: Nla32,
|
||||
sparse_flows: Nla32,
|
||||
bulk_flows: Nla32,
|
||||
unresponsive_flows: Nla32,
|
||||
max_skblen: Nla32,
|
||||
flow_quantum: Nla32,
|
||||
}
|
||||
|
||||
unsafe impl bytemuck::Zeroable for CakeTin {}
|
||||
unsafe impl bytemuck::Pod for CakeTin {}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Debug)]
|
||||
struct Nla64 {
|
||||
#[derivative(Debug="ignore")]
|
||||
length: u16,
|
||||
#[derivative(Debug="ignore")]
|
||||
nla_type: u16,
|
||||
value: u64,
|
||||
}
|
||||
|
||||
unsafe impl bytemuck::Zeroable for Nla64 {}
|
||||
unsafe impl bytemuck::Pod for Nla64 {}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Debug)]
|
||||
struct Nla32 {
|
||||
#[derivative(Debug="ignore")]
|
||||
length: u16,
|
||||
#[derivative(Debug="ignore")]
|
||||
nla_type: u16,
|
||||
value: u32,
|
||||
}
|
||||
|
||||
unsafe impl bytemuck::Zeroable for Nla32 {}
|
||||
unsafe impl bytemuck::Pod for Nla32 {}
|
||||
|
||||
Reference in New Issue
Block a user