Skip to content

Commit ed4d777

Browse files
committed
add examples
1 parent ae9cd31 commit ed4d777

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

examples/dump_channels.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
use futures::stream::TryStreamExt;
4+
5+
// Once we find a way to load netsimdev kernel module in CI, we can convert this
6+
// to a test
7+
fn main() {
8+
let rt = tokio::runtime::Builder::new_current_thread()
9+
.enable_io()
10+
.build()
11+
.unwrap();
12+
rt.block_on(get_channels(None));
13+
}
14+
15+
async fn get_channels(iface_name: Option<&str>) {
16+
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
17+
tokio::spawn(connection);
18+
19+
let mut channel_handle = handle.channel().get(iface_name).execute().await;
20+
21+
let mut msgs = Vec::new();
22+
while let Some(msg) = channel_handle.try_next().await.unwrap() {
23+
msgs.push(msg);
24+
}
25+
assert!(!msgs.is_empty());
26+
for msg in msgs {
27+
println!("{msg:?}");
28+
}
29+
}

examples/set_rx_count.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
use std::env;
4+
5+
// Once we find a way to load netsimdev kernel module in CI, we can convert this
6+
// to a test
7+
fn main() {
8+
let args: Vec<String> = env::args().collect();
9+
if args.len() != 2 {
10+
usage();
11+
return;
12+
}
13+
let link_name = &args[1];
14+
let rt = tokio::runtime::Builder::new_current_thread()
15+
.enable_io()
16+
.build()
17+
.unwrap();
18+
rt.block_on(set_rx_count(link_name));
19+
}
20+
21+
async fn set_rx_count(iface_name: &str) {
22+
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
23+
tokio::spawn(connection);
24+
25+
let result = handle.channel().set(iface_name).rx_count(4).execute().await;
26+
27+
if let Err(error) = result {
28+
panic!("{:?}", error);
29+
}
30+
}
31+
32+
fn usage() {
33+
eprintln!(
34+
"usage:
35+
cargo run --example set_rx_count -- <link name>
36+
37+
Note that you need to run this program as root. Instead of running cargo as root,
38+
build the example normally:
39+
40+
cd ethtool ; cargo build --example set_rx_count
41+
42+
Then find the binary in the target directory:
43+
44+
cd target/debug/example ; sudo ./set_rx_count <link_name>"
45+
);
46+
}

0 commit comments

Comments
 (0)