/// Utility function to parse a pair of BGP error code and subcode (both u8) into a defined struct.
Utility function to parse a pair of BGP error code and subcode (both u8) into a defined struct.
Utility function to parse a pair of BGP error code and subcode ( both u8 ) into a defined struct .
pub fn parse_error_codes(error_code: &u8, error_subcode: &u8) -> Result<BgpError, BgpErrorCodeParsingError> {
    match error_code {
        0 => {
            Ok(BgpError::Reserved)
        },
        1 => {
            match MessageHeaderErrorSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::MessageHeaderError(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        2 => {
            if [5,8,9,10].contains(error_subcode) {
                return Err(BgpErrorCodeParsingError::DeprecatedSubcode(*error_subcode))
            }
            match OpenMessageErrorSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::OpenMessageError(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        3 => {
            if [7].contains(error_subcode) {
                return Err(BgpErrorCodeParsingError::DeprecatedSubcode(*error_subcode))
            }
            match UpdateMessageErrorSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::UpdateMessageError(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        4 => {
            Ok(BgpError::HoldTimerExpired)
        },
        5 => {
            match BgpFiniteStateMachineErrorSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::BgpFiniteStateMachineError(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        6 => {
            match BgpCeaseNotificationMessageSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::BgpCeaseNotification(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        7 => {
            match BgpRouteRefreshMessageErrorSubcode::from_u8(*error_subcode){
                Some(v) => {
                    Ok(BgpError::BgpRouteFreshMessageError(v))
                },
                None => {
                    Err(BgpErrorCodeParsingError::UnknownSubcode(*error_subcode))
                }
            }
        },
        v => Err(BgpErrorCodeParsingError::UnknownCode(*v)),
    }
}
pub fn parse_error_codes ( error_code : & u8 , error_subcode : & u8 ) -> Result < BgpError , BgpErrorCodeParsingError > { match error_code { 0 => { Ok ( BgpError :: Reserved ) } , 1 => { match MessageHeaderErrorSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: MessageHeaderError ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , 2 => { if [ 5 , 8 , 9 , 10 ] . contains ( error_subcode ) { return Err ( BgpErrorCodeParsingError :: DeprecatedSubcode ( * error_subcode ) ) } match OpenMessageErrorSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: OpenMessageError ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , 3 => { if [ 7 ] . contains ( error_subcode ) { return Err ( BgpErrorCodeParsingError :: DeprecatedSubcode ( * error_subcode ) ) } match UpdateMessageErrorSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: UpdateMessageError ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , 4 => { Ok ( BgpError :: HoldTimerExpired ) } , 5 => { match BgpFiniteStateMachineErrorSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: BgpFiniteStateMachineError ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , 6 => { match BgpCeaseNotificationMessageSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: BgpCeaseNotification ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , 7 => { match BgpRouteRefreshMessageErrorSubcode :: from_u8 ( * error_subcode ) { Some ( v ) => { Ok ( BgpError :: BgpRouteFreshMessageError ( v ) ) } , None => { Err ( BgpErrorCodeParsingError :: UnknownSubcode ( * error_subcode ) ) } } } , v => Err ( BgpErrorCodeParsingError :: UnknownCode ( * v ) ) , } }
Utility function to parse a pair of BGP error code and subcode (both u8) into a defined struct.
Utility function to parse a pair of BGP error code and subcode ( both u8 ) into a defined struct .
error_code
&u8
error_subcode
&u8