diff --git a/src/encoder/rib_encoder.rs b/src/encoder/rib_encoder.rs index f429ae7..2e4e560 100644 --- a/src/encoder/rib_encoder.rs +++ b/src/encoder/rib_encoder.rs @@ -152,8 +152,7 @@ mod tests { let mut cursor = Cursor::new(bytes.clone()); while cursor.has_remaining() { - let parsed = parse_mrt_record(&mut cursor).unwrap(); - dbg!(&parsed); + let _parsed = parse_mrt_record(&mut cursor).unwrap(); } // v6 @@ -168,8 +167,7 @@ mod tests { let mut cursor = Cursor::new(bytes.clone()); while cursor.has_remaining() { - let parsed = parse_mrt_record(&mut cursor).unwrap(); - dbg!(&parsed); + let _parsed = parse_mrt_record(&mut cursor).unwrap(); } } } diff --git a/src/encoder/updates_encoder.rs b/src/encoder/updates_encoder.rs index 57df5f7..5d1b965 100644 --- a/src/encoder/updates_encoder.rs +++ b/src/encoder/updates_encoder.rs @@ -96,8 +96,7 @@ mod tests { let mut cursor = Cursor::new(bytes.clone()); while cursor.has_remaining() { - let parsed = parse_mrt_record(&mut cursor).unwrap(); - dbg!(&parsed); + let _parsed = parse_mrt_record(&mut cursor).unwrap(); } } @@ -113,8 +112,7 @@ mod tests { let bytes = encoder.export_bytes(); let mut cursor = Cursor::new(bytes.clone()); while cursor.has_remaining() { - let parsed = parse_mrt_record(&mut cursor).unwrap(); - dbg!(&parsed); + let _parsed = parse_mrt_record(&mut cursor).unwrap(); } } } diff --git a/src/models/bgp/attributes/aspath.rs b/src/models/bgp/attributes/aspath.rs index 2690456..95eb70a 100644 --- a/src/models/bgp/attributes/aspath.rs +++ b/src/models/bgp/attributes/aspath.rs @@ -1072,7 +1072,6 @@ mod tests { fn test_get_collector() { let aspath = AsPath::from_sequence([1, 2, 3, 5]); let collector = aspath.get_collector_opt(); - dbg!(&collector); assert_eq!(collector.unwrap(), 1); let aspath = AsPath::from_segments(vec![AsPathSegment::set([7])]); diff --git a/src/parser/bmp/error.rs b/src/parser/bmp/error.rs index 17f2840..df3780b 100644 --- a/src/parser/bmp/error.rs +++ b/src/parser/bmp/error.rs @@ -1,7 +1,9 @@ use crate::bmp::messages::headers::BmpPeerType; use crate::bmp::messages::initiation_message::InitiationTlvType; +use crate::bmp::messages::peer_down_notification::PeerDownReason; +use crate::bmp::messages::peer_up_notification::PeerUpTlvType; use crate::bmp::messages::route_mirroring::RouteMirroringInfo; -use crate::bmp::messages::termination_message::TerminationTlvType; +use crate::bmp::messages::termination_message::{TerminationReason, TerminationTlvType}; use crate::bmp::messages::BmpMsgType; use crate::ParserError; use num_enum::TryFromPrimitiveError; @@ -12,6 +14,8 @@ use std::fmt::{Display, Formatter}; pub enum ParserBmpError { InvalidOpenBmpHeader, UnsupportedOpenBmpMessage, + UnknownTlvType, + UnknownTlvValue, CorruptedBmpMessage, TruncatedBmpMessage, } @@ -31,6 +35,12 @@ impl Display for ParserBmpError { ParserBmpError::TruncatedBmpMessage => { write!(f, "Truncated BMP message") } + ParserBmpError::UnknownTlvType => { + write!(f, "Unknown TLV type") + } + ParserBmpError::UnknownTlvValue => { + write!(f, "Unknown TLV value") + } } } } @@ -58,13 +68,19 @@ impl From> for ParserBmpError { impl From> for ParserBmpError { fn from(_: TryFromPrimitiveError) -> Self { - ParserBmpError::InvalidOpenBmpHeader + ParserBmpError::CorruptedBmpMessage } } impl From> for ParserBmpError { fn from(_: TryFromPrimitiveError) -> Self { - ParserBmpError::CorruptedBmpMessage + ParserBmpError::UnknownTlvType + } +} + +impl From> for ParserBmpError { + fn from(_: TryFromPrimitiveError) -> Self { + ParserBmpError::UnknownTlvType } } @@ -76,7 +92,19 @@ impl From> for ParserBmpError { impl From> for ParserBmpError { fn from(_: TryFromPrimitiveError) -> Self { - ParserBmpError::CorruptedBmpMessage + ParserBmpError::UnknownTlvType + } +} + +impl From> for ParserBmpError { + fn from(_: TryFromPrimitiveError) -> Self { + ParserBmpError::UnknownTlvValue + } +} + +impl From> for ParserBmpError { + fn from(_: TryFromPrimitiveError) -> Self { + ParserBmpError::UnknownTlvValue } } @@ -102,6 +130,14 @@ mod tests { ParserBmpError::TruncatedBmpMessage.to_string(), "Truncated BMP message" ); + assert_eq!( + ParserBmpError::UnknownTlvType.to_string(), + "Unknown TLV type" + ); + assert_eq!( + ParserBmpError::UnknownTlvValue.to_string(), + "Unknown TLV value" + ); } #[test] @@ -120,11 +156,11 @@ mod tests { ); assert_eq!( ParserBmpError::from(TryFromPrimitiveError::::new(0)), - ParserBmpError::InvalidOpenBmpHeader + ParserBmpError::CorruptedBmpMessage ); assert_eq!( ParserBmpError::from(TryFromPrimitiveError::::new(0)), - ParserBmpError::CorruptedBmpMessage + ParserBmpError::UnknownTlvType ); assert_eq!( ParserBmpError::from(TryFromPrimitiveError::::new(0)), @@ -132,7 +168,19 @@ mod tests { ); assert_eq!( ParserBmpError::from(TryFromPrimitiveError::::new(0)), - ParserBmpError::CorruptedBmpMessage + ParserBmpError::UnknownTlvType + ); + assert_eq!( + ParserBmpError::from(TryFromPrimitiveError::::new(0)), + ParserBmpError::UnknownTlvType + ); + assert_eq!( + ParserBmpError::from(TryFromPrimitiveError::::new(0)), + ParserBmpError::UnknownTlvValue + ); + assert_eq!( + ParserBmpError::from(TryFromPrimitiveError::::new(0)), + ParserBmpError::UnknownTlvValue ); } } diff --git a/src/parser/bmp/messages/headers.rs b/src/parser/bmp/messages/headers.rs index ad4f0e4..f22316e 100644 --- a/src/parser/bmp/messages/headers.rs +++ b/src/parser/bmp/messages/headers.rs @@ -95,7 +95,7 @@ pub fn parse_bmp_common_header(data: &mut Bytes) -> Result, } @@ -18,13 +18,15 @@ pub struct InitiationTlv { ///Type-Length-Value Type /// -/// For more, see: https://datatracker.ietf.org/doc/html/rfc1213 +/// https://www.iana.org/assignments/bmp-parameters/bmp-parameters.xhtml#initiation-peer-up-tlvs #[derive(Debug, TryFromPrimitive, IntoPrimitive, PartialEq, Clone, Copy)] #[repr(u16)] pub enum InitiationTlvType { String = 0, SysDescr = 1, SysName = 2, + VrTableName = 3, + AdminLabel = 4, } /// Parse BMP initiation message diff --git a/src/parser/bmp/messages/peer_down_notification.rs b/src/parser/bmp/messages/peer_down_notification.rs index 4993ec7..79a5c8d 100644 --- a/src/parser/bmp/messages/peer_down_notification.rs +++ b/src/parser/bmp/messages/peer_down_notification.rs @@ -1,20 +1,37 @@ use crate::parser::bmp::error::ParserBmpError; use crate::parser::ReadUtils; use bytes::{Buf, Bytes}; +use num_enum::{IntoPrimitive, TryFromPrimitive}; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct PeerDownNotification { - pub reason: u8, + pub reason: PeerDownReason, pub data: Option>, } +#[derive(Debug, TryFromPrimitive, IntoPrimitive, PartialEq, Clone, Copy)] +#[repr(u8)] +pub enum PeerDownReason { + Reserved = 0, + LocalSystemClosedNotificationPduFollows = 1, + LocalSystemClosedFsmEvenFollows = 2, + RemoteSystemClosedNotificationPduFollows = 3, + RemoteSystemsClosedNoData, + PeerDeConfigured = 5, + LocalSystemClosedTlvDataFollows = 6, +} + pub fn parse_peer_down_notification( data: &mut Bytes, ) -> Result { - let reason = data.read_u8()?; + let reason = PeerDownReason::try_from(data.read_u8()?)?; let bytes_left = data.remaining(); let data: Option> = match reason { - 1 => { + PeerDownReason::Reserved => match bytes_left { + 0 => None, + _ => Some(data.read_n_bytes(bytes_left)?), + }, + PeerDownReason::LocalSystemClosedNotificationPduFollows => { /* The local system closed the session. Following the Reason is a BGP PDU containing a BGP NOTIFICATION message that @@ -22,7 +39,7 @@ pub fn parse_peer_down_notification( */ Some(data.read_n_bytes(bytes_left)?) } - 2 => { + PeerDownReason::LocalSystemClosedFsmEvenFollows => { /* The local system closed the session. No notification message was sent. Following the reason code is a 2-byte field @@ -33,7 +50,7 @@ pub fn parse_peer_down_notification( */ Some(data.read_n_bytes(bytes_left)?) } - 3 => { + PeerDownReason::RemoteSystemClosedNotificationPduFollows => { /* The remote system closed the session with a notification message. Following the Reason is a BGP PDU containing the BGP @@ -41,7 +58,7 @@ pub fn parse_peer_down_notification( */ Some(data.read_n_bytes(bytes_left)?) } - 4 => { + PeerDownReason::RemoteSystemsClosedNoData => { /* The remote system closed the session without a notification message. This includes any unexpected termination of @@ -50,7 +67,7 @@ pub fn parse_peer_down_notification( */ None } - 5 => { + PeerDownReason::PeerDeConfigured => { /* Information for this peer will no longer be sent to the monitoring station for configuration reasons. This does not, @@ -60,7 +77,14 @@ pub fn parse_peer_down_notification( */ None } - _ => return Err(ParserBmpError::CorruptedBmpMessage), + PeerDownReason::LocalSystemClosedTlvDataFollows => { + /* + https://www.rfc-editor.org/rfc/rfc9069.html#name-peer-down-notification + The Peer Down notification MUST use reason code 6. Following the reason + is data in TLV format. The following Peer Down Information TLV type is defined: + */ + Some(data.read_n_bytes(bytes_left)?) + } }; Ok(PeerDownNotification { reason, data }) } @@ -80,7 +104,10 @@ mod tests { let result = parse_peer_down_notification(&mut data); assert!(result.is_ok()); let peer_down_notification = result.unwrap(); - assert_eq!(peer_down_notification.reason, 1); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::LocalSystemClosedNotificationPduFollows + ); assert_eq!(peer_down_notification.data.unwrap(), vec![0u8; 10]); // Test with reason `2` @@ -91,7 +118,10 @@ mod tests { let result = parse_peer_down_notification(&mut data); assert!(result.is_ok()); let peer_down_notification = result.unwrap(); - assert_eq!(peer_down_notification.reason, 2); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::LocalSystemClosedFsmEvenFollows + ); assert_eq!(peer_down_notification.data.unwrap(), vec![0u8; 10]); // Test with reason `3` @@ -102,7 +132,10 @@ mod tests { let result = parse_peer_down_notification(&mut data); assert!(result.is_ok()); let peer_down_notification = result.unwrap(); - assert_eq!(peer_down_notification.reason, 3); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::RemoteSystemClosedNotificationPduFollows + ); assert_eq!(peer_down_notification.data.unwrap(), vec![0u8; 10]); // Test with reason `4` @@ -112,7 +145,10 @@ mod tests { let result = parse_peer_down_notification(&mut data); assert!(result.is_ok()); let peer_down_notification = result.unwrap(); - assert_eq!(peer_down_notification.reason, 4); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::RemoteSystemsClosedNoData + ); assert!(peer_down_notification.data.is_none()); // Test with reason `5` @@ -122,12 +158,29 @@ mod tests { let result = parse_peer_down_notification(&mut data); assert!(result.is_ok()); let peer_down_notification = result.unwrap(); - assert_eq!(peer_down_notification.reason, 5); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::PeerDeConfigured + ); assert!(peer_down_notification.data.is_none()); - // Test with invalid reason + // Test with reason `5` let mut data = bytes::BytesMut::new(); data.put_u8(6); + data.put_slice(&[0u8; 10]); + let mut data = data.freeze(); + let result = parse_peer_down_notification(&mut data); + assert!(result.is_ok()); + let peer_down_notification = result.unwrap(); + assert_eq!( + peer_down_notification.reason, + PeerDownReason::LocalSystemClosedTlvDataFollows + ); + assert_eq!(peer_down_notification.data.unwrap(), vec![0u8; 10]); + + // Test with invalid reason + let mut data = bytes::BytesMut::new(); + data.put_u8(7); let mut data = data.freeze(); let result = parse_peer_down_notification(&mut data); assert!(result.is_err()); diff --git a/src/parser/bmp/messages/peer_up_notification.rs b/src/parser/bmp/messages/peer_up_notification.rs index faf1011..978ed76 100644 --- a/src/parser/bmp/messages/peer_up_notification.rs +++ b/src/parser/bmp/messages/peer_up_notification.rs @@ -3,9 +3,10 @@ use crate::models::*; use crate::parser::bmp::error::ParserBmpError; use crate::parser::ReadUtils; use bytes::{Buf, Bytes}; +use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::net::IpAddr; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct PeerUpNotification { pub local_addr: IpAddr, pub local_port: u16, @@ -15,9 +16,22 @@ pub struct PeerUpNotification { pub tlvs: Vec, } -#[derive(Debug)] +///Type-Length-Value Type +/// +/// https://www.iana.org/assignments/bmp-parameters/bmp-parameters.xhtml#initiation-peer-up-tlvs +#[derive(Debug, TryFromPrimitive, IntoPrimitive, PartialEq, Clone, Copy)] +#[repr(u16)] +pub enum PeerUpTlvType { + String = 0, + SysDescr = 1, + SysName = 2, + VrTableName = 3, + AdminLabel = 4, +} + +#[derive(Debug, PartialEq, Clone)] pub struct PeerUpNotificationTlv { - pub info_type: u16, + pub info_type: PeerUpTlvType, pub info_len: u16, pub info_value: String, } @@ -44,7 +58,7 @@ pub fn parse_peer_up_notification( // let received_open = parse_bgp_open_message(data)?; let mut tlvs = vec![]; while data.remaining() >= 4 { - let info_type = data.read_u16()?; + let info_type = PeerUpTlvType::try_from(data.read_u16()?)?; let info_len = data.read_u16()?; let info_value = data.read_n_bytes_to_string(info_len as usize)?; tlvs.push(PeerUpNotificationTlv { @@ -114,12 +128,12 @@ mod tests { // Continue to check other values from peer_notification like sent_open, received_open, tlvs let tlv = peer_notification.tlvs.first().unwrap(); - assert_eq!(tlv.info_type, 1); + assert_eq!(tlv.info_type, PeerUpTlvType::SysDescr); assert_eq!(tlv.info_len, 2); assert_eq!(tlv.info_value, "\u{0}\u{3}"); } Err(_) => { - assert!(false, "parse_peer_up_notification should return Ok"); + panic!("parse_peer_up_notification should return Ok"); } } } diff --git a/src/parser/bmp/messages/route_mirroring.rs b/src/parser/bmp/messages/route_mirroring.rs index 98c6613..06caa18 100644 --- a/src/parser/bmp/messages/route_mirroring.rs +++ b/src/parser/bmp/messages/route_mirroring.rs @@ -6,18 +6,18 @@ use bytes::{Buf, Bytes}; use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::convert::TryFrom; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct RouteMirroring { pub tlvs: Vec, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct RouteMirroringTlv { pub info_len: u16, pub value: RouteMirroringValue, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub enum RouteMirroringValue { BgpMessage(BgpMessage), Information(RouteMirroringInfo), diff --git a/src/parser/bmp/messages/route_monitoring.rs b/src/parser/bmp/messages/route_monitoring.rs index 5d9aee0..6ef801f 100644 --- a/src/parser/bmp/messages/route_monitoring.rs +++ b/src/parser/bmp/messages/route_monitoring.rs @@ -3,7 +3,7 @@ use crate::parser::bgp::messages::parse_bgp_message; use crate::parser::bmp::error::ParserBmpError; use bytes::Bytes; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct RouteMonitoring { pub bgp_message: BgpMessage, } diff --git a/src/parser/bmp/messages/stats_report.rs b/src/parser/bmp/messages/stats_report.rs index 0793a36..c7ab8c3 100644 --- a/src/parser/bmp/messages/stats_report.rs +++ b/src/parser/bmp/messages/stats_report.rs @@ -1,22 +1,30 @@ use crate::parser::bmp::error::ParserBmpError; use crate::parser::ReadUtils; -use bytes::Bytes; +use bytes::{Buf, Bytes}; use num_enum::{FromPrimitive, IntoPrimitive}; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct StatsReport { pub stats_count: u32, pub counters: Vec, } /// Statistics count values -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct StatCounter { pub stat_type: StatType, pub stat_len: u16, pub stat_data: StatsData, } +#[derive(Debug, PartialEq, Clone)] +pub enum StatsData { + Counter(u32), + Gauge(u64), + AfiSafiGauge(u16, u8, u64), + Unknown(Vec), +} + /// Stats counter types enum /// /// Types of BMP statistics are listed here: @@ -45,22 +53,27 @@ pub enum StatType { Other(u16) = 65535, } -#[derive(Debug)] -pub enum StatsData { - Counter(u32), - Gauge(u64), -} - pub fn parse_stats_report(data: &mut Bytes) -> Result { let stats_count = data.read_u32()?; let mut counters = vec![]; for _ in 0..stats_count { let stat_type = StatType::from(data.read_u16()?); let stat_len = data.read_u16()?; + data.has_n_remaining(stat_len as usize)?; let stat_data = match stat_len { 4 => StatsData::Counter(data.read_u32()?), 8 => StatsData::Gauge(data.read_u64()?), - _ => return Err(ParserBmpError::CorruptedBmpMessage), + 11 => { + let afi = data.read_u16()?; + let safi = data.read_u8()?; + let value = data.read_u64()?; + StatsData::AfiSafiGauge(afi, safi, value) + } + _ => { + let mut unknown = vec![0; stat_len as usize]; + data.copy_to_slice(&mut unknown); + StatsData::Unknown(unknown) + } }; counters.push(StatCounter { stat_type, @@ -80,9 +93,8 @@ mod tests { use super::*; use bytes::{BufMut, BytesMut}; - // Check parsing data #[test] - fn test_parse_stats_report() { + fn test_parse_stats_report_counter() { let mut data = BytesMut::new(); data.put_u32(1); data.put_u16(0); @@ -107,6 +119,90 @@ mod tests { } } + #[test] + fn test_parse_stats_report_gauge() { + let mut data = BytesMut::new(); + data.put_u32(1); + data.put_u16(0); + data.put_u16(8); + data.put_u64(1234); + + let result = parse_stats_report(&mut data.freeze()); + match result { + Ok(report) => { + assert_eq!(report.stats_count, 1); + assert_eq!( + report.counters[0].stat_type, + StatType::PrefixesRejectedByInboundPolicy + ); + assert_eq!(report.counters[0].stat_len, 8); + match report.counters[0].stat_data { + StatsData::Gauge(value) => assert_eq!(value, 1234), + _ => panic!("Unexpected StatsData!"), + } + } + Err(_) => panic!("Error parsing stats!"), + } + } + + #[test] + fn test_parse_stats_report_afi_safi_gauge() { + let mut data = BytesMut::new(); + data.put_u32(1); + data.put_u16(9); + data.put_u16(11); + data.put_u16(1); + data.put_u8(2); + data.put_u64(1234); + + let result = parse_stats_report(&mut data.freeze()); + match result { + Ok(report) => { + assert_eq!(report.stats_count, 1); + assert_eq!( + report.counters[0].stat_type, + StatType::RoutesInPerAfiSafiAdjRibIn + ); + assert_eq!(report.counters[0].stat_len, 11); + match report.counters[0].stat_data { + StatsData::AfiSafiGauge(afi, safi, value) => { + assert_eq!(afi, 1); + assert_eq!(safi, 2); + assert_eq!(value, 1234) + } + _ => panic!("Unexpected StatsData!"), + } + } + Err(_) => panic!("Error parsing stats!"), + } + } + + #[test] + fn test_parse_stats_report_unknown() { + let mut data = BytesMut::new(); + data.put_u32(1); + data.put_u16(100); + data.put_u16(1); + data.put_u8(3); + + let result = parse_stats_report(&mut data.freeze()); + match result { + Ok(report) => { + assert_eq!(report.stats_count, 1); + assert_eq!(report.counters[0].stat_type, StatType::Other(100)); + assert_eq!(report.counters[0].stat_len, 1); + match &report.counters[0].stat_data { + StatsData::Unknown(data_vec) => { + assert_eq!(data_vec.len(), 1); + assert_eq!(data_vec[0], 3); + } + _ => panic!("Unexpected StatsData!"), + } + } + Err(_) => panic!("Error parsing stats!"), + } + } + // Check parsing error #[test] fn test_parse_stats_report_error() { diff --git a/src/parser/bmp/messages/termination_message.rs b/src/parser/bmp/messages/termination_message.rs index 43eff3f..3b3810c 100644 --- a/src/parser/bmp/messages/termination_message.rs +++ b/src/parser/bmp/messages/termination_message.rs @@ -4,16 +4,32 @@ use bytes::{Buf, Bytes}; use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::convert::TryFrom; -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct TerminationMessage { pub tlvs: Vec, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub struct TerminationTlv { pub info_type: TerminationTlvType, pub info_len: u16, - pub info: String, + pub info_value: TerminationTlvValue, +} + +#[derive(Debug, PartialEq, Clone)] +pub enum TerminationTlvValue { + String(String), + Reason(TerminationReason), +} + +#[derive(Debug, TryFromPrimitive, IntoPrimitive, PartialEq, Clone, Copy)] +#[repr(u16)] +pub enum TerminationReason { + AdministrativelyClosed = 0, + UnspecifiedReason = 1, + OutOfResources = 2, + RedundantConnection = 3, + PermanentlyAdministrativelyClosed = 4, } ///Type-Length-Value Type @@ -36,11 +52,20 @@ pub fn parse_termination_message(data: &mut Bytes) -> Result { + let info = data.read_n_bytes_to_string(info_len as usize)?; + TerminationTlvValue::String(info) + } + TerminationTlvType::Reason => { + let reason = TerminationReason::try_from(data.read_u16()?)?; + TerminationTlvValue::Reason(reason) + } + }; tlvs.push(TerminationTlv { info_type, info_len, - info, + info_value, }) } @@ -60,8 +85,8 @@ mod tests { 0, 5, // info_len: 5 67, 79, 68, 69, 83, // info: "CODES" 0, 1, // info_type: Reason - 0, 4, // info_len: 4 - 84, 69, 83, 84, // info: "TEST" + 0, 2, // info_len: 2 + 0, 1, // info: UnspecifiedReason ]); // Check if parse_termination_message correctly reads the data @@ -76,15 +101,21 @@ mod tests { TerminationTlvType::String ); assert_eq!(termination_message.tlvs[0].info_len, 5); - assert_eq!(termination_message.tlvs[0].info, "CODES"); + assert_eq!( + termination_message.tlvs[0].info_value, + TerminationTlvValue::String("CODES".to_string()) + ); // tlvs[1] assertions assert_eq!( termination_message.tlvs[1].info_type, TerminationTlvType::Reason ); - assert_eq!(termination_message.tlvs[1].info_len, 4); - assert_eq!(termination_message.tlvs[1].info, "TEST"); + assert_eq!(termination_message.tlvs[1].info_len, 2); + assert_eq!( + termination_message.tlvs[1].info_value, + TerminationTlvValue::Reason(TerminationReason::UnspecifiedReason) + ); } Err(e) => panic!("Failed to parse: {}", e), } diff --git a/src/parser/mrt/messages/table_dump_v2/mod.rs b/src/parser/mrt/messages/table_dump_v2/mod.rs index 89cfb7a..9ab8fb5 100644 --- a/src/parser/mrt/messages/table_dump_v2/mod.rs +++ b/src/parser/mrt/messages/table_dump_v2/mod.rs @@ -60,7 +60,6 @@ mod tests { #[test] fn test_unsupported_type() { let msg = parse_table_dump_v2_message(7, Bytes::new()); - dbg!(&msg); assert!(msg.is_err()); } }