diff --git a/crates/scion-proto/src/packet/scmp.rs b/crates/scion-proto/src/packet/scmp.rs index 2bced74..89fd93d 100644 --- a/crates/scion-proto/src/packet/scmp.rs +++ b/crates/scion-proto/src/packet/scmp.rs @@ -127,7 +127,7 @@ impl WireDecode for ScionPacketScmp { } } -impl WireEncodeVec<3> for ScionPacketScmp { +impl WireEncodeVec<3> for &ScionPacketScmp { type Error = InadequateBufferSize; fn encode_with_unchecked(&self, buffer: &mut bytes::BytesMut) -> [Bytes; 3] { diff --git a/crates/scion-proto/src/scmp/messages.rs b/crates/scion-proto/src/scmp/messages.rs index d05a124..bc5cc3f 100644 --- a/crates/scion-proto/src/scmp/messages.rs +++ b/crates/scion-proto/src/scmp/messages.rs @@ -168,10 +168,10 @@ impl TryFrom for ScmpMessage { } } -impl WireDecode for ScmpMessage { +impl WireDecode for ScmpMessage { type Error = ScmpDecodeError; - fn decode(data: &mut Bytes) -> Result { + fn decode(data: &mut T) -> Result { ScmpMessageRaw::decode(data)?.try_into() } } diff --git a/crates/scion/tests/test_scmp_packet.rs b/crates/scion/tests/test_raw_socket_with_scmp.rs similarity index 69% rename from crates/scion/tests/test_scmp_packet.rs rename to crates/scion/tests/test_raw_socket_with_scmp.rs index e48ff24..36cb20d 100644 --- a/crates/scion/tests/test_scmp_packet.rs +++ b/crates/scion/tests/test_raw_socket_with_scmp.rs @@ -2,7 +2,7 @@ use std::time::Duration; use scion::{ daemon::{get_daemon_address, DaemonClient}, - dispatcher::{get_dispatcher_path, DispatcherStream}, + socket::RawSocket, }; use scion_proto::{ address::{ScionAddr, SocketAddr}, @@ -21,6 +21,8 @@ async fn scmp_traceroute() -> TestResult { source: "1-ff00:0:111,127.0.0.17".parse().unwrap(), destination: "1-ff00:0:112,::1".parse().unwrap(), }; + + let (raw_socket, _port) = RawSocket::bind(SocketAddr::new(endpoints.source, 0)).await?; let daemon_client = DaemonClient::connect(&get_daemon_address()) .await .expect("should be able to connect"); @@ -31,21 +33,17 @@ async fn scmp_traceroute() -> TestResult { .unwrap(); println!("Forward path: {:?}", path_forward.dataplane_path); - let mut stream = DispatcherStream::connect(get_dispatcher_path()).await?; - let _local_address = stream - .register(SocketAddr::new(endpoints.source, 0)) - .await?; - let request = ScionPacketScmp::new_traceroute_request(&endpoints, &path_forward, 1, 1, 3)?; - - stream - .send_packet_via(path_forward.underlay_next_hop, request.clone()) + raw_socket + .send_packet_via(path_forward.underlay_next_hop, &request) .await?; - let mut packet = tokio::time::timeout(TIMEOUT, stream.receive_packet()).await??; - let scion_packet_scmp = ScionPacketScmp::decode(&mut packet.content)?; - let scmp_message = scion_packet_scmp.message; - assert!(scmp_message.verify_checksum(&scion_packet_scmp.headers.address)); + let mut buffer = [0_u8; 1500]; + + let (payload_length, _common_header, address_header) = + tokio::time::timeout(TIMEOUT, raw_socket.recv_with_headers(&mut buffer)).await??; + let scmp_message = ScmpMessage::decode(&mut buffer[..payload_length].as_ref())?; + assert!(scmp_message.verify_checksum(&address_header)); let ScmpMessage::TracerouteReply(reply) = scmp_message else { panic!("Unexpected SCMP reply received.")