1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! TC handle computation and common request infrastructure.
//!
//! TC handles are 32-bit values split into major:minor (16:16 bits). This module
//! provides utilities for computing handles according to our numbering scheme.
use TcHandle;
/// The offset added to peer IDs to compute HTB class minor numbers.
///
/// For peer ID `N`, the class minor/major (depending on the qdisc level) is `ID_OFFSET + N`. This
/// keeps class 1:1 reserved as the default (unimpaired) class.
pub const ID_OFFSET: u32 = 10;
/// Offset for netem qdisc major numbers (separate from TBF to avoid collisions).
pub const NETEM_MAJOR_OFFSET: u32 = 20;
/// Common fields shared by all qdisc/class/filter requests.
///
/// This struct captures the basic addressing information needed to target
/// a specific qdisc, class, or filter in the traffic control hierarchy.
/// Compute the HTB class handle for a destination peer.
///
/// # Handle Format
///
/// Returns `1:(10 + peer_id)` as a 32-bit handle.
///
/// # Example
///
/// ```
/// use linkem::tc::handle::htb_class_handle;
/// assert_eq!(htb_class_handle(2), 0x0001_000C); // 1:12
/// ```
/// Compute the TBF qdisc handle for a destination peer.
///
/// # Handle Format
///
/// Returns `(10 + peer_id):0` as a 32-bit handle.
/// Qdisc handles must have minor=0 (kernel rejects non-zero minor).
///
/// # Example
///
/// ```
/// use linkem::tc::handle::tbf_handle;
/// assert_eq!(tbf_handle(2), 0x000C_0000); // 12:0
/// ```
/// Compute the netem qdisc handle for a destination peer.
///
/// # Handle Format
///
/// Returns `(20 + peer_id):0` as a 32-bit handle.
/// Uses a different major offset than TBF to avoid handle collisions.
/// Qdisc handles must have minor=0 (kernel rejects non-zero minor).
///
/// # Example
///
/// ```
/// use linkem::tc::handle::netem_handle;
/// assert_eq!(netem_handle(2), 0x0016_0000); // 22:0
/// ```