netlink_packet_route/rtnl/tc/nlas/
stats.rs1use crate::{
4 traits::{Emitable, Parseable},
5 DecodeError,
6};
7
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
10pub struct Stats {
11 pub bytes: u64,
13 pub packets: u32,
15 pub drops: u32,
17 pub overlimits: u32,
19 pub bps: u32,
21 pub pps: u32,
23 pub qlen: u32,
24 pub backlog: u32,
25}
26
27pub const STATS_LEN: usize = 36;
28
29buffer!(StatsBuffer(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<StatsBuffer<T>> for Stats {
41 fn parse(buf: &StatsBuffer<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 Stats {
56 fn buffer_len(&self) -> usize {
57 STATS_LEN
58 }
59
60 fn emit(&self, buffer: &mut [u8]) {
61 let mut buffer = StatsBuffer::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}