netlink_packet_route/rtnl/neighbour_table/nlas/
stats.rs

1// SPDX-License-Identifier: MIT
2
3use crate::{
4    traits::{Emitable, Parseable},
5    DecodeError,
6};
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq)]
9pub struct Stats {
10    pub allocs: u64,
11    pub destroys: u64,
12    pub hash_grows: u64,
13    pub res_failed: u64,
14    pub lookups: u64,
15    pub hits: u64,
16    pub multicast_probes_received: u64,
17    pub unicast_probes_received: u64,
18    pub periodic_gc_runs: u64,
19    pub forced_gc_runs: u64,
20}
21
22pub const STATS_LEN: usize = 80;
23buffer!(StatsBuffer(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});
35
36impl<T: AsRef<[u8]>> Parseable<StatsBuffer<T>> for Stats {
37    fn parse(buf: &StatsBuffer<T>) -> Result<Self, DecodeError> {
38        Ok(Self {
39            allocs: buf.allocs(),
40            destroys: buf.destroys(),
41            hash_grows: buf.hash_grows(),
42            res_failed: buf.res_failed(),
43            lookups: buf.lookups(),
44            hits: buf.hits(),
45            multicast_probes_received: buf.multicast_probes_received(),
46            unicast_probes_received: buf.unicast_probes_received(),
47            periodic_gc_runs: buf.periodic_gc_runs(),
48            forced_gc_runs: buf.forced_gc_runs(),
49        })
50    }
51}
52
53impl Emitable for Stats {
54    fn buffer_len(&self) -> usize {
55        STATS_LEN
56    }
57
58    fn emit(&self, buffer: &mut [u8]) {
59        let mut buffer = StatsBuffer::new(buffer);
60        buffer.set_allocs(self.allocs);
61        buffer.set_destroys(self.destroys);
62        buffer.set_hash_grows(self.hash_grows);
63        buffer.set_res_failed(self.res_failed);
64        buffer.set_lookups(self.lookups);
65        buffer.set_hits(self.hits);
66        buffer.set_multicast_probes_received(self.multicast_probes_received);
67        buffer.set_unicast_probes_received(self.unicast_probes_received);
68        buffer.set_periodic_gc_runs(self.periodic_gc_runs);
69        buffer.set_forced_gc_runs(self.forced_gc_runs);
70    }
71}