netlink_packet_route/rtnl/link/nlas/
stats64.rs

1// SPDX-License-Identifier: MIT
2
3use crate::{
4    traits::{Emitable, Parseable},
5    DecodeError,
6};
7
8pub const LINK_STATS64_LEN: usize = 192;
9buffer!(Stats64Buffer(LINK_STATS64_LEN) {
10    rx_packets: (u64, 0..8),
11    tx_packets: (u64, 8..16),
12    rx_bytes: (u64, 16..24),
13    tx_bytes: (u64, 24..32),
14    rx_errors: (u64, 32..40),
15    tx_errors: (u64, 40..48),
16    rx_dropped: (u64, 48..56),
17    tx_dropped: (u64, 56..64),
18    multicast: (u64, 64..72),
19    collisions: (u64, 72..80),
20    rx_length_errors: (u64, 80..88),
21    rx_over_errors: (u64, 88..96),
22    rx_crc_errors: (u64, 96..104),
23    rx_frame_errors: (u64, 104..112),
24    rx_fifo_errors: (u64, 112..120),
25    rx_missed_errors: (u64, 120..128),
26    tx_aborted_errors: (u64, 128..136),
27    tx_carrier_errors: (u64, 136..144),
28    tx_fifo_errors: (u64, 144..152),
29    tx_heartbeat_errors: (u64, 152..160),
30    tx_window_errors: (u64, 160..168),
31    rx_compressed: (u64, 168..176),
32    tx_compressed: (u64, 176..184),
33    rx_nohandler: (u64, 184..192),
34});
35
36#[derive(Debug, Clone, Copy, Eq, PartialEq)]
37pub struct Stats64 {
38    /// total packets received
39    pub rx_packets: u64,
40    /// total packets transmitted
41    pub tx_packets: u64,
42    /// total bytes received
43    pub rx_bytes: u64,
44    /// total bytes transmitted
45    pub tx_bytes: u64,
46    /// bad packets received
47    pub rx_errors: u64,
48    /// packet transmit problems
49    pub tx_errors: u64,
50    /// no space in linux buffers
51    pub rx_dropped: u64,
52    /// no space available in linux
53    pub tx_dropped: u64,
54    /// multicast packets received
55    pub multicast: u64,
56    pub collisions: u64,
57
58    // detailed rx_errors
59    pub rx_length_errors: u64,
60    /// receiver ring buff overflow
61    pub rx_over_errors: u64,
62    /// received packets with crc error
63    pub rx_crc_errors: u64,
64    /// received frame alignment errors
65    pub rx_frame_errors: u64,
66    /// recv'r fifo overrun
67    pub rx_fifo_errors: u64,
68    /// receiver missed packet
69    pub rx_missed_errors: u64,
70
71    // detailed tx_errors
72    pub tx_aborted_errors: u64,
73    pub tx_carrier_errors: u64,
74    pub tx_fifo_errors: u64,
75    pub tx_heartbeat_errors: u64,
76    pub tx_window_errors: u64,
77
78    // for cslip etc
79    pub rx_compressed: u64,
80    pub tx_compressed: u64,
81
82    /// dropped, no handler found
83    pub rx_nohandler: u64,
84}
85
86impl<T: AsRef<[u8]>> Parseable<Stats64Buffer<T>> for Stats64 {
87    fn parse(buf: &Stats64Buffer<T>) -> Result<Self, DecodeError> {
88        Ok(Self {
89            rx_packets: buf.rx_packets(),
90            tx_packets: buf.tx_packets(),
91            rx_bytes: buf.rx_bytes(),
92            tx_bytes: buf.tx_bytes(),
93            rx_errors: buf.rx_errors(),
94            tx_errors: buf.tx_errors(),
95            rx_dropped: buf.rx_dropped(),
96            tx_dropped: buf.tx_dropped(),
97            multicast: buf.multicast(),
98            collisions: buf.collisions(),
99            rx_length_errors: buf.rx_length_errors(),
100            rx_over_errors: buf.rx_over_errors(),
101            rx_crc_errors: buf.rx_crc_errors(),
102            rx_frame_errors: buf.rx_frame_errors(),
103            rx_fifo_errors: buf.rx_fifo_errors(),
104            rx_missed_errors: buf.rx_missed_errors(),
105            tx_aborted_errors: buf.tx_aborted_errors(),
106            tx_carrier_errors: buf.tx_carrier_errors(),
107            tx_fifo_errors: buf.tx_fifo_errors(),
108            tx_heartbeat_errors: buf.tx_heartbeat_errors(),
109            tx_window_errors: buf.tx_window_errors(),
110            rx_compressed: buf.rx_compressed(),
111            tx_compressed: buf.tx_compressed(),
112            rx_nohandler: buf.rx_nohandler(),
113        })
114    }
115}
116
117impl Emitable for Stats64 {
118    fn buffer_len(&self) -> usize {
119        LINK_STATS64_LEN
120    }
121
122    fn emit(&self, buffer: &mut [u8]) {
123        let mut buffer = Stats64Buffer::new(buffer);
124        buffer.set_rx_packets(self.rx_packets);
125        buffer.set_tx_packets(self.tx_packets);
126        buffer.set_rx_bytes(self.rx_bytes);
127        buffer.set_tx_bytes(self.tx_bytes);
128        buffer.set_rx_errors(self.rx_errors);
129        buffer.set_tx_errors(self.tx_errors);
130        buffer.set_rx_dropped(self.rx_dropped);
131        buffer.set_tx_dropped(self.tx_dropped);
132        buffer.set_multicast(self.multicast);
133        buffer.set_collisions(self.collisions);
134        buffer.set_rx_length_errors(self.rx_length_errors);
135        buffer.set_rx_over_errors(self.rx_over_errors);
136        buffer.set_rx_crc_errors(self.rx_crc_errors);
137        buffer.set_rx_frame_errors(self.rx_frame_errors);
138        buffer.set_rx_fifo_errors(self.rx_fifo_errors);
139        buffer.set_rx_missed_errors(self.rx_missed_errors);
140        buffer.set_tx_aborted_errors(self.tx_aborted_errors);
141        buffer.set_tx_carrier_errors(self.tx_carrier_errors);
142        buffer.set_tx_fifo_errors(self.tx_fifo_errors);
143        buffer.set_tx_heartbeat_errors(self.tx_heartbeat_errors);
144        buffer.set_tx_window_errors(self.tx_window_errors);
145        buffer.set_rx_compressed(self.rx_compressed);
146        buffer.set_tx_compressed(self.tx_compressed);
147        buffer.set_rx_nohandler(self.rx_nohandler);
148    }
149}