From bff48e4bc426e3a273f7b69e372d010b8b866761 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Sun, 4 Feb 2024 17:39:31 +0800 Subject: [PATCH] test(net): added `ipv6 test_dispatch_icmp_probe_no_payload` --- src/tracing/net/ipv6.rs | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/tracing/net/ipv6.rs b/src/tracing/net/ipv6.rs index 7f01364f4..2923e1a98 100644 --- a/src/tracing/net/ipv6.rs +++ b/src/tracing/net/ipv6.rs @@ -435,8 +435,55 @@ mod tests { use crate::mocket_recv_from; use crate::tracing::error::IoResult; use crate::tracing::net::socket::MockSocket; + use crate::tracing::{Port, Round, TimeToLive}; + use mockall::predicate; use std::str::FromStr; + // Test dispatching an IPv6/ICMP probe. + #[test] + fn test_dispatch_icmp_probe_no_payload() -> anyhow::Result<()> { + let probe = Probe::new( + Sequence(33000), + TraceId(1234), + Port(0), + Port(0), + TimeToLive(10), + Round(0), + SystemTime::now(), + ); + let src_addr = Ipv6Addr::from_str("fd7a:115c:a1e0:ab12:4843:cd96:6263:82a")?; + let dest_addr = Ipv6Addr::from_str("2a00:1450:4009:815::200e")?; + let packet_size = PacketSize(48); + let payload_pattern = PayloadPattern(0x00); + let expected_send_to_buf = hex_literal::hex!("80 00 77 54 04 d2 80 e8"); + let expected_send_to_addr = SocketAddr::new(IpAddr::V6(dest_addr), 0); + + let mut mocket = MockSocket::new(); + mocket + .expect_send_to() + .with( + predicate::eq(expected_send_to_buf), + predicate::eq(expected_send_to_addr), + ) + .times(1) + .returning(|_, _| Ok(())); + mocket + .expect_set_unicast_hops_v6() + .times(1) + .with(predicate::eq(10)) + .returning(|_| Ok(())); + + dispatch_icmp_probe( + &mut mocket, + probe, + src_addr, + dest_addr, + packet_size, + payload_pattern, + )?; + Ok(()) + } + // This ICMPv6 packet has code 1 ("Fragment reassembly time exceeded") // and must be ignored. //