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