netlink_packet_route/neighbour_table/
stats.rs

1// SPDX-License-Identifier: MIT
2
3use netlink_packet_utils::traits::{Emitable, Parseable};
4use netlink_packet_utils::DecodeError;
5
6#[derive(Debug, Clone, Copy, Eq, PartialEq)]
7#[non_exhaustive]
8pub struct NeighbourTableStats {
9    pub allocs: u64,
10    pub destroys: u64,
11    pub hash_grows: u64,
12    pub res_failed: u64,
13    pub lookups: u64,
14    pub hits: u64,
15    pub multicast_probes_received: u64,
16    pub unicast_probes_received: u64,
17    pub periodic_gc_runs: u64,
18    pub forced_gc_runs: u64,
19    pub table_fulls: u64,
20}
21
22pub const STATS_LEN: usize = 88;
23buffer!(NeighbourTableStatsBuffer(STATS_LEN) {
24    allocs: (u64, 0..8),
25    destroys: (u64, 8..16),
26    hash_grows: (u64, 16..24),
27    res_failed: (u64, 24..32),
28    lookups: (u64, 32..40),
29    hits: (u64, 40..48),
30    multicast_probes_received: (u64, 48..56),
31    unicast_probes_received: (u64, 56..64),
32    periodic_gc_runs: (u64, 64..72),
33    forced_gc_runs: (u64, 72..80),
34    table_fulls: (u64, 80..88),
35});
36
37impl<T: AsRef<[u8]>> Parseable<NeighbourTableStatsBuffer<T>> for NeighbourTableStats {
38    type Error = DecodeError;
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}