Skip to content

Commit 23b6819

Browse files
author
Valentin Obst
committed
samples/rust: add minimal CCA
Add an example that uses the `module_cca` macro and the `Algorithm` trait to implement a minimal CCA. IMPORTANT: This CCA is not compliant with the relevant RFCs and must not be used outside of test environments.
1 parent 9ccd6e0 commit 23b6819

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

samples/rust/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ config SAMPLE_RUST_PRINT
3030

3131
If unsure, say N.
3232

33+
config SAMPLE_RUST_CCA
34+
tristate "Congestion control algorithm"
35+
help
36+
This option builds the Rust congestion control algorithm sample.
37+
38+
To compile this as a module, choose M here:
39+
the module will be called rust_cca.
40+
41+
If unsure, say N.
42+
3343
config SAMPLE_RUST_HOSTPROGS
3444
bool "Host programs"
3545
help

samples/rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
44
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
5+
obj-$(CONFIG_SAMPLE_RUST_CCA) += rust_cca.o
56

67
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs

samples/rust/rust_cca.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! Congestion control algorithm example.
2+
use core::num::NonZeroU32;
3+
use kernel::net::tcp::cong::*;
4+
use kernel::prelude::*;
5+
use kernel::{c_str, module_cca};
6+
7+
struct MyCca {}
8+
9+
#[vtable]
10+
impl Algorithm for MyCca {
11+
type Data = ();
12+
13+
const NAME: &'static CStr = c_str!("my_cca");
14+
15+
fn undo_cwnd(sk: &mut Sock<'_, Self>) -> u32 {
16+
reno::undo_cwnd(sk)
17+
}
18+
19+
fn ssthresh(_sk: &mut Sock<'_, Self>) -> u32 {
20+
2
21+
}
22+
23+
fn cong_avoid(sk: &mut Sock<'_, Self>, _ack: u32, acked: u32) {
24+
sk.tcp_sk_mut()
25+
.cong_avoid_ai(NonZeroU32::new(1).unwrap(), acked)
26+
}
27+
}
28+
29+
module_cca! {
30+
type: MyCca,
31+
name: "my_cca",
32+
author: "Rust for Linux Contributors",
33+
description: "Sample congestion control algorithm implemented in Rust.",
34+
license: "GPL v2",
35+
}

0 commit comments

Comments
 (0)