Skip to content

Commit

Permalink
test(net): added ipv6 test_dispatch_icmp_probe_no_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Feb 4, 2024
1 parent 0470d66 commit 3301067
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/tracing/net/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,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(8);
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.
//
Expand Down

0 comments on commit 3301067

Please sign in to comment.