netlink_packet_route/tc/stats/
compat.rs
1use netlink_packet_utils::traits::{Emitable, Parseable};
4use netlink_packet_utils::DecodeError;
5
6#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
8#[non_exhaustive]
9pub struct TcStats {
10 pub bytes: u64,
12 pub packets: u32,
14 pub drops: u32,
16 pub overlimits: u32,
19 pub bps: u32,
21 pub pps: u32,
23 pub qlen: u32,
24 pub backlog: u32,
25}
26
27const STATS_LEN: usize = 40;
29
30buffer!(TcStatsBuffer(STATS_LEN) {
31 bytes: (u64, 0..8),
32 packets: (u32, 8..12),
33 drops: (u32, 12..16),
34 overlimits: (u32, 16..20),
35 bps: (u32, 20..24),
36 pps: (u32, 24..28),
37 qlen: (u32, 28..32),
38 backlog: (u32, 32..36),
39});
40
41impl<T: AsRef<[u8]>> Parseable<TcStatsBuffer<T>> for TcStats {
42 type Error = DecodeError;
43 fn parse(buf: &TcStatsBuffer<T>) -> Result<Self, DecodeError> {
44 Ok(Self {
45 bytes: buf.bytes(),
46 packets: buf.packets(),
47 drops: buf.drops(),
48 overlimits: buf.overlimits(),
49 bps: buf.bps(),
50 pps: buf.pps(),
51 qlen: buf.qlen(),
52 backlog: buf.backlog(),
53 })
54 }
55}
56
57impl Emitable for TcStats {
58 fn buffer_len(&self) -> usize {
59 STATS_LEN
60 }
61
62 fn emit(&self, buffer: &mut [u8]) {
63 let mut buffer = TcStatsBuffer::new(buffer);
64 buffer.set_bytes(self.bytes);
65 buffer.set_packets(self.packets);
66 buffer.set_drops(self.drops);
67 buffer.set_overlimits(self.overlimits);
68 buffer.set_bps(self.bps);
69 buffer.set_pps(self.pps);
70 buffer.set_qlen(self.qlen);
71 buffer.set_backlog(self.backlog);
72 }
73}