diff options
Diffstat (limited to 'src/protocol/gtpv1.rs')
| -rw-r--r-- | src/protocol/gtpv1.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/protocol/gtpv1.rs b/src/protocol/gtpv1.rs index a38da21..9acfc0f 100644 --- a/src/protocol/gtpv1.rs +++ b/src/protocol/gtpv1.rs @@ -11,21 +11,21 @@ use nom::IResult; ******************************************************************************/ #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Gtpv1Option { +pub struct GTPv1Option { pub sequence_number: u16, // 16bit pub npdu_number: u8, // 8bit pub next_header_type: u8, // 8bit } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Gtpv1ExtensionHeader { +pub struct GTPv1ExtensionHeader { pub length: u8, // 8bit (单位4字节,包括长度/内容/下一扩展消息头字段) pub contents: Vec<u8>, pub next_header_type: u8, // 8bit } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Gtpv1Header { +pub struct GTPv1Header { pub version: u8, // 3bit 1: GTPv1 pub protocol_type: u8, // 1bit pub reserved: u8, // 1bit @@ -38,8 +38,8 @@ pub struct Gtpv1Header { pub teid: u32, // 32bit // extension_header_flag/sequence_number_flag/npdu_number_flag任意一个取值为1时options字段才存在 - pub options: Option<Gtpv1Option>, - pub extensions: Vec<Gtpv1ExtensionHeader>, + pub options: Option<GTPv1Option>, + pub extensions: Vec<GTPv1ExtensionHeader>, } /****************************************************************************** @@ -57,14 +57,14 @@ fn bit_decode(input: &[u8]) -> IResult<&[u8], (u8, u8, u8, u8, u8, u8)> { )))(input) } -fn option_decode(input: &[u8]) -> IResult<&[u8], Gtpv1Option> { +fn option_decode(input: &[u8]) -> IResult<&[u8], GTPv1Option> { let (input, sequence_number) = number::streaming::be_u16(input)?; let (input, npdu_number) = number::streaming::be_u8(input)?; let (input, next_header_type) = number::streaming::be_u8(input)?; Ok(( input, - Gtpv1Option { + GTPv1Option { sequence_number, npdu_number, next_header_type, @@ -72,7 +72,7 @@ fn option_decode(input: &[u8]) -> IResult<&[u8], Gtpv1Option> { )) } -fn extension_decode(input: &[u8]) -> IResult<&[u8], Gtpv1ExtensionHeader> { +fn extension_decode(input: &[u8]) -> IResult<&[u8], GTPv1ExtensionHeader> { let (input, length) = number::streaming::be_u8(input)?; if length * 4 < 2 { return Err(nom::Err::Incomplete(nom::Needed::new( @@ -83,7 +83,7 @@ fn extension_decode(input: &[u8]) -> IResult<&[u8], Gtpv1ExtensionHeader> { let (input, next_header_type) = number::streaming::be_u8(input)?; Ok(( input, - Gtpv1ExtensionHeader { + GTPv1ExtensionHeader { length, contents: contents.to_vec(), next_header_type, @@ -91,9 +91,9 @@ fn extension_decode(input: &[u8]) -> IResult<&[u8], Gtpv1ExtensionHeader> { )) } -impl Decode for Gtpv1Header { - type Iterm = Gtpv1Header; - fn decode(input: &[u8]) -> IResult<&[u8], Gtpv1Header> { +impl Decode for GTPv1Header { + type Iterm = GTPv1Header; + fn decode(input: &[u8]) -> IResult<&[u8], GTPv1Header> { let ( input, ( @@ -140,7 +140,7 @@ impl Decode for Gtpv1Header { Ok(( remain, - Gtpv1Header { + GTPv1Header { version, protocol_type, reserved, @@ -163,8 +163,8 @@ impl Decode for Gtpv1Header { #[cfg(test)] mod tests { - use super::Gtpv1ExtensionHeader; - use super::Gtpv1Header; + use super::GTPv1ExtensionHeader; + use super::GTPv1Header; use crate::protocol::codec::Decode; const LAST_SLICE: &'static [u8] = &[0xff]; @@ -188,7 +188,7 @@ mod tests { 0x30, 0xff, 0x00, 0x40, 0x1f, 0x54, 0xd4, 0xb5, 0xff, /* Payload */ ]; - let expectation = Gtpv1Header { + let expectation = GTPv1Header { version: 1, protocol_type: 1, reserved: 0, @@ -202,10 +202,10 @@ mod tests { extensions: vec![], }; - assert_eq!(Gtpv1Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(GTPv1Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = Gtpv1Header::decode(&bytes); + let result = GTPv1Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { @@ -246,7 +246,7 @@ mod tests { 0x01, 0x00, 0xff, /* Payload */ ]; - let expectation = Gtpv1Header { + let expectation = GTPv1Header { version: 1, protocol_type: 1, reserved: 0, @@ -256,22 +256,22 @@ mod tests { message_type: 0xff, message_length: 48, teid: 476419836, - options: Some(super::Gtpv1Option { + options: Some(super::GTPv1Option { sequence_number: 26425, npdu_number: 0, next_header_type: 0x85, }), - extensions: vec![Gtpv1ExtensionHeader { + extensions: vec![GTPv1ExtensionHeader { length: 1, contents: vec![0x10, 0x01], next_header_type: 0x00, }], }; - assert_eq!(Gtpv1Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(GTPv1Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = Gtpv1Header::decode(&bytes); + let result = GTPv1Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { |
