diff options
Diffstat (limited to 'src/protocol/mpls.rs')
| -rw-r--r-- | src/protocol/mpls.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/protocol/mpls.rs b/src/protocol/mpls.rs index e6a7a37..add686d 100644 --- a/src/protocol/mpls.rs +++ b/src/protocol/mpls.rs @@ -10,7 +10,7 @@ use nom::IResult; ******************************************************************************/ #[derive(Clone, Debug, PartialEq, Eq)] -pub struct MplsHeader { +pub struct MPLSHeader { pub label: u32, pub experimental: u8, pub bottom_of_stack: bool, @@ -19,7 +19,7 @@ pub struct MplsHeader { #[derive(Clone, Debug, PartialEq, Eq)] // Ethernet pseudowire (PW) https://tools.ietf.org/html/rfc4448#section-3.1 -pub struct PwEthHeader { +pub struct PWEthHeader { pub control_word: u32, } @@ -36,14 +36,14 @@ fn bit_decode(input: &[u8]) -> IResult<&[u8], (u32, u8, u8, u8)> { )))(input) } -impl Decode for MplsHeader { - type Iterm = MplsHeader; - fn decode(input: &[u8]) -> IResult<&[u8], MplsHeader> { +impl Decode for MPLSHeader { + type Iterm = MPLSHeader; + fn decode(input: &[u8]) -> IResult<&[u8], MPLSHeader> { let (input, (label, experimental, bottom_of_stack, ttl)) = bit_decode(input)?; Ok(( input, - MplsHeader { + MPLSHeader { label, experimental, bottom_of_stack: bottom_of_stack == 1, @@ -53,12 +53,12 @@ impl Decode for MplsHeader { } } -impl Decode for PwEthHeader { - type Iterm = PwEthHeader; - fn decode(input: &[u8]) -> IResult<&[u8], PwEthHeader> { +impl Decode for PWEthHeader { + type Iterm = PWEthHeader; + fn decode(input: &[u8]) -> IResult<&[u8], PWEthHeader> { let (input, control_word) = number::streaming::be_u32(input)?; - Ok((input, PwEthHeader { control_word })) + Ok((input, PWEthHeader { control_word })) } } @@ -68,7 +68,7 @@ impl Decode for PwEthHeader { #[cfg(test)] mod tests { - use super::MplsHeader; + use super::MPLSHeader; use crate::protocol::codec::Decode; const LAST_SLICE: &'static [u8] = &[0xff]; @@ -89,28 +89,28 @@ mod tests { let bytes = [0x00, 0x01, 0x2a, 0xff, 0x00, 0x01, 0x0b, 0xff, 0xff]; - let expectation1 = MplsHeader { + let expectation1 = MPLSHeader { label: 18, experimental: 5, bottom_of_stack: false, ttl: 255, }; - let expectation2 = MplsHeader { + let expectation2 = MPLSHeader { label: 16, experimental: 5, bottom_of_stack: true, ttl: 255, }; - assert_eq!(MplsHeader::decode(&bytes), Ok((&bytes[4..], expectation1))); + assert_eq!(MPLSHeader::decode(&bytes), Ok((&bytes[4..], expectation1))); assert_eq!( - MplsHeader::decode(&bytes[4..]), + MPLSHeader::decode(&bytes[4..]), Ok((LAST_SLICE, expectation2)) ); // example let mut payload = &bytes[..]; - while let Ok((remain, header)) = MplsHeader::decode(payload) { + while let Ok((remain, header)) = MPLSHeader::decode(payload) { println!("return: {:?}, payload: {}", header, remain.len()); payload = remain; if header.bottom_of_stack { |
