Skip to main content

flowparser_sflow/samples/
discarded_packet.rs

1use nom::IResult;
2use nom::number::complete::be_u32;
3use serde::{Deserialize, Serialize};
4
5use crate::flow_records::{FlowRecord, parse_flow_records};
6
7/// Discarded packet notification sample (enterprise=0, format=5).
8///
9/// Reports packets discarded by the switch, along with the reason
10/// and flow records describing the discarded packet.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct DiscardedPacket {
13    pub sequence_number: u32,
14    pub ds_class: u32,
15    pub ds_index: u32,
16    pub drops: u32,
17    pub input: u32,
18    pub output: u32,
19    pub reason: u32,
20    pub records: Vec<FlowRecord>,
21}
22
23pub(crate) fn parse_discarded_packet(input: &[u8]) -> IResult<&[u8], DiscardedPacket> {
24    let (input, sequence_number) = be_u32(input)?;
25    let (input, source_id) = be_u32(input)?;
26    let ds_class = source_id >> 24;
27    let ds_index = source_id & 0x00FF_FFFF;
28    let (input, drops) = be_u32(input)?;
29    let (input, input_if) = be_u32(input)?;
30    let (input, output_if) = be_u32(input)?;
31    let (input, reason) = be_u32(input)?;
32    let (input, num_records) = be_u32(input)?;
33
34    let (input, records) = parse_flow_records(input, num_records)?;
35
36    Ok((
37        input,
38        DiscardedPacket {
39            sequence_number,
40            ds_class,
41            ds_index,
42            drops,
43            input: input_if,
44            output: output_if,
45            reason,
46            records,
47        },
48    ))
49}