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