netlink_packet_route/link/
stats64.rs1use netlink_packet_utils::{
4 traits::{Emitable, Parseable},
5 DecodeError,
6};
7
8pub(crate) const LINK_STATS64_LEN: usize = 200;
9
10buffer!(Stats64Buffer(LINK_STATS64_LEN) {
11 rx_packets: (u64, 0..8),
12 tx_packets: (u64, 8..16),
13 rx_bytes: (u64, 16..24),
14 tx_bytes: (u64, 24..32),
15 rx_errors: (u64, 32..40),
16 tx_errors: (u64, 40..48),
17 rx_dropped: (u64, 48..56),
18 tx_dropped: (u64, 56..64),
19 multicast: (u64, 64..72),
20 collisions: (u64, 72..80),
21 rx_length_errors: (u64, 80..88),
22 rx_over_errors: (u64, 88..96),
23 rx_crc_errors: (u64, 96..104),
24 rx_frame_errors: (u64, 104..112),
25 rx_fifo_errors: (u64, 112..120),
26 rx_missed_errors: (u64, 120..128),
27 tx_aborted_errors: (u64, 128..136),
28 tx_carrier_errors: (u64, 136..144),
29 tx_fifo_errors: (u64, 144..152),
30 tx_heartbeat_errors: (u64, 152..160),
31 tx_window_errors: (u64, 160..168),
32 rx_compressed: (u64, 168..176),
33 tx_compressed: (u64, 176..184),
34 rx_nohandler: (u64, 184..192),
35 rx_otherhost_dropped: (u64, 192..200),
36});
37
38#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
39#[non_exhaustive]
40pub struct Stats64 {
41 pub rx_packets: u64,
43 pub tx_packets: u64,
45 pub rx_bytes: u64,
47 pub tx_bytes: u64,
49 pub rx_errors: u64,
51 pub tx_errors: u64,
53 pub rx_dropped: u64,
55 pub tx_dropped: u64,
57 pub multicast: u64,
59 pub collisions: u64,
60
61 pub rx_length_errors: u64,
63 pub rx_over_errors: u64,
65 pub rx_crc_errors: u64,
67 pub rx_frame_errors: u64,
69 pub rx_fifo_errors: u64,
71 pub rx_missed_errors: u64,
73
74 pub tx_aborted_errors: u64,
76 pub tx_carrier_errors: u64,
77 pub tx_fifo_errors: u64,
78 pub tx_heartbeat_errors: u64,
79 pub tx_window_errors: u64,
80
81 pub rx_compressed: u64,
83 pub tx_compressed: u64,
84
85 pub rx_nohandler: u64,
87
88 pub rx_otherhost_dropped: u64,
89}
90
91impl<T: AsRef<[u8]>> Parseable<Stats64Buffer<T>> for Stats64 {
92 fn parse(buf: &Stats64Buffer<T>) -> Result<Self, DecodeError> {
93 Ok(Self {
94 rx_packets: buf.rx_packets(),
95 tx_packets: buf.tx_packets(),
96 rx_bytes: buf.rx_bytes(),
97 tx_bytes: buf.tx_bytes(),
98 rx_errors: buf.rx_errors(),
99 tx_errors: buf.tx_errors(),
100 rx_dropped: buf.rx_dropped(),
101 tx_dropped: buf.tx_dropped(),
102 multicast: buf.multicast(),
103 collisions: buf.collisions(),
104 rx_length_errors: buf.rx_length_errors(),
105 rx_over_errors: buf.rx_over_errors(),
106 rx_crc_errors: buf.rx_crc_errors(),
107 rx_frame_errors: buf.rx_frame_errors(),
108 rx_fifo_errors: buf.rx_fifo_errors(),
109 rx_missed_errors: buf.rx_missed_errors(),
110 tx_aborted_errors: buf.tx_aborted_errors(),
111 tx_carrier_errors: buf.tx_carrier_errors(),
112 tx_fifo_errors: buf.tx_fifo_errors(),
113 tx_heartbeat_errors: buf.tx_heartbeat_errors(),
114 tx_window_errors: buf.tx_window_errors(),
115 rx_compressed: buf.rx_compressed(),
116 tx_compressed: buf.tx_compressed(),
117 rx_nohandler: buf.rx_nohandler(),
118 rx_otherhost_dropped: buf.rx_otherhost_dropped(),
119 })
120 }
121}
122
123impl Emitable for Stats64 {
124 fn buffer_len(&self) -> usize {
125 LINK_STATS64_LEN
126 }
127
128 fn emit(&self, buffer: &mut [u8]) {
129 let mut buffer = Stats64Buffer::new(buffer);
130 buffer.set_rx_packets(self.rx_packets);
131 buffer.set_tx_packets(self.tx_packets);
132 buffer.set_rx_bytes(self.rx_bytes);
133 buffer.set_tx_bytes(self.tx_bytes);
134 buffer.set_rx_errors(self.rx_errors);
135 buffer.set_tx_errors(self.tx_errors);
136 buffer.set_rx_dropped(self.rx_dropped);
137 buffer.set_tx_dropped(self.tx_dropped);
138 buffer.set_multicast(self.multicast);
139 buffer.set_collisions(self.collisions);
140 buffer.set_rx_length_errors(self.rx_length_errors);
141 buffer.set_rx_over_errors(self.rx_over_errors);
142 buffer.set_rx_crc_errors(self.rx_crc_errors);
143 buffer.set_rx_frame_errors(self.rx_frame_errors);
144 buffer.set_rx_fifo_errors(self.rx_fifo_errors);
145 buffer.set_rx_missed_errors(self.rx_missed_errors);
146 buffer.set_tx_aborted_errors(self.tx_aborted_errors);
147 buffer.set_tx_carrier_errors(self.tx_carrier_errors);
148 buffer.set_tx_fifo_errors(self.tx_fifo_errors);
149 buffer.set_tx_heartbeat_errors(self.tx_heartbeat_errors);
150 buffer.set_tx_window_errors(self.tx_window_errors);
151 buffer.set_rx_compressed(self.rx_compressed);
152 buffer.set_tx_compressed(self.tx_compressed);
153 buffer.set_rx_nohandler(self.rx_nohandler);
154 buffer.set_rx_otherhost_dropped(self.rx_otherhost_dropped);
155 }
156}