Skip to main content

flowparser_sflow/flow_records/
extended_ib.rs

1use nom::IResult;
2use nom::bytes::complete::take;
3use nom::number::complete::be_u32;
4use serde::{Deserialize, Serialize};
5
6/// InfiniBand Local Routing Header (enterprise=0, format=1031).
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct ExtendedIbLrh {
9    pub src_vl: u32,
10    pub src_sl: u32,
11    pub src_dlid: u32,
12    pub src_slid: u32,
13    pub src_lnh: u32,
14    pub dst_vl: u32,
15    pub dst_sl: u32,
16    pub dst_dlid: u32,
17    pub dst_slid: u32,
18    pub dst_lnh: u32,
19}
20
21pub(crate) fn parse_extended_ib_lrh(input: &[u8]) -> IResult<&[u8], ExtendedIbLrh> {
22    let (input, src_vl) = be_u32(input)?;
23    let (input, src_sl) = be_u32(input)?;
24    let (input, src_dlid) = be_u32(input)?;
25    let (input, src_slid) = be_u32(input)?;
26    let (input, src_lnh) = be_u32(input)?;
27    let (input, dst_vl) = be_u32(input)?;
28    let (input, dst_sl) = be_u32(input)?;
29    let (input, dst_dlid) = be_u32(input)?;
30    let (input, dst_slid) = be_u32(input)?;
31    let (input, dst_lnh) = be_u32(input)?;
32
33    Ok((
34        input,
35        ExtendedIbLrh {
36            src_vl,
37            src_sl,
38            src_dlid,
39            src_slid,
40            src_lnh,
41            dst_vl,
42            dst_sl,
43            dst_dlid,
44            dst_slid,
45            dst_lnh,
46        },
47    ))
48}
49
50/// InfiniBand Global Routing Header (enterprise=0, format=1032).
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct ExtendedIbGrh {
53    pub flow_label: u32,
54    pub tc: u32,
55    pub s_gid: [u8; 16],
56    pub d_gid: [u8; 16],
57}
58
59pub(crate) fn parse_extended_ib_grh(input: &[u8]) -> IResult<&[u8], ExtendedIbGrh> {
60    let (input, flow_label) = be_u32(input)?;
61    let (input, tc) = be_u32(input)?;
62    let (input, s_gid_bytes) = take(16usize)(input)?;
63    let (input, d_gid_bytes) = take(16usize)(input)?;
64
65    let mut s_gid = [0u8; 16];
66    s_gid.copy_from_slice(s_gid_bytes);
67    let mut d_gid = [0u8; 16];
68    d_gid.copy_from_slice(d_gid_bytes);
69
70    Ok((
71        input,
72        ExtendedIbGrh {
73            flow_label,
74            tc,
75            s_gid,
76            d_gid,
77        },
78    ))
79}
80
81/// InfiniBand Base Transport Header (enterprise=0, format=1033).
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83pub struct ExtendedIbBrh {
84    pub pky: u32,
85    pub dst_qp: u32,
86}
87
88pub(crate) fn parse_extended_ib_brh(input: &[u8]) -> IResult<&[u8], ExtendedIbBrh> {
89    let (input, pky) = be_u32(input)?;
90    let (input, dst_qp) = be_u32(input)?;
91
92    Ok((input, ExtendedIbBrh { pky, dst_qp }))
93}