netlink_packet_route/rtnl/neighbour_table/nlas/
stats.rs1use netlink_packet_utils::{
4 traits::{Emitable, Parseable},
5 DecodeError,
6};
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq)]
9#[non_exhaustive]
10pub struct Stats {
11 pub allocs: u64,
12 pub destroys: u64,
13 pub hash_grows: u64,
14 pub res_failed: u64,
15 pub lookups: u64,
16 pub hits: u64,
17 pub multicast_probes_received: u64,
18 pub unicast_probes_received: u64,
19 pub periodic_gc_runs: u64,
20 pub forced_gc_runs: u64,
21}
22
23pub const STATS_LEN: usize = 80;
24buffer!(StatsBuffer(STATS_LEN) {
25 allocs: (u64, 0..8),
26 destroys: (u64, 8..16),
27 hash_grows: (u64, 16..24),
28 res_failed: (u64, 24..32),
29 lookups: (u64, 32..40),
30 hits: (u64, 40..48),
31 multicast_probes_received: (u64, 48..56),
32 unicast_probes_received: (u64, 56..64),
33 periodic_gc_runs: (u64, 64..72),
34 forced_gc_runs: (u64, 72..80),
35});
36
37impl<T: AsRef<[u8]>> Parseable<StatsBuffer<T>> for Stats {
38 fn parse(buf: &StatsBuffer<T>) -> Result<Self, DecodeError> {
39 Ok(Self {
40 allocs: buf.allocs(),
41 destroys: buf.destroys(),
42 hash_grows: buf.hash_grows(),
43 res_failed: buf.res_failed(),
44 lookups: buf.lookups(),
45 hits: buf.hits(),
46 multicast_probes_received: buf.multicast_probes_received(),
47 unicast_probes_received: buf.unicast_probes_received(),
48 periodic_gc_runs: buf.periodic_gc_runs(),
49 forced_gc_runs: buf.forced_gc_runs(),
50 })
51 }
52}
53
54impl Emitable for Stats {
55 fn buffer_len(&self) -> usize {
56 STATS_LEN
57 }
58
59 fn emit(&self, buffer: &mut [u8]) {
60 let mut buffer = StatsBuffer::new(buffer);
61 buffer.set_allocs(self.allocs);
62 buffer.set_destroys(self.destroys);
63 buffer.set_hash_grows(self.hash_grows);
64 buffer.set_res_failed(self.res_failed);
65 buffer.set_lookups(self.lookups);
66 buffer.set_hits(self.hits);
67 buffer.set_multicast_probes_received(self.multicast_probes_received);
68 buffer.set_unicast_probes_received(self.unicast_probes_received);
69 buffer.set_periodic_gc_runs(self.periodic_gc_runs);
70 buffer.set_forced_gc_runs(self.forced_gc_runs);
71 }
72}