netlink_packet_route/rtnl/tc/nlas/
stats.rs1use netlink_packet_utils::{
4 traits::{Emitable, Parseable},
5 DecodeError,
6};
7
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
10#[non_exhaustive]
11pub struct Stats {
12 pub bytes: u64,
14 pub packets: u32,
16 pub drops: u32,
18 pub overlimits: u32,
21 pub bps: u32,
23 pub pps: u32,
25 pub qlen: u32,
26 pub backlog: u32,
27}
28
29pub const STATS_LEN: usize = 36;
30
31buffer!(StatsBuffer(STATS_LEN) {
32 bytes: (u64, 0..8),
33 packets: (u32, 8..12),
34 drops: (u32, 12..16),
35 overlimits: (u32, 16..20),
36 bps: (u32, 20..24),
37 pps: (u32, 24..28),
38 qlen: (u32, 28..32),
39 backlog: (u32, 32..36),
40});
41
42impl<T: AsRef<[u8]>> Parseable<StatsBuffer<T>> for Stats {
43 fn parse(buf: &StatsBuffer<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 Stats {
58 fn buffer_len(&self) -> usize {
59 STATS_LEN
60 }
61
62 fn emit(&self, buffer: &mut [u8]) {
63 let mut buffer = StatsBuffer::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}